From 0798a5223dfa684c29d7b59406e15d96c76c64ee Mon Sep 17 00:00:00 2001 From: Petr Horacek Date: Fri, 26 Jul 2019 14:04:33 +0200 Subject: [PATCH] use unified HCO conditions Use common library to handle conditions in order to integrate with proposed HCO design. Signed-off-by: Petr Horacek --- Gopkg.lock | 9 + README.md | 2 +- .../v1alpha1/networkaddonsconfig_types.go | 29 +-- .../v1alpha1/zz_generated.deepcopy.go | 21 +- .../statusmanager/status_manager.go | 89 ++------ .../statusmanager/status_manager_test.go | 46 ---- .../statusmanager/statusmanager_suite_test.go | 13 -- test/check/check.go | 3 +- test/check/conditions.go | 11 +- test/e2e/lifecycle/upgrade_test.go | 28 ++- test/e2e/workflow/recovery_test.go | 4 +- test/e2e/workflow/validation_test.go | 4 +- test/kubectl/kubectl.go | 15 ++ test/releases/releases.go | 16 +- .../openshift/custom-resource-status/LICENSE | 201 ++++++++++++++++++ .../conditions/v1/_doc.go | 9 + .../conditions/v1/conditions.go | 80 +++++++ .../conditions/v1/types.go | 51 +++++ .../conditions/v1/zz_generated.deepcopy.go | 23 ++ 19 files changed, 453 insertions(+), 201 deletions(-) delete mode 100644 pkg/controller/statusmanager/status_manager_test.go delete mode 100644 pkg/controller/statusmanager/statusmanager_suite_test.go create mode 100644 test/kubectl/kubectl.go create mode 100644 vendor/github.com/openshift/custom-resource-status/LICENSE create mode 100644 vendor/github.com/openshift/custom-resource-status/conditions/v1/_doc.go create mode 100644 vendor/github.com/openshift/custom-resource-status/conditions/v1/conditions.go create mode 100644 vendor/github.com/openshift/custom-resource-status/conditions/v1/types.go create mode 100644 vendor/github.com/openshift/custom-resource-status/conditions/v1/zz_generated.deepcopy.go diff --git a/Gopkg.lock b/Gopkg.lock index bdf0a6bde..851093c11 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -765,6 +765,14 @@ pruneopts = "NUT" revision = "ca122b5aa28a375e9cb365e76b980bb8cad7a5f2" +[[projects]] + branch = "master" + digest = "1:f4a2b3be9fe012a2e6aa27f5110bbee6953ee96991d2f4d0f7d925d701cc37b4" + name = "github.com/openshift/custom-resource-status" + packages = ["conditions/v1"] + pruneopts = "NUT" + revision = "a3f1373825c788339bfb03e81a15951ed11497d7" + [[projects]] digest = "1:95582b8c9cedd77c5d8f7be55be509cbff5ec78441eacdb73aae24ce28f2bbc8" name = "github.com/openshift/origin" @@ -1961,6 +1969,7 @@ "github.com/onsi/gomega", "github.com/openshift/api/operator/v1", "github.com/openshift/cluster-network-operator/pkg/names", + "github.com/openshift/custom-resource-status/conditions/v1", "github.com/openshift/origin/pkg/security/apis/security", "github.com/operator-framework/operator-sdk/cmd/operator-sdk", "github.com/operator-framework/operator-sdk/pkg/k8sutil", diff --git a/README.md b/README.md index 2bad5d231..befd31398 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ kubectl apply -f https://raw.githubusercontent.com/kubevirt/cluster-network-addo Finally you can wait for the operator to finish deployment: ```shell -kubectl wait networkaddonsconfig cluster --for condition=Ready +kubectl wait networkaddonsconfig cluster --for condition=Available ``` In case something failed, you can find the error in the NetworkAddonsConfig Status field: diff --git a/pkg/apis/networkaddonsoperator/v1alpha1/networkaddonsconfig_types.go b/pkg/apis/networkaddonsoperator/v1alpha1/networkaddonsconfig_types.go index 85385eca9..afaf971a2 100644 --- a/pkg/apis/networkaddonsoperator/v1alpha1/networkaddonsconfig_types.go +++ b/pkg/apis/networkaddonsoperator/v1alpha1/networkaddonsconfig_types.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -44,36 +45,10 @@ type NetworkAddonsConfigStatus struct { OperatorVersion string `json:"operatorVersion,omitempty"` ObservedVersion string `json:"observedVersion,omitempty"` TargetVersion string `json:"targetVersion,omitempty"` - Conditions []NetworkAddonsCondition `json:"conditions,omitempty" optional:"true"` + Conditions []conditionsv1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` Containers []Container `json:"containers,omitempty"` } -// NetworkAddonsCondition represents a condition of a NetworkAddons deployment -// --- -// +k8s:openapi-gen=true -type NetworkAddonsCondition struct { - Type NetworkAddonsConditionType `json:"type"` - Status corev1.ConditionStatus `json:"status"` - LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"` - LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` - Reason string `json:"reason,omitempty"` - Message string `json:"message,omitempty"` -} - -// --- -// +k8s:openapi-gen=true -type NetworkAddonsConditionType string - -// These are the valid NetworkAddons condition types -const ( - // Whether operator failed during deployment - NetworkAddonsConditionFailing NetworkAddonsConditionType = "Failing" - // Whether is the deployment progressing - NetworkAddonsConditionProgressing NetworkAddonsConditionType = "Progressing" - // Whether all components were ready - NetworkAddonsConditionAvailable NetworkAddonsConditionType = "Ready" -) - type Container struct { Namespace string `json:"namespace"` ParentKind string `json:"parentKind"` diff --git a/pkg/apis/networkaddonsoperator/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/networkaddonsoperator/v1alpha1/zz_generated.deepcopy.go index 069de1b6d..34cbf0688 100644 --- a/pkg/apis/networkaddonsoperator/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/networkaddonsoperator/v1alpha1/zz_generated.deepcopy.go @@ -5,6 +5,7 @@ package v1alpha1 import ( + v1 "github.com/openshift/custom-resource-status/conditions/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -88,24 +89,6 @@ func (in *NMState) DeepCopy() *NMState { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NetworkAddonsCondition) DeepCopyInto(out *NetworkAddonsCondition) { - *out = *in - in.LastProbeTime.DeepCopyInto(&out.LastProbeTime) - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkAddonsCondition. -func (in *NetworkAddonsCondition) DeepCopy() *NetworkAddonsCondition { - if in == nil { - return nil - } - out := new(NetworkAddonsCondition) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkAddonsConfig) DeepCopyInto(out *NetworkAddonsConfig) { *out = *in @@ -218,7 +201,7 @@ func (in *NetworkAddonsConfigStatus) DeepCopyInto(out *NetworkAddonsConfigStatus *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]NetworkAddonsCondition, len(*in)) + *out = make([]v1.Condition, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } diff --git a/pkg/controller/statusmanager/status_manager.go b/pkg/controller/statusmanager/status_manager.go index bd4aa9fe0..870c6b46e 100644 --- a/pkg/controller/statusmanager/status_manager.go +++ b/pkg/controller/statusmanager/status_manager.go @@ -9,6 +9,7 @@ import ( "strings" "time" + conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -47,7 +48,7 @@ type StatusManager struct { client client.Client name string - failing [maxStatusLevel]*opv1alpha1.NetworkAddonsCondition + failing [maxStatusLevel]*conditionsv1.Condition daemonSets []types.NamespacedName deployments []types.NamespacedName @@ -64,7 +65,7 @@ func New(client client.Client, name string) *StatusManager { // the status, calling set is tried several times. // TODO: Calling of Patch instead may save some problems. We can reiterate later, // current collision problem is detected by functional tests -func (status *StatusManager) Set(reachedAvailableLevel bool, conditions ...opv1alpha1.NetworkAddonsCondition) { +func (status *StatusManager) Set(reachedAvailableLevel bool, conditions ...conditionsv1.Condition) { for i := 0; i < conditionsUpdateRetries; i++ { err := status.set(reachedAvailableLevel, conditions...) if err == nil { @@ -78,7 +79,7 @@ func (status *StatusManager) Set(reachedAvailableLevel bool, conditions ...opv1a } // set updates the NetworkAddonsConfig.Status with the provided conditions -func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...opv1alpha1.NetworkAddonsCondition) error { +func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...conditionsv1.Condition) error { // Read the current NetworkAddonsConfig config := &opv1alpha1.NetworkAddonsConfig{ObjectMeta: metav1.ObjectMeta{Name: status.name}} err := status.client.Get(context.TODO(), types.NamespacedName{Name: status.name}, config) @@ -91,7 +92,7 @@ func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...opv1a // Update Status field with given conditions for _, condition := range conditions { - updateCondition(&config.Status, condition) + conditionsv1.SetStatusCondition(&config.Status.Conditions, condition) } config.Status.OperatorVersion = operatorVersion @@ -103,11 +104,10 @@ func (status *StatusManager) set(reachedAvailableLevel bool, conditions ...opv1a // In case that the status field has been updated with "Progressing" condition, make sure that // "Ready" condition is set to False, even when not explicitly set. - progressingCondition := getCondition(&config.Status, opv1alpha1.NetworkAddonsConditionProgressing) - if progressingCondition != nil && progressingCondition.Status == corev1.ConditionTrue { - updateCondition(&config.Status, - opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionAvailable, + if conditionsv1.IsStatusConditionTrue(config.Status.Conditions, conditionsv1.ConditionProgressing) { + conditionsv1.SetStatusCondition(&config.Status.Conditions, + conditionsv1.Condition{ + Type: conditionsv1.ConditionAvailable, Status: corev1.ConditionFalse, Reason: "Startup", Message: "Configuration is in process", @@ -141,8 +141,8 @@ func (status *StatusManager) syncFailing() { } status.Set( false, - opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionFailing, + conditionsv1.Condition{ + Type: conditionsv1.ConditionDegraded, Status: corev1.ConditionFalse, }, ) @@ -151,8 +151,8 @@ func (status *StatusManager) syncFailing() { // SetFailing marks the operator as Failing with the given reason and message. If it // is not already failing for a lower-level reason, the operator's status will be updated. func (status *StatusManager) SetFailing(level StatusLevel, reason, message string) { - status.failing[level] = &opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionFailing, + status.failing[level] = &conditionsv1.Condition{ + Type: conditionsv1.ConditionDegraded, Status: corev1.ConditionTrue, Reason: reason, Message: message, @@ -272,8 +272,8 @@ func (status *StatusManager) SetFromPods() { if len(progressing) > 0 { status.Set( false, - opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionProgressing, + conditionsv1.Condition{ + Type: conditionsv1.ConditionProgressing, Status: corev1.ConditionTrue, Reason: "Deploying", Message: strings.Join(progressing, "\n"), @@ -282,12 +282,12 @@ func (status *StatusManager) SetFromPods() { } else { status.Set( true, - opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionProgressing, + conditionsv1.Condition{ + Type: conditionsv1.ConditionProgressing, Status: corev1.ConditionFalse, }, - opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionAvailable, + conditionsv1.Condition{ + Type: conditionsv1.ConditionAvailable, Status: corev1.ConditionTrue, }, ) @@ -297,57 +297,6 @@ func (status *StatusManager) SetFromPods() { status.SetNotFailing(PodDeployment) } -// Set condition in the Status field. In case condition with given Type already exists, update it. -// This function also takes care of setting timestamps of LastProbeTime and LastTransitionTime. -func updateCondition(status *opv1alpha1.NetworkAddonsConfigStatus, condition opv1alpha1.NetworkAddonsCondition) { - originalCondition := getCondition(status, condition.Type) - - // Check whether the condition is to be added or updated - isNew := originalCondition == nil - - // Check whether there are any changes compared to the original condition - transition := (!isNew && (condition.Status != originalCondition.Status || condition.Reason != originalCondition.Reason || condition.Message != originalCondition.Message)) - - // Update Condition's timestamps - now := time.Now() - - // LastProbeTime indicates the last time the condition has been checked - condition.LastProbeTime = metav1.Time{ - Time: now, - } - - // LastTransitionTime indicates the last time the condition has been changed or it has been added - if isNew || transition { - condition.LastTransitionTime = metav1.Time{ - Time: now, - } - } else { - condition.LastTransitionTime = originalCondition.LastTransitionTime - } - - // Update or add desired condition to the Status field - if isNew { - status.Conditions = append(status.Conditions, condition) - } else { - for i := range status.Conditions { - if status.Conditions[i].Type == condition.Type { - status.Conditions[i] = condition - break - } - } - } -} - -// Get conditition of given type from NetworkAddonsConfig.Status -func getCondition(status *opv1alpha1.NetworkAddonsConfigStatus, conditionType opv1alpha1.NetworkAddonsConditionType) *opv1alpha1.NetworkAddonsCondition { - for _, condition := range status.Conditions { - if condition.Type == conditionType { - return &condition - } - } - return nil -} - func (status *StatusManager) SetContainers(containers []opv1alpha1.Container) { status.containers = containers } diff --git a/pkg/controller/statusmanager/status_manager_test.go b/pkg/controller/statusmanager/status_manager_test.go deleted file mode 100644 index 085f00e12..000000000 --- a/pkg/controller/statusmanager/status_manager_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package statusmanager - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" - - opv1alpha1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1alpha1" -) - -var _ = Describe("updateCondition", func() { - Context("when status has empty conditions", func() { - status := &opv1alpha1.NetworkAddonsConfigStatus{} - var testedStatus *opv1alpha1.NetworkAddonsConfigStatus - - Context("and condition is being set", func() { - condition := opv1alpha1.NetworkAddonsCondition{ - Type: opv1alpha1.NetworkAddonsConditionProgressing, - Status: corev1.ConditionFalse, - Reason: "bar", - Message: "foo", - } - - BeforeEach(func() { - // Update condition changes status - testedStatus = status.DeepCopy() - updateCondition(testedStatus, condition) - }) - - It("should have length 1", func() { - Expect(testedStatus.Conditions).To(HaveLen(1)) - }) - - It("should have type of condition, status, message, reason", func() { - Expect(testedStatus.Conditions[0].Type).To(Equal(condition.Type)) - Expect(testedStatus.Conditions[0].Status).To(Equal(condition.Status)) - Expect(testedStatus.Conditions[0].Reason).To(Equal(condition.Reason)) - Expect(testedStatus.Conditions[0].Message).To(Equal(condition.Message)) - }) - - It("should have probe time and transition time equal", func() { - Expect(testedStatus.Conditions[0].LastProbeTime.Time).To(Equal(testedStatus.Conditions[0].LastTransitionTime.Time)) - }) - }) - }) -}) diff --git a/pkg/controller/statusmanager/statusmanager_suite_test.go b/pkg/controller/statusmanager/statusmanager_suite_test.go deleted file mode 100644 index 5ff3d00c8..000000000 --- a/pkg/controller/statusmanager/statusmanager_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package statusmanager - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -func TestStatusManager(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Status Manager Suite") -} diff --git a/test/check/check.go b/test/check/check.go index 5d584da02..1b6542f38 100644 --- a/test/check/check.go +++ b/test/check/check.go @@ -11,6 +11,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" securityapi "github.com/openshift/origin/pkg/security/apis/security" framework "github.com/operator-framework/operator-sdk/pkg/test" "gopkg.in/yaml.v2" @@ -396,7 +397,7 @@ func isNotFound(componentType string, componentName string, clientGetOutput erro func checkConfigCondition(conf *opv1alpha1.NetworkAddonsConfig, conditionType ConditionType, conditionStatus ConditionStatus) error { for _, condition := range conf.Status.Conditions { - if condition.Type == opv1alpha1.NetworkAddonsConditionType(conditionType) { + if condition.Type == conditionsv1.ConditionType(conditionType) { if condition.Status == corev1.ConditionStatus(conditionStatus) { return nil } diff --git a/test/check/conditions.go b/test/check/conditions.go index affa92120..449877466 100644 --- a/test/check/conditions.go +++ b/test/check/conditions.go @@ -1,19 +1,18 @@ package check import ( + conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" corev1 "k8s.io/api/core/v1" - - opv1alpha1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1alpha1" ) -type ConditionType opv1alpha1.NetworkAddonsConditionType +type ConditionType conditionsv1.ConditionType type ConditionStatus corev1.ConditionStatus const ( - ConditionAvailable = ConditionType(opv1alpha1.NetworkAddonsConditionAvailable) - ConditionProgressing = ConditionType(opv1alpha1.NetworkAddonsConditionProgressing) - ConditionFailing = ConditionType(opv1alpha1.NetworkAddonsConditionFailing) + ConditionAvailable = ConditionType(conditionsv1.ConditionAvailable) + ConditionProgressing = ConditionType(conditionsv1.ConditionProgressing) + ConditionDegraded = ConditionType(conditionsv1.ConditionDegraded) ConditionTrue = ConditionStatus(corev1.ConditionTrue) ConditionFalse = ConditionStatus(corev1.ConditionFalse) diff --git a/test/e2e/lifecycle/upgrade_test.go b/test/e2e/lifecycle/upgrade_test.go index b12ea7594..436d93eb3 100644 --- a/test/e2e/lifecycle/upgrade_test.go +++ b/test/e2e/lifecycle/upgrade_test.go @@ -4,9 +4,12 @@ import ( "fmt" "time" + "github.com/blang/semver" . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" . "github.com/kubevirt/cluster-network-addons-operator/test/check" + . "github.com/kubevirt/cluster-network-addons-operator/test/kubectl" . "github.com/kubevirt/cluster-network-addons-operator/test/operations" . "github.com/kubevirt/cluster-network-addons-operator/test/releases" ) @@ -20,7 +23,12 @@ var _ = Context("Cluster Network Addons Operator", func() { InstallRelease(oldRelease) CheckOperatorIsReady(podsDeploymentTimeout) CreateConfig(oldRelease.SupportedSpec) - CheckConfigCondition(ConditionAvailable, ConditionTrue, 15*time.Minute, CheckDoNotRepeat) + // Conditions API changed in 0.12.0, use this check for older versions + if isReleaseLesserOrEqual(oldRelease, "0.11.0") { + checkConfigConditionAvailablePre0dot12() + } else { + CheckConfigCondition(ConditionAvailable, ConditionTrue, 15*time.Minute, CheckDoNotRepeat) + } ignoreInitialKubeMacPoolRestart() CheckReleaseUsesExpectedContainerImages(oldRelease) expectedOperatorVersion := oldRelease.Version @@ -90,3 +98,21 @@ func ignoreInitialKubeMacPoolRestart() { By("Ignoring initial KubeMacPool restart") time.Sleep(10 * time.Second) } + +func isReleaseLesserOrEqual(release Release, thanVersion string) bool { + givenReleaseVersion, err := semver.Make(release.Version) + if err != nil { + panic(err) + } + comparedToVersion, err := semver.Make(thanVersion) + if err != nil { + panic(err) + } + return givenReleaseVersion.LTE(comparedToVersion) +} + +func checkConfigConditionAvailablePre0dot12() { + By("Checking that condition Available status is set to True (<0.12.0 compat)") + out, err := Kubectl("wait", "networkaddonsconfig", "cluster", "--for", "condition=Ready", "--timeout=10m") + Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Failed waiting for the CR to become Availabe: %s", string(out))) +} diff --git a/test/e2e/workflow/recovery_test.go b/test/e2e/workflow/recovery_test.go index 018ece31c..9f25a5ebf 100644 --- a/test/e2e/workflow/recovery_test.go +++ b/test/e2e/workflow/recovery_test.go @@ -20,7 +20,7 @@ var _ = Describe("NetworkAddonsConfig", func() { }, } CreateConfig(configSpec) - CheckConfigCondition(ConditionFailing, ConditionTrue, 5*time.Second, CheckDoNotRepeat) + CheckConfigCondition(ConditionDegraded, ConditionTrue, 5*time.Second, CheckDoNotRepeat) }) Context("and it is updated with a valid config", func() { @@ -31,7 +31,7 @@ var _ = Describe("NetworkAddonsConfig", func() { It("should turn from Failing to Available", func() { CheckConfigCondition(ConditionAvailable, ConditionTrue, 5*time.Second, CheckDoNotRepeat) - CheckConfigCondition(ConditionFailing, ConditionFalse, CheckImmediately, CheckDoNotRepeat) + CheckConfigCondition(ConditionDegraded, ConditionFalse, CheckImmediately, CheckDoNotRepeat) }) }) }) diff --git a/test/e2e/workflow/validation_test.go b/test/e2e/workflow/validation_test.go index 072f0a3cb..6c37f0827 100644 --- a/test/e2e/workflow/validation_test.go +++ b/test/e2e/workflow/validation_test.go @@ -31,7 +31,7 @@ var _ = Describe("NetworkAddonsConfig", func() { }) It("should report Failing condition and Available must be set to False", func() { - CheckConfigCondition(ConditionFailing, ConditionTrue, time.Minute, CheckDoNotRepeat) + CheckConfigCondition(ConditionDegraded, ConditionTrue, time.Minute, CheckDoNotRepeat) CheckConfigCondition(ConditionAvailable, ConditionFalse, CheckImmediately, CheckDoNotRepeat) }) }) @@ -53,7 +53,7 @@ var _ = Describe("NetworkAddonsConfig", func() { }) It("should report Failing condition and remain Available", func() { - CheckConfigCondition(ConditionFailing, ConditionTrue, time.Minute, CheckDoNotRepeat) + CheckConfigCondition(ConditionDegraded, ConditionTrue, time.Minute, CheckDoNotRepeat) CheckConfigCondition(ConditionAvailable, ConditionTrue, CheckImmediately, CheckDoNotRepeat) }) }) diff --git a/test/kubectl/kubectl.go b/test/kubectl/kubectl.go new file mode 100644 index 000000000..d13474eb4 --- /dev/null +++ b/test/kubectl/kubectl.go @@ -0,0 +1,15 @@ +package kubectl + +import ( + "bytes" + "os/exec" +) + +func Kubectl(command ...string) (string, error) { + var stdout, stderr bytes.Buffer + cmd := exec.Command("./cluster/kubectl.sh", command...) + cmd.Stderr = &stderr + cmd.Stdout = &stdout + err := cmd.Run() + return stdout.String() + stderr.String(), err +} diff --git a/test/releases/releases.go b/test/releases/releases.go index 53e4188af..45f609bc9 100644 --- a/test/releases/releases.go +++ b/test/releases/releases.go @@ -1,9 +1,7 @@ package releases import ( - "bytes" "fmt" - "os/exec" "sort" "github.com/blang/semver" @@ -11,6 +9,7 @@ import ( . "github.com/onsi/gomega" opv1alpha1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1alpha1" + . "github.com/kubevirt/cluster-network-addons-operator/test/kubectl" . "github.com/kubevirt/cluster-network-addons-operator/test/operations" ) @@ -61,7 +60,7 @@ func LatestRelease() Release { func InstallRelease(release Release) { By(fmt.Sprintf("Installing release %s", release.Version)) for _, manifestName := range release.Manifests { - out, err := kubectl("apply", "-f", "_out/cluster-network-addons/"+release.Version+"/"+manifestName) + out, err := Kubectl("apply", "-f", "_out/cluster-network-addons/"+release.Version+"/"+manifestName) Expect(err).NotTo(HaveOccurred(), out) } } @@ -70,7 +69,7 @@ func InstallRelease(release Release) { func UninstallRelease(release Release) { By(fmt.Sprintf("Uninstalling release %s", release.Version)) for _, manifestName := range release.Manifests { - out, err := kubectl("delete", "--ignore-not-found", "-f", "_out/cluster-network-addons/"+release.Version+"/"+manifestName) + out, err := Kubectl("delete", "--ignore-not-found", "-f", "_out/cluster-network-addons/"+release.Version+"/"+manifestName) Expect(err).NotTo(HaveOccurred(), out) } } @@ -97,12 +96,3 @@ func sortContainers(containers []opv1alpha1.Container) []opv1alpha1.Container { }) return containers } - -func kubectl(command ...string) (string, error) { - var stdout, stderr bytes.Buffer - cmd := exec.Command("./cluster/kubectl.sh", command...) - cmd.Stderr = &stderr - cmd.Stdout = &stdout - err := cmd.Run() - return stdout.String() + stderr.String(), err -} diff --git a/vendor/github.com/openshift/custom-resource-status/LICENSE b/vendor/github.com/openshift/custom-resource-status/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/vendor/github.com/openshift/custom-resource-status/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/openshift/custom-resource-status/conditions/v1/_doc.go b/vendor/github.com/openshift/custom-resource-status/conditions/v1/_doc.go new file mode 100644 index 000000000..b657efeaa --- /dev/null +++ b/vendor/github.com/openshift/custom-resource-status/conditions/v1/_doc.go @@ -0,0 +1,9 @@ +// +k8s:deepcopy-gen=package,register +// +k8s:defaulter-gen=TypeMeta +// +k8s:openapi-gen=true + +// Package v1 provides version v1 of the types and functions necessary to +// manage and inspect a slice of conditions. It is opinionated in the +// condition types provided but leaves it to the user to define additional +// types as necessary. +package v1 diff --git a/vendor/github.com/openshift/custom-resource-status/conditions/v1/conditions.go b/vendor/github.com/openshift/custom-resource-status/conditions/v1/conditions.go new file mode 100644 index 000000000..cb2c85e5b --- /dev/null +++ b/vendor/github.com/openshift/custom-resource-status/conditions/v1/conditions.go @@ -0,0 +1,80 @@ +package v1 + +import ( + "time" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// SetStatusCondition sets the corresponding condition in conditions to newCondition. +func SetStatusCondition(conditions *[]Condition, newCondition Condition) { + if conditions == nil { + conditions = &[]Condition{} + } + existingCondition := FindStatusCondition(*conditions, newCondition.Type) + if existingCondition == nil { + newCondition.LastTransitionTime = metav1.NewTime(time.Now()) + *conditions = append(*conditions, newCondition) + return + } + + if existingCondition.Status != newCondition.Status { + existingCondition.Status = newCondition.Status + existingCondition.LastTransitionTime = metav1.NewTime(time.Now()) + } + + existingCondition.Reason = newCondition.Reason + existingCondition.Message = newCondition.Message +} + +// RemoveStatusCondition removes the corresponding conditionType from conditions. +func RemoveStatusCondition(conditions *[]Condition, conditionType ConditionType) { + if conditions == nil { + return + } + newConditions := []Condition{} + for _, condition := range *conditions { + if condition.Type != conditionType { + newConditions = append(newConditions, condition) + } + } + + *conditions = newConditions +} + +// FindStatusCondition finds the conditionType in conditions. +func FindStatusCondition(conditions []Condition, conditionType ConditionType) *Condition { + for i := range conditions { + if conditions[i].Type == conditionType { + return &conditions[i] + } + } + + return nil +} + +// IsStatusConditionTrue returns true when the conditionType is present and set to `corev1.ConditionTrue` +func IsStatusConditionTrue(conditions []Condition, conditionType ConditionType) bool { + return IsStatusConditionPresentAndEqual(conditions, conditionType, corev1.ConditionTrue) +} + +// IsStatusConditionFalse returns true when the conditionType is present and set to `corev1.ConditionFalse` +func IsStatusConditionFalse(conditions []Condition, conditionType ConditionType) bool { + return IsStatusConditionPresentAndEqual(conditions, conditionType, corev1.ConditionFalse) +} + +// IsStatusConditionUnknown returns true when the conditionType is present and set to `corev1.ConditionUnknown` +func IsStatusConditionUnknown(conditions []Condition, conditionType ConditionType) bool { + return IsStatusConditionPresentAndEqual(conditions, conditionType, corev1.ConditionUnknown) +} + +// IsStatusConditionPresentAndEqual returns true when conditionType is present and equal to status. +func IsStatusConditionPresentAndEqual(conditions []Condition, conditionType ConditionType, status corev1.ConditionStatus) bool { + for _, condition := range conditions { + if condition.Type == conditionType { + return condition.Status == status + } + } + return false +} diff --git a/vendor/github.com/openshift/custom-resource-status/conditions/v1/types.go b/vendor/github.com/openshift/custom-resource-status/conditions/v1/types.go new file mode 100644 index 000000000..950678fb9 --- /dev/null +++ b/vendor/github.com/openshift/custom-resource-status/conditions/v1/types.go @@ -0,0 +1,51 @@ +package v1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Condition represents the state of the operator's +// reconciliation functionality. +// +k8s:deepcopy-gen=true +type Condition struct { + Type ConditionType `json:"type" description:"type of condition ie. Available|Progressing|Degraded."` + + Status corev1.ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"` + + // +optional + Reason string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"` + + // +optional + Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"` + + // +optional + LastHeartbeatTime metav1.Time `json:"lastHeartbeatTime" description:"last time we got an update on a given condition"` + + // +optional + LastTransitionTime metav1.Time `json:"lastTransitionTime" description:"last time the condition transit from one status to another"` +} + +// ConditionType is the state of the operator's reconciliation functionality. +type ConditionType string + +const ( + // ConditionAvailable indicates that the resources maintained by the operator, + // is functional and available in the cluster. + ConditionAvailable ConditionType = "Available" + + // ConditionProgressing indicates that the operator is actively making changes to the resources maintained by the + // operator + ConditionProgressing ConditionType = "Progressing" + + // ConditionDegraded indicates that the resources maintained by the operator are not functioning completely. + // An example of a degraded state would be if not all pods in a deployment were running. + // It may still be available, but it is degraded + ConditionDegraded ConditionType = "Degraded" + + // ConditionUpgradeable indicates whether the resources maintained by the operator are in a state that is safe to upgrade. + // When `False`, the resources maintained by the operator should not be upgraded and the + // message field should contain a human readable description of what the administrator should do to + // allow the operator to successfully update the resources maintained by the operator. + ConditionUpgradeable ConditionType = "Upgradeable" +) diff --git a/vendor/github.com/openshift/custom-resource-status/conditions/v1/zz_generated.deepcopy.go b/vendor/github.com/openshift/custom-resource-status/conditions/v1/zz_generated.deepcopy.go new file mode 100644 index 000000000..bbbbf863d --- /dev/null +++ b/vendor/github.com/openshift/custom-resource-status/conditions/v1/zz_generated.deepcopy.go @@ -0,0 +1,23 @@ +// +build !ignore_autogenerated + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Condition) DeepCopyInto(out *Condition) { + *out = *in + in.LastHeartbeatTime.DeepCopyInto(&out.LastHeartbeatTime) + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition. +func (in *Condition) DeepCopy() *Condition { + if in == nil { + return nil + } + out := new(Condition) + in.DeepCopyInto(out) + return out +}