Skip to content

Commit 559ee7c

Browse files
Merge pull request openstack-k8s-operators#1217 from stuggi/add_hash_osvers
Add commit hash as suffix to the OpenStackVersion
2 parents 1089a7c + a6164e6 commit 559ee7c

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
66
VERSION ?= 0.0.1
77

8+
OPENSTACK_RELEASE_VERSION ?= $(VERSION)-$(shell date +%s)
9+
810
# CHANNELS define the bundle channels used in the bundle.
911
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
1012
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
@@ -338,7 +340,9 @@ endif
338340
.PHONY: bundle
339341
bundle: build manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
340342
$(OPERATOR_SDK) generate kustomize manifests -q
341-
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
343+
cd config/manager && \
344+
$(KUSTOMIZE) edit set image controller=$(IMG) && \
345+
$(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)\"}}]"
342346
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
343347
cp dependencies.yaml ./bundle/metadata
344348
$(OPERATOR_SDK) bundle validate ./bundle

apis/core/v1beta1/conditions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ const (
478478
OpenStackVersionMinorUpdateControlplane condition.Type = "MinorUpdateControlplane"
479479

480480
OpenStackVersionMinorUpdateDataplane condition.Type = "MinorUpdateDataplane"
481+
482+
OpenStackVersionMinorUpdateAvailable condition.Type = "MinorUpdateAvailable"
481483
)
482484

483485
// Version Messages used by API objects.
@@ -506,4 +508,7 @@ const (
506508

507509
// OpenStackVersionMinorUpdateReadyErrorMessage
508510
OpenStackVersionMinorUpdateReadyErrorMessage = "error occured %s"
511+
512+
// OpenStackVersionMinorUpdateAvailableMessage
513+
OpenStackVersionMinorUpdateAvailableMessage = "update available"
509514
)

controllers/core/openstackversion_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req
301301
Log.Info("Setting DeployedVersion")
302302
instance.Status.DeployedVersion = &instance.Spec.TargetVersion
303303
}
304+
if instance.Status.DeployedVersion != nil &&
305+
*instance.Status.AvailableVersion != *instance.Status.DeployedVersion {
306+
instance.Status.Conditions.Set(condition.TrueCondition(
307+
corev1beta1.OpenStackVersionMinorUpdateAvailable,
308+
corev1beta1.OpenStackVersionMinorUpdateAvailableMessage))
309+
} else {
310+
instance.Status.Conditions.Remove(corev1beta1.OpenStackVersionMinorUpdateAvailable)
311+
}
304312

305313
return ctrl.Result{}, nil
306314
}

hack/export_related_images.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
export OPENSTACK_RELEASE_VERSION=0.0.1
3+
export OPENSTACK_RELEASE_VERSION=0.0.1-$(date +%s)
44
export RELATED_IMAGE_OPENSTACK_CLIENT_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified
55
export RELATED_IMAGE_RABBITMQ_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-rabbitmq:current-podified
66
export RELATED_IMAGE_KEYSTONE_API_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-keystone:current-podified

tests/functional/ctlplane/openstackversion_controller_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ var _ = Describe("OpenStackOperator controller", func() {
9696
version := GetOpenStackVersion(names.OpenStackVersionName)
9797
g.Expect(version).Should(Not(BeNil()))
9898

99-
g.Expect(*version.Status.AvailableVersion).Should(Equal("0.0.1"))
100-
g.Expect(version.Spec.TargetVersion).Should(Equal("0.0.1"))
99+
// no condition which reflects an update is available
100+
g.Expect(version.Status.Conditions.Has(corev1.OpenStackVersionMinorUpdateAvailable)).To(BeFalse())
101+
102+
g.Expect(*version.Status.AvailableVersion).Should(ContainSubstring("0.0.1"))
103+
g.Expect(version.Spec.TargetVersion).Should(ContainSubstring("0.0.1"))
101104

102105
g.Expect(version.Status.ContainerImages.AgentImage).ShouldNot(BeNil())
103106
g.Expect(version.Status.ContainerImages.AnsibleeeImage).ShouldNot(BeNil())
@@ -291,15 +294,15 @@ var _ = Describe("OpenStackOperator controller", func() {
291294
targetOvnControllerVersion = *version.Status.ContainerImages.OvnControllerImage
292295
g.Expect(version).Should(Not(BeNil()))
293296

294-
g.Expect(*version.Status.AvailableVersion).Should(Equal("0.0.1"))
295-
g.Expect(version.Spec.TargetVersion).Should(Equal("0.0.1"))
296-
297+
g.Expect(*version.Status.AvailableVersion).Should(ContainSubstring("0.0.1"))
298+
g.Expect(version.Spec.TargetVersion).Should(ContainSubstring("0.0.1"))
299+
updatedVersion = *version.Status.AvailableVersion
297300
}, timeout, interval).Should(Succeed())
298301

299302
// inject an "old" version
300303
Eventually(func(g Gomega) {
301304
version := GetOpenStackVersion(names.OpenStackVersionName)
302-
version.Status.ContainerImageVersionDefaults[initialVersion] = version.Status.ContainerImageVersionDefaults["0.0.1"]
305+
version.Status.ContainerImageVersionDefaults[initialVersion] = version.Status.ContainerImageVersionDefaults[updatedVersion]
303306
version.Status.ContainerImageVersionDefaults[initialVersion].OvnControllerImage = &testOvnControllerImage
304307
g.Expect(th.K8sClient.Status().Update(th.Ctx, version)).To(Succeed())
305308

@@ -391,6 +394,15 @@ var _ = Describe("OpenStackOperator controller", func() {
391394

392395
// 1) switch to version 0.0.1, this triggers a minor update
393396
osversion := GetOpenStackVersion(names.OpenStackVersionName)
397+
398+
// should have a condition which reflects an update is available
399+
th.ExpectCondition(
400+
names.OpenStackVersionName,
401+
ConditionGetterFunc(OpenStackVersionConditionGetter),
402+
corev1.OpenStackVersionMinorUpdateAvailable,
403+
k8s_corev1.ConditionTrue,
404+
)
405+
394406
osversion.Spec.TargetVersion = updatedVersion
395407
Expect(k8sClient.Update(ctx, osversion)).Should(Succeed())
396408

@@ -536,7 +548,8 @@ var _ = Describe("OpenStackOperator controller", func() {
536548
k8s_corev1.ConditionTrue,
537549
)
538550
g.Expect(osversion.Status.DeployedVersion).Should(Equal(&updatedVersion)) // we're done here
539-
551+
// no condition which reflects an update is available
552+
g.Expect(osversion.Status.Conditions.Has(corev1.OpenStackVersionMinorUpdateAvailable)).To(BeFalse())
540553
}, timeout, interval).Should(Succeed())
541554

542555
})

0 commit comments

Comments
 (0)