From afea586f949d486889abab62567702a1d124cef9 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Wed, 4 Dec 2024 13:47:36 +0100 Subject: [PATCH] Add Condition when minor update is available When there is a new AvailableVersion, which does not match the Deployed version, this adds a condition to reflect this. This can be used e.g. in CI to wait for the new AvailableVersion to be reflected when the OpenStackVersion was patched. But could be useful for other situations. Signed-off-by: Martin Schuppert --- apis/core/v1beta1/conditions.go | 5 +++++ controllers/core/openstackversion_controller.go | 9 +++++++++ .../ctlplane/openstackversion_controller_test.go | 12 ++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/apis/core/v1beta1/conditions.go b/apis/core/v1beta1/conditions.go index c0617e70e..7456fbb59 100644 --- a/apis/core/v1beta1/conditions.go +++ b/apis/core/v1beta1/conditions.go @@ -478,6 +478,8 @@ const ( OpenStackVersionMinorUpdateControlplane condition.Type = "MinorUpdateControlplane" OpenStackVersionMinorUpdateDataplane condition.Type = "MinorUpdateDataplane" + + OpenStackVersionMinorUpdateAvailable condition.Type = "MinorUpdateAvailable" ) // Version Messages used by API objects. @@ -506,4 +508,7 @@ const ( // OpenStackVersionMinorUpdateReadyErrorMessage OpenStackVersionMinorUpdateReadyErrorMessage = "error occured %s" + + // OpenStackVersionMinorUpdateAvailableMessage + OpenStackVersionMinorUpdateAvailableMessage = "update available" ) diff --git a/controllers/core/openstackversion_controller.go b/controllers/core/openstackversion_controller.go index 88d50998d..d13c08581 100644 --- a/controllers/core/openstackversion_controller.go +++ b/controllers/core/openstackversion_controller.go @@ -301,6 +301,15 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req Log.Info("Setting DeployedVersion") instance.Status.DeployedVersion = &instance.Spec.TargetVersion } + if instance.Status.AvailableVersion != nil && + instance.Status.DeployedVersion != nil && + *instance.Status.AvailableVersion != *instance.Status.DeployedVersion { + instance.Status.Conditions.Set(condition.TrueCondition( + corev1beta1.OpenStackVersionMinorUpdateAvailable, + corev1beta1.OpenStackVersionMinorUpdateAvailableMessage)) + } else { + instance.Status.Conditions.Remove(corev1beta1.OpenStackVersionMinorUpdateAvailable) + } return ctrl.Result{}, nil } diff --git a/tests/functional/ctlplane/openstackversion_controller_test.go b/tests/functional/ctlplane/openstackversion_controller_test.go index 8e65e929b..70296e8f3 100644 --- a/tests/functional/ctlplane/openstackversion_controller_test.go +++ b/tests/functional/ctlplane/openstackversion_controller_test.go @@ -96,8 +96,8 @@ var _ = Describe("OpenStackOperator controller", func() { version := GetOpenStackVersion(names.OpenStackVersionName) g.Expect(version).Should(Not(BeNil())) - g.Expect(*version.Status.AvailableVersion).Should(Equal("0.0.1")) - g.Expect(version.Spec.TargetVersion).Should(Equal("0.0.1")) + g.Expect(*version.Status.AvailableVersion).Should(ContainSubstring("0.0.1")) + g.Expect(version.Spec.TargetVersion).Should(ContainSubstring("0.0.1")) g.Expect(version.Status.ContainerImages.AgentImage).ShouldNot(BeNil()) g.Expect(version.Status.ContainerImages.AnsibleeeImage).ShouldNot(BeNil()) @@ -291,15 +291,15 @@ var _ = Describe("OpenStackOperator controller", func() { targetOvnControllerVersion = *version.Status.ContainerImages.OvnControllerImage g.Expect(version).Should(Not(BeNil())) - g.Expect(*version.Status.AvailableVersion).Should(Equal("0.0.1")) - g.Expect(version.Spec.TargetVersion).Should(Equal("0.0.1")) - + g.Expect(*version.Status.AvailableVersion).Should(ContainSubstring("0.0.1")) + g.Expect(version.Spec.TargetVersion).Should(ContainSubstring("0.0.1")) + updatedVersion = *version.Status.AvailableVersion }, timeout, interval).Should(Succeed()) // inject an "old" version Eventually(func(g Gomega) { version := GetOpenStackVersion(names.OpenStackVersionName) - version.Status.ContainerImageVersionDefaults[initialVersion] = version.Status.ContainerImageVersionDefaults["0.0.1"] + version.Status.ContainerImageVersionDefaults[initialVersion] = version.Status.ContainerImageVersionDefaults[updatedVersion] version.Status.ContainerImageVersionDefaults[initialVersion].OvnControllerImage = &testOvnControllerImage g.Expect(th.K8sClient.Status().Update(th.Ctx, version)).To(Succeed())