Skip to content

Commit d95b067

Browse files
Merge pull request #2235 from zzzeek/OSPRH-40831
Wait for all Galeras before reporting MariaDB ready
2 parents 642365e + e425bc0 commit d95b067

2 files changed

Lines changed: 87 additions & 4 deletions

File tree

‎internal/openstack/galera.go‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ func ReconcileGaleras(
172172

173173
// Add the conditions to the list of conditions to consider later for mirroring.
174174
// It doesn't matter if the conditions are already in the list, they will be
175-
// deduplicated later during the MirrorSubResourceCondition call.
176-
if galera != nil && galera.Status.Conditions != nil {
175+
// deduplicated later during the MirrorSubResourceCondition call. Conditions
176+
// of a Galera that is ready are left out, as a True Ready condition from any
177+
// one Galera would otherwise be mirrored as the state of all of them.
178+
if status != galeraReady && galera != nil && galera.Status.Conditions != nil {
177179
conditions = append(conditions, galera.Status.Conditions...)
178180
}
179181

@@ -211,7 +213,13 @@ func ReconcileGaleras(
211213
// the "oc get oscontrolplane -n <namespace>" output.
212214
if len(conditions) > 0 {
213215
MirrorSubResourceCondition(conditions, corev1beta1.OpenStackControlPlaneMariaDBReadyCondition, instance, reflect.TypeOf(mariadbv1.Galera{}).Name())
214-
} else {
216+
}
217+
// At least one Galera is in progress, so MariaDBReady must not be True. A
218+
// non-True result mirrored above is kept, as it has the Galera's own reason
219+
// and message. Otherwise, either no Galera has conditions yet, or one that
220+
// is in progress still has a True Ready condition from before its current
221+
// generation was observed, so report the generic in-progress state instead.
222+
if len(conditions) == 0 || instance.Status.Conditions.IsTrue(corev1beta1.OpenStackControlPlaneMariaDBReadyCondition) {
215223
instance.Status.Conditions.Set(condition.FalseCondition(
216224
corev1beta1.OpenStackControlPlaneMariaDBReadyCondition,
217225
condition.RequestedReason,
@@ -220,6 +228,11 @@ func ReconcileGaleras(
220228
}
221229
} else {
222230
log.Info("Galera ready condition is true")
231+
// The image is recorded only once every Galera is ready, as the minor
232+
// update uses it to determine that MariaDB has been updated.
233+
if len(templateNames) > 0 {
234+
instance.Status.ContainerImages.MariadbImage = version.Status.ContainerImages.MariadbImage
235+
}
223236
instance.Status.Conditions.MarkTrue(
224237
corev1beta1.OpenStackControlPlaneMariaDBReadyCondition,
225238
corev1beta1.OpenStackControlPlaneMariaDBReadyMessage,
@@ -310,7 +323,6 @@ func reconcileGalera(
310323
}
311324

312325
if galera.Status.ObservedGeneration == galera.Generation && galera.IsReady() {
313-
instance.Status.ContainerImages.MariadbImage = version.Status.ContainerImages.MariadbImage
314326
return galeraReady, galera, nil
315327
}
316328

‎test/functional/ctlplane/openstackoperator_controller_test.go‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,6 +3716,77 @@ var _ = Describe("OpenStackOperator controller", func() {
37163716
// Template-level takes precedence over top-level.
37173717
})
37183718

3719+
// The minor update waits on the control plane's MariaDBReady condition and
3720+
// MariadbImage status, which must reflect all of the Galeras together.
3721+
When("A OpenStackControlPlane has more than one Galera", func() {
3722+
setGaleraStatus := func(name types.NamespacedName, generationObserved bool, ready bool) {
3723+
Eventually(func(g Gomega) {
3724+
db := &mariadbv1.Galera{}
3725+
g.Expect(th.K8sClient.Get(th.Ctx, name, db)).Should(Succeed())
3726+
db.Status.ObservedGeneration = db.Generation
3727+
if !generationObserved {
3728+
db.Status.ObservedGeneration = db.Generation - 1
3729+
}
3730+
db.Status.Conditions = condition.Conditions{}
3731+
if ready {
3732+
db.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage)
3733+
db.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
3734+
} else {
3735+
db.Status.Conditions.Set(condition.FalseCondition(
3736+
condition.ReadyCondition, condition.RequestedReason, condition.SeverityInfo, "upgrading"))
3737+
db.Status.Conditions.Set(condition.FalseCondition(
3738+
condition.DeploymentReadyCondition, condition.RequestedReason, condition.SeverityInfo, "upgrading"))
3739+
}
3740+
g.Expect(th.K8sClient.Status().Update(th.Ctx, db)).To(Succeed())
3741+
}, timeout, interval).Should(Succeed())
3742+
}
3743+
3744+
expectMariaDBNotReported := func() {
3745+
Consistently(func(g Gomega) {
3746+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3747+
g.Expect(OSCtlplane.Status.Conditions.IsTrue(
3748+
corev1.OpenStackControlPlaneMariaDBReadyCondition)).To(BeFalse())
3749+
g.Expect(OSCtlplane.Status.ContainerImages.MariadbImage).To(BeNil())
3750+
}, "5s", interval).Should(Succeed())
3751+
}
3752+
3753+
BeforeEach(func() {
3754+
spec := GetDefaultOpenStackControlPlaneSpec()
3755+
spec["tls"] = GetTLSPublicSpec()
3756+
DeferCleanup(
3757+
th.DeleteInstance,
3758+
CreateOpenStackControlPlane(names.OpenStackControlplaneName, spec),
3759+
)
3760+
Eventually(func(g Gomega) {
3761+
db := &mariadbv1.Galera{}
3762+
g.Expect(th.K8sClient.Get(th.Ctx, names.DBName, db)).Should(Succeed())
3763+
g.Expect(th.K8sClient.Get(th.Ctx, names.DBCell1Name, db)).Should(Succeed())
3764+
}, timeout, interval).Should(Succeed())
3765+
})
3766+
3767+
It("does not report MariaDB ready until all of them are ready", func() {
3768+
setGaleraStatus(names.DBCell1Name, true, true)
3769+
setGaleraStatus(names.DBName, true, false)
3770+
expectMariaDBNotReported()
3771+
3772+
setGaleraStatus(names.DBName, true, true)
3773+
Eventually(func(g Gomega) {
3774+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3775+
version := GetOpenStackVersion(names.OpenStackVersionName)
3776+
g.Expect(OSCtlplane.Status.Conditions.IsTrue(
3777+
corev1.OpenStackControlPlaneMariaDBReadyCondition)).To(BeTrue())
3778+
g.Expect(OSCtlplane.Status.ContainerImages.MariadbImage).To(
3779+
Equal(version.Status.ContainerImages.MariadbImage))
3780+
}, timeout, interval).Should(Succeed())
3781+
})
3782+
3783+
It("does not report MariaDB ready from a Galera with stale status", func() {
3784+
setGaleraStatus(names.DBCell1Name, true, true)
3785+
setGaleraStatus(names.DBName, false, true)
3786+
expectMariaDBNotReported()
3787+
})
3788+
})
3789+
37193790
//
37203791
// MariaDB major version upgrade (ServiceDefaults.MariadbVersion -> Galera TargetVersion)
37213792
//

0 commit comments

Comments
 (0)