@@ -317,6 +317,26 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
317317 }
318318 },
319319 },
320+ {
321+ name : "Create: MultiAdmin with ImagePullSecrets" ,
322+ cluster : func () * multigresv1alpha1.MultigresCluster {
323+ c := baseCluster .DeepCopy ()
324+ c .Spec .Images .ImagePullSecrets = []corev1.LocalObjectReference {{Name : "my-secret" }}
325+ return c
326+ }(),
327+ existingObjects : []client.Object {coreTpl , cellTpl , shardTpl },
328+ expectError : false ,
329+ validate : func (t * testing.T , c client.Client ) {
330+ ctx := context .Background ()
331+ deploy := & appsv1.Deployment {}
332+ if err := c .Get (ctx , types.NamespacedName {Name : clusterName + "-multiadmin" , Namespace : namespace }, deploy ); err != nil {
333+ t .Fatal ("MultiAdmin not created" )
334+ }
335+ if len (deploy .Spec .Template .Spec .ImagePullSecrets ) != 1 || deploy .Spec .Template .Spec .ImagePullSecrets [0 ].Name != "my-secret" {
336+ t .Errorf ("ImagePullSecrets not propagated. Got %v" , deploy .Spec .Template .Spec .ImagePullSecrets )
337+ }
338+ },
339+ },
320340 {
321341 name : "Create: Inline Etcd" ,
322342 cluster : func () * multigresv1alpha1.MultigresCluster {
@@ -475,6 +495,26 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
475495 expectError : true , // Updated to true because controller now enforces 50 char limit
476496 validate : func (t * testing.T , c client.Client ) {},
477497 },
498+ {
499+ name : "Create: No Global Topo Config" ,
500+ cluster : func () * multigresv1alpha1.MultigresCluster {
501+ c := baseCluster .DeepCopy ()
502+ c .Spec .GlobalTopoServer = multigresv1alpha1.GlobalTopoServerSpec {} // Empty
503+ c .Spec .TemplateDefaults = multigresv1alpha1.TemplateDefaults {} // Empty
504+ c .Spec .MultiAdmin = multigresv1alpha1.MultiAdminConfig {} // Empty
505+ return c
506+ }(),
507+ existingObjects : []client.Object {cellTpl , shardTpl }, // No Core Template
508+ expectError : false ,
509+ validate : func (t * testing.T , c client.Client ) {
510+ // Verify Cell got empty topo address
511+ cell := & multigresv1alpha1.Cell {}
512+ _ = c .Get (context .Background (), types.NamespacedName {Name : clusterName + "-zone-a" , Namespace : namespace }, cell )
513+ if cell .Spec .GlobalTopoServer .Address != "" {
514+ t .Errorf ("Expected empty topo address, got %q" , cell .Spec .GlobalTopoServer .Address )
515+ }
516+ },
517+ },
478518 {
479519 name : "Status: Aggregation Logic" ,
480520 cluster : func () * multigresv1alpha1.MultigresCluster {
@@ -602,6 +642,37 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
602642 // ---------------------------------------------------------------------
603643 // Error Injection Scenarios
604644 // ---------------------------------------------------------------------
645+ {
646+ name : "Error: Explicit Template Missing (Should Fail)" ,
647+ cluster : func () * multigresv1alpha1.MultigresCluster {
648+ c := baseCluster .DeepCopy ()
649+ c .Spec .TemplateDefaults .CoreTemplate = "non-existent-template"
650+ return c
651+ }(),
652+ existingObjects : []client.Object {}, // No templates exist
653+ failureConfig : nil , // No API failure, just logical failure
654+ expectError : true , // MUST ERROR NOW
655+ },
656+ {
657+ name : "Error: Explicit Cell Template Missing" ,
658+ cluster : func () * multigresv1alpha1.MultigresCluster {
659+ c := baseCluster .DeepCopy ()
660+ c .Spec .Cells [0 ].CellTemplate = "missing-cell-tpl"
661+ return c
662+ }(),
663+ existingObjects : []client.Object {coreTpl , shardTpl }, // Missing cellTpl
664+ expectError : true ,
665+ },
666+ {
667+ name : "Error: Explicit Shard Template Missing" ,
668+ cluster : func () * multigresv1alpha1.MultigresCluster {
669+ c := baseCluster .DeepCopy ()
670+ c .Spec .Databases [0 ].TableGroups [0 ].Shards [0 ].ShardTemplate = "missing-shard-tpl"
671+ return c
672+ }(),
673+ existingObjects : []client.Object {coreTpl , cellTpl }, // Missing shardTpl
674+ expectError : true ,
675+ },
605676 {
606677 name : "Error: Object Not Found (Clean Exit)" ,
607678 cluster : baseCluster .DeepCopy (),
@@ -913,6 +984,8 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
913984 c := baseCluster .DeepCopy ()
914985 c .Spec .TemplateDefaults .CoreTemplate = ""
915986 c .Spec .GlobalTopoServer .TemplateRef = "topo-fail-cells"
987+ // Clear MultiAdmin to ensure predictable call counts
988+ c .Spec .MultiAdmin = multigresv1alpha1.MultiAdminConfig {}
916989 return c
917990 }(),
918991 existingObjects : []client.Object {
@@ -928,8 +1001,8 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
9281001 return func (key client.ObjectKey ) error {
9291002 if key .Name == "topo-fail-cells" {
9301003 count ++
931- // Call 1: reconcileGlobalComponents (Succeed )
932- // Call 2: reconcileCells (Fail )
1004+ // Call 1: reconcileGlobalComponents -> ResolveCoreTemplate (Succeeds to proceed )
1005+ // Call 2: reconcileCells -> getGlobalTopoRef -> ResolveCoreTemplate (Fails )
9331006 if count == 2 {
9341007 return errBoom
9351008 }
@@ -946,6 +1019,8 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
9461019 c := baseCluster .DeepCopy ()
9471020 c .Spec .TemplateDefaults .CoreTemplate = ""
9481021 c .Spec .GlobalTopoServer .TemplateRef = "topo-fail-db"
1022+ // Clear MultiAdmin to ensure predictable call counts
1023+ c .Spec .MultiAdmin = multigresv1alpha1.MultiAdminConfig {}
9491024 return c
9501025 }(),
9511026 existingObjects : []client.Object {
@@ -961,9 +1036,9 @@ func TestMultigresClusterReconciler_Reconcile(t *testing.T) {
9611036 return func (key client.ObjectKey ) error {
9621037 if key .Name == "topo-fail-db" {
9631038 count ++
964- // Call 1: reconcileGlobalComponents (Succeed )
965- // Call 2: reconcileCells (Succeed )
966- // Call 3: reconcileDatabases (Fail )
1039+ // Call 1: reconcileGlobalComponents (Succeeds )
1040+ // Call 2: reconcileCells (Succeeds )
1041+ // Call 3: reconcileDatabases -> getGlobalTopoRef (Fails )
9671042 if count == 3 {
9681043 return errBoom
9691044 }
0 commit comments