44 "context"
55 "errors"
66 "fmt"
7+ "reflect"
78 "strings"
89
910 certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
@@ -98,6 +99,9 @@ func ReconcileGaleras(
9899 instance .Spec .Galera .Templates = ptr .To (map [string ]mariadbv1.GaleraSpecCore {})
99100 }
100101
102+ // List of conditions to consider later for mirroring
103+ conditions := condition.Conditions {}
104+
101105 for name , spec := range * instance .Spec .Galera .Templates {
102106 hostname := fmt .Sprintf ("%s.%s.svc" , name , instance .Namespace )
103107 hostnameHeadless := fmt .Sprintf ("%s-galera.%s.svc" , name , instance .Namespace )
@@ -151,7 +155,14 @@ func ReconcileGaleras(
151155 spec .TLS .Ca .CaBundleSecretName = instance .Status .TLS .CaBundleSecretName
152156 spec .TLS .SecretName = ptr .To (certSecret .Name )
153157
154- status , err := reconcileGalera (ctx , instance , version , helper , name , & spec )
158+ status , galera , err := reconcileGalera (ctx , instance , version , helper , name , & spec )
159+
160+ // Add the conditions to the list of conditions to consider later for mirroring.
161+ // It doesn't matter if the conditions are already in the list, they will be
162+ // deduplicated later during the MirrorSubResourceCondition call.
163+ if galera != nil && galera .Status .Conditions != nil {
164+ conditions = append (conditions , galera .Status .Conditions ... )
165+ }
155166
156167 switch status {
157168 case galeraFailed :
@@ -178,11 +189,22 @@ func ReconcileGaleras(
178189
179190 } else if len (inprogress ) > 0 {
180191 log .Info ("Galera in progress" )
181- instance .Status .Conditions .Set (condition .FalseCondition (
182- corev1beta1 .OpenStackControlPlaneMariaDBReadyCondition ,
183- condition .RequestedReason ,
184- condition .SeverityInfo ,
185- corev1beta1 .OpenStackControlPlaneMariaDBReadyRunningMessage ))
192+ // We want to mirror the condition of the highest priority from the Galera resources into the instance
193+ // under the condition of type OpenStackControlPlaneMariaDBReadyCondition, but only if the sub-resources
194+ // currently have any conditions (which won't be true for the initial creation of the sub-resources, since
195+ // they have not gone through a reconcile loop yet to have any conditions). If this condition ends up being
196+ // the highest priority condition in the OpenStackControlPlane, it will appear in the OpenStackControlPlane's
197+ // "Ready" condition at the end of the reconciliation loop, clearly surfacing the condition to the user in
198+ // the "oc get oscontrolplane -n <namespace>" output.
199+ if len (conditions ) > 0 {
200+ MirrorSubResourceCondition (conditions , corev1beta1 .OpenStackControlPlaneMariaDBReadyCondition , instance , reflect .TypeOf (mariadbv1.Galera {}).Name ())
201+ } else {
202+ instance .Status .Conditions .Set (condition .FalseCondition (
203+ corev1beta1 .OpenStackControlPlaneMariaDBReadyCondition ,
204+ condition .RequestedReason ,
205+ condition .SeverityInfo ,
206+ corev1beta1 .OpenStackControlPlaneMariaDBReadyRunningMessage ))
207+ }
186208 } else {
187209 log .Info ("Galera ready condition is true" )
188210 instance .Status .Conditions .MarkTrue (
@@ -213,7 +235,7 @@ func reconcileGalera(
213235 helper * helper.Helper ,
214236 name string ,
215237 spec * mariadbv1.GaleraSpecCore ,
216- ) (galeraStatus , error ) {
238+ ) (galeraStatus , * mariadbv1. Galera , error ) {
217239 galera := & mariadbv1.Galera {
218240 ObjectMeta : metav1.ObjectMeta {
219241 Name : name ,
@@ -224,11 +246,11 @@ func reconcileGalera(
224246
225247 if ! instance .Spec .Galera .Enabled {
226248 if _ , err := EnsureDeleted (ctx , helper , galera ); err != nil {
227- return galeraFailed , err
249+ return galeraFailed , galera , err
228250 }
229251 instance .Status .Conditions .Remove (corev1beta1 .OpenStackControlPlaneMariaDBReadyCondition )
230252 instance .Status .ContainerImages .MariadbImage = nil
231- return galeraReady , nil
253+ return galeraReady , galera , nil
232254 }
233255
234256 if spec .NodeSelector == nil {
@@ -256,18 +278,18 @@ func reconcileGalera(
256278 })
257279
258280 if err != nil {
259- return galeraFailed , err
281+ return galeraFailed , galera , err
260282 }
261283 if op != controllerutil .OperationResultNone {
262284 log .Info (fmt .Sprintf ("Galera %s - %s" , galera .Name , op ))
263285 }
264286
265287 if galera .Status .ObservedGeneration == galera .Generation && galera .IsReady () {
266288 instance .Status .ContainerImages .MariadbImage = version .Status .ContainerImages .MariadbImage
267- return galeraReady , nil
289+ return galeraReady , galera , nil
268290 }
269291
270- return galeraCreating , nil
292+ return galeraCreating , galera , nil
271293}
272294
273295// GaleraImageMatch - return true if the Galera images match on the ControlPlane and Version, or if Galera is not enabled
0 commit comments