From 8c3af4eb9713c288e969587e4ca2d3d2853b0826 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 2 Dec 2024 17:36:17 +0100 Subject: [PATCH 1/2] Add timestamp as suffix to the OpenStackVersion Right now when a PR merges, the build openstack-operator has the OpenStackVersion 0.0.1. Since they are all the same for each PR it is not possible to test updates. Lets add the seconds since the Epoch as a suffix so that we get a different OpenStackVersion with each operator build. Signed-off-by: Martin Schuppert --- Makefile | 6 +++++- hack/export_related_images.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a2dcbcb06..ce6883e9b 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) VERSION ?= 0.0.1 +OPENSTACK_RELEASE_VERSION ?= $(VERSION)-$(shell date +%s) + # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") # To re-generate a bundle for other specific channels without changing the standard setup, you can: @@ -338,7 +340,9 @@ endif .PHONY: bundle bundle: build manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files. $(OPERATOR_SDK) generate kustomize manifests -q - cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) + cd config/manager && \ + $(KUSTOMIZE) edit set image controller=$(IMG) && \ + $(KUSTOMIZE) edit add patch --kind Deployment --name controller-manager --namespace system --patch "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/env/0\", \"value\": {\"name\": \"OPENSTACK_RELEASE_VERSION\", \"value\": \"$(OPENSTACK_RELEASE_VERSION)\"}}]" $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) cp dependencies.yaml ./bundle/metadata $(OPERATOR_SDK) bundle validate ./bundle diff --git a/hack/export_related_images.sh b/hack/export_related_images.sh index 6b9045d11..b025b130a 100755 --- a/hack/export_related_images.sh +++ b/hack/export_related_images.sh @@ -1,6 +1,6 @@ #!/bin/bash -export OPENSTACK_RELEASE_VERSION=0.0.1 +export OPENSTACK_RELEASE_VERSION=0.0.1-$(date +%s) export RELATED_IMAGE_OPENSTACK_CLIENT_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified export RELATED_IMAGE_RABBITMQ_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-rabbitmq:current-podified export RELATED_IMAGE_KEYSTONE_API_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-keystone:current-podified From 247a3b81cf331ba565010eedc9f3e38e51711bbc Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Wed, 4 Dec 2024 13:47:36 +0100 Subject: [PATCH 2/2] 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 ++++ .../core/openstackversion_controller.go | 8 ++++++ .../openstackversion_controller_test.go | 27 ++++++++++++++----- 3 files changed, 33 insertions(+), 7 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..255a7de4c 100644 --- a/controllers/core/openstackversion_controller.go +++ b/controllers/core/openstackversion_controller.go @@ -301,6 +301,14 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req Log.Info("Setting DeployedVersion") instance.Status.DeployedVersion = &instance.Spec.TargetVersion } + if 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 362aaa34e..68ee88a09 100644 --- a/tests/functional/ctlplane/openstackversion_controller_test.go +++ b/tests/functional/ctlplane/openstackversion_controller_test.go @@ -96,8 +96,11 @@ 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")) + // no condition which reflects an update is available + g.Expect(version.Status.Conditions.Has(corev1.OpenStackVersionMinorUpdateAvailable)).To(BeFalse()) + + 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()) @@ -288,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()) @@ -388,6 +391,15 @@ var _ = Describe("OpenStackOperator controller", func() { // 1) switch to version 0.0.1, this triggers a minor update osversion := GetOpenStackVersion(names.OpenStackVersionName) + + // should have a condition which reflects an update is available + th.ExpectCondition( + names.OpenStackVersionName, + ConditionGetterFunc(OpenStackVersionConditionGetter), + corev1.OpenStackVersionMinorUpdateAvailable, + k8s_corev1.ConditionTrue, + ) + osversion.Spec.TargetVersion = updatedVersion Expect(k8sClient.Update(ctx, osversion)).Should(Succeed()) @@ -533,7 +545,8 @@ var _ = Describe("OpenStackOperator controller", func() { k8s_corev1.ConditionTrue, ) g.Expect(osversion.Status.DeployedVersion).Should(Equal(&updatedVersion)) // we're done here - + // no condition which reflects an update is available + g.Expect(osversion.Status.Conditions.Has(corev1.OpenStackVersionMinorUpdateAvailable)).To(BeFalse()) }, timeout, interval).Should(Succeed()) })