@@ -708,17 +708,13 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
708708 //
709709 // Handle Topology
710710 //
711- lastTopologyRef := topologyv1.TopoRef {
712- Name : instance .Status .LastAppliedTopology ,
713- Namespace : instance .Namespace ,
714- }
715- topology , err := ensureGaleraTopology (
711+ topology , err := topologyv1 .EnsureServiceTopology (
716712 ctx ,
717713 helper ,
718714 instance .Spec .TopologyRef ,
719- & lastTopologyRef ,
715+ instance . GetLastAppliedTopologyRef () ,
720716 instance .Name ,
721- mariadb .ServiceName ,
717+ labels . GetAppLabelSelector ( mariadb .ServiceName ) ,
722718 )
723719 if err != nil {
724720 instance .Status .Conditions .Set (condition .FalseCondition (
@@ -735,12 +731,12 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
735731 // and mark the condition as true
736732 if instance .Spec .TopologyRef != nil {
737733 // update the Status with the last retrieved Topology name
738- instance .Status .LastAppliedTopology = instance .Spec .TopologyRef . Name
734+ instance .Status .LastAppliedTopology = instance .Spec .TopologyRef
739735 // update the TopologyRef associated condition
740736 instance .Status .Conditions .MarkTrue (condition .TopologyReadyCondition , condition .TopologyReadyMessage )
741737 } else {
742738 // remove LastAppliedTopology from the .Status
743- instance .Status .LastAppliedTopology = ""
739+ instance .Status .LastAppliedTopology = nil
744740 }
745741
746742 commonstatefulset := commonstatefulset .NewStatefulSet (mariadb .StatefulSet (instance , hashOfHashes , topology ), 5 )
@@ -1103,10 +1099,7 @@ func (r *GaleraReconciler) reconcileDelete(ctx context.Context, instance *databa
11031099 if ctrlResult , err := topologyv1 .EnsureDeletedTopologyRef (
11041100 ctx ,
11051101 helper ,
1106- & topologyv1.TopoRef {
1107- Name : instance .Status .LastAppliedTopology ,
1108- Namespace : instance .Namespace ,
1109- },
1102+ instance .Status .LastAppliedTopology ,
11101103 instance .Name ,
11111104 ); err != nil {
11121105 return ctrlResult , err
@@ -1118,61 +1111,3 @@ func (r *GaleraReconciler) reconcileDelete(ctx context.Context, instance *databa
11181111
11191112 return ctrl.Result {}, nil
11201113}
1121-
1122- // ensureGaleraTopology - when a Topology CR is referenced, remove the
1123- // finalizer from a previous referenced Topology (if any), and retrieve the
1124- // newly referenced topology object
1125- func ensureGaleraTopology (
1126- ctx context.Context ,
1127- helper * helper.Helper ,
1128- tpRef * topologyv1.TopoRef ,
1129- lastAppliedTopology * topologyv1.TopoRef ,
1130- finalizer string ,
1131- selector string ,
1132- ) (* topologyv1.Topology , error ) {
1133-
1134- var podTopology * topologyv1.Topology
1135- var err error
1136-
1137- // Remove (if present) the finalizer from a previously referenced topology
1138- //
1139- // 1. a topology reference is removed (tpRef == nil) from the Manila Component
1140- // subCR and the finalizer should be deleted from the last applied topology
1141- // (lastAppliedTopology != "")
1142- // 2. a topology reference is updated in the Manila Component CR (tpRef != nil)
1143- // and the finalizer should be removed from the previously
1144- // referenced topology (tpRef.Name != lastAppliedTopology.Name)
1145- if (tpRef == nil && lastAppliedTopology .Name != "" ) ||
1146- (tpRef != nil && tpRef .Name != lastAppliedTopology .Name ) {
1147- _ , err = topologyv1 .EnsureDeletedTopologyRef (
1148- ctx ,
1149- helper ,
1150- lastAppliedTopology ,
1151- finalizer ,
1152- )
1153- if err != nil {
1154- return nil , err
1155- }
1156- }
1157- // TopologyRef is passed as input, get the Topology object
1158- if tpRef != nil {
1159- // no Namespace is provided, default to instance.Namespace
1160- if tpRef .Namespace == "" {
1161- tpRef .Namespace = helper .GetBeforeObject ().GetNamespace ()
1162- }
1163- // Build the defaultLabelSelector based on serviceName (service=mariadb)
1164- defaultLabelSelector := labels .GetAppLabelSelector (selector )
1165- // Retrieve the referenced Topology
1166- podTopology , _ , err = topologyv1 .EnsureTopologyRef (
1167- ctx ,
1168- helper ,
1169- tpRef ,
1170- finalizer ,
1171- & defaultLabelSelector ,
1172- )
1173- if err != nil {
1174- return nil , err
1175- }
1176- }
1177- return podTopology , nil
1178- }
0 commit comments