Skip to content

Commit

Permalink
Add Condition when minor update is available
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stuggi authored and openshift-cherrypick-robot committed Dec 21, 2024
1 parent 8c3af4e commit 247a3b8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions apis/core/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ const (
OpenStackVersionMinorUpdateControlplane condition.Type = "MinorUpdateControlplane"

OpenStackVersionMinorUpdateDataplane condition.Type = "MinorUpdateDataplane"

OpenStackVersionMinorUpdateAvailable condition.Type = "MinorUpdateAvailable"
)

// Version Messages used by API objects.
Expand Down Expand Up @@ -506,4 +508,7 @@ const (

// OpenStackVersionMinorUpdateReadyErrorMessage
OpenStackVersionMinorUpdateReadyErrorMessage = "error occured %s"

// OpenStackVersionMinorUpdateAvailableMessage
OpenStackVersionMinorUpdateAvailableMessage = "update available"
)
8 changes: 8 additions & 0 deletions controllers/core/openstackversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
27 changes: 20 additions & 7 deletions tests/functional/ctlplane/openstackversion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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())

})
Expand Down

0 comments on commit 247a3b8

Please sign in to comment.