Skip to content

Commit a6164e6

Browse files
committed
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 <mschuppert@redhat.com>
1 parent ffc51a8 commit a6164e6

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

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
}

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)