mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 17:52:12 +00:00
Add APIs for computing status based on fetching resource info from a
cluster
This commit is contained in:
@@ -6,8 +6,8 @@ package status
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
corev1 "sigs.k8s.io/kustomize/pseudo/k8s/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
// GetConditionsFn defines the signature for functions to compute the
|
||||
@@ -36,6 +36,8 @@ const (
|
||||
tooFewAvailable = "LessAvailable"
|
||||
tooFewUpdated = "LessUpdated"
|
||||
tooFewReplicas = "LessReplicas"
|
||||
|
||||
onDeleteUpdateStrategy = "OnDelete"
|
||||
)
|
||||
|
||||
// GetLegacyConditionsFn returns a function that can compute the status for the
|
||||
@@ -71,7 +73,7 @@ func stsConditions(u *unstructured.Unstructured) (*Result, error) {
|
||||
|
||||
// updateStrategy==ondelete is a user managed statefulset.
|
||||
updateStrategy := GetStringField(obj, ".spec.updateStrategy.type", "")
|
||||
if updateStrategy == "ondelete" {
|
||||
if updateStrategy == onDeleteUpdateStrategy {
|
||||
return &Result{
|
||||
Status: CurrentStatus,
|
||||
Message: "StatefulSet is using the ondelete update strategy",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// Computing the status of a resources can be done by calling the
|
||||
// Compute function in the status package.
|
||||
// import (
|
||||
// "sigs.k8s.io/kustomize/kstatus/status
|
||||
// "sigs.k8s.io/kustomize/kstatus/status"
|
||||
// )
|
||||
// res, err := status.Compute(resource)
|
||||
//
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
. "sigs.k8s.io/kustomize/kstatus/status"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
corev1 "sigs.k8s.io/kustomize/pseudo/k8s/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
// checkGenericProperties looks at the properties that are available on
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
corev1 "sigs.k8s.io/kustomize/pseudo/k8s/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,6 +23,7 @@ const (
|
||||
FailedStatus Status = "Failed"
|
||||
CurrentStatus Status = "Current"
|
||||
TerminatingStatus Status = "Terminating"
|
||||
UnknownStatus Status = "Unknown"
|
||||
)
|
||||
|
||||
// ConditionType defines the set of condition types allowed inside a Condition struct.
|
||||
@@ -81,8 +82,15 @@ type Condition struct {
|
||||
// a list of standard resources that would belong on the given resource.
|
||||
func Compute(u *unstructured.Unstructured) (*Result, error) {
|
||||
res, err := checkGenericProperties(u)
|
||||
if err != nil || res != nil {
|
||||
return res, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If res is not nil, it means the generic checks was able to determine
|
||||
// the status of the resource. We don't need to check the type-specific
|
||||
// rules.
|
||||
if res != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
fn := GetLegacyConditionsFn(u)
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
corev1 "sigs.k8s.io/kustomize/pseudo/k8s/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
var pod = `
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
corev1 "sigs.k8s.io/kustomize/pseudo/k8s/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func y2u(t *testing.T, spec string) *unstructured.Unstructured {
|
||||
|
||||
@@ -6,9 +6,9 @@ package status
|
||||
import (
|
||||
"strings"
|
||||
|
||||
apiunstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
corev1 "sigs.k8s.io/kustomize/pseudo/k8s/api/core/v1"
|
||||
apiunstructured "sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"sigs.k8s.io/kustomize/pseudo/k8s/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// newInProgressCondition creates an inProgress condition with the given
|
||||
|
||||
Reference in New Issue
Block a user