Skip to content

Commit e425bc0

Browse files
zzzeekclaude
andcommitted
Wait for all Galeras before reporting MariaDB ready
With more than one Galera, the MariaDB minor update gate could open as soon as any one of them was ready. reconcileGalera recorded the new MariadbImage in the control plane status when a single Galera became ready, so GaleraImageMatch passed. ReconcileGaleras also merged the conditions of all Galeras before mirroring them while one was still in progress, and Conditions.Mirror() returns True when it finds a True Ready condition in the list. Later update stages then started while another Galera was still being upgraded. Record MariadbImage only once every Galera is ready. While any Galera is in progress, mirror conditions only from Galeras that are not ready, and never report MariaDBReady as True, including when a Galera that is in progress still carries a True Ready condition from before its current generation was observed. References: OSPRH-40831 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3da6daf commit e425bc0

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
@@ -3523,6 +3523,77 @@ var _ = Describe("OpenStackOperator controller", func() {
35233523
// Template-level takes precedence over top-level.
35243524
})
35253525

3526+
// The minor update waits on the control plane's MariaDBReady condition and
3527+
// MariadbImage status, which must reflect all of the Galeras together.
3528+
When("A OpenStackControlPlane has more than one Galera", func() {
3529+
setGaleraStatus := func(name types.NamespacedName, generationObserved bool, ready bool) {
3530+
Eventually(func(g Gomega) {
3531+
db := &mariadbv1.Galera{}
3532+
g.Expect(th.K8sClient.Get(th.Ctx, name, db)).Should(Succeed())
3533+
db.Status.ObservedGeneration = db.Generation
3534+
if !generationObserved {
3535+
db.Status.ObservedGeneration = db.Generation - 1
3536+
}
3537+
db.Status.Conditions = condition.Conditions{}
3538+
if ready {
3539+
db.Status.Conditions.MarkTrue(condition.ReadyCondition, condition.ReadyMessage)
3540+
db.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
3541+
} else {
3542+
db.Status.Conditions.Set(condition.FalseCondition(
3543+
condition.ReadyCondition, condition.RequestedReason, condition.SeverityInfo, "upgrading"))
3544+
db.Status.Conditions.Set(condition.FalseCondition(
3545+
condition.DeploymentReadyCondition, condition.RequestedReason, condition.SeverityInfo, "upgrading"))
3546+
}
3547+
g.Expect(th.K8sClient.Status().Update(th.Ctx, db)).To(Succeed())
3548+
}, timeout, interval).Should(Succeed())
3549+
}
3550+
3551+
expectMariaDBNotReported := func() {
3552+
Consistently(func(g Gomega) {
3553+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3554+
g.Expect(OSCtlplane.Status.Conditions.IsTrue(
3555+
corev1.OpenStackControlPlaneMariaDBReadyCondition)).To(BeFalse())
3556+
g.Expect(OSCtlplane.Status.ContainerImages.MariadbImage).To(BeNil())
3557+
}, "5s", interval).Should(Succeed())
3558+
}
3559+
3560+
BeforeEach(func() {
3561+
spec := GetDefaultOpenStackControlPlaneSpec()
3562+
spec["tls"] = GetTLSPublicSpec()
3563+
DeferCleanup(
3564+
th.DeleteInstance,
3565+
CreateOpenStackControlPlane(names.OpenStackControlplaneName, spec),
3566+
)
3567+
Eventually(func(g Gomega) {
3568+
db := &mariadbv1.Galera{}
3569+
g.Expect(th.K8sClient.Get(th.Ctx, names.DBName, db)).Should(Succeed())
3570+
g.Expect(th.K8sClient.Get(th.Ctx, names.DBCell1Name, db)).Should(Succeed())
3571+
}, timeout, interval).Should(Succeed())
3572+
})
3573+
3574+
It("does not report MariaDB ready until all of them are ready", func() {
3575+
setGaleraStatus(names.DBCell1Name, true, true)
3576+
setGaleraStatus(names.DBName, true, false)
3577+
expectMariaDBNotReported()
3578+
3579+
setGaleraStatus(names.DBName, true, true)
3580+
Eventually(func(g Gomega) {
3581+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3582+
version := GetOpenStackVersion(names.OpenStackVersionName)
3583+
g.Expect(OSCtlplane.Status.Conditions.IsTrue(
3584+
corev1.OpenStackControlPlaneMariaDBReadyCondition)).To(BeTrue())
3585+
g.Expect(OSCtlplane.Status.ContainerImages.MariadbImage).To(
3586+
Equal(version.Status.ContainerImages.MariadbImage))
3587+
}, timeout, interval).Should(Succeed())
3588+
})
3589+
3590+
It("does not report MariaDB ready from a Galera with stale status", func() {
3591+
setGaleraStatus(names.DBCell1Name, true, true)
3592+
setGaleraStatus(names.DBName, false, true)
3593+
expectMariaDBNotReported()
3594+
})
3595+
})
3596+
35263597
//
35273598
// MariaDB major version upgrade (ServiceDefaults.MariadbVersion -> Galera TargetVersion)
35283599
//

0 commit comments

Comments
 (0)