@@ -105,6 +105,7 @@ func (r *ClusterBootstrapConfigReconciler) Reconcile(ctx context.Context, req ct
105
105
return ctrl.Result {RequeueAfter : clusterBootstrapConfig .ClusterReadinessRequeue ()}, nil
106
106
}
107
107
}
108
+
108
109
if err := bootstrapClusterWithConfig (ctx , logger , r .Client , cluster , & clusterBootstrapConfig ); err != nil {
109
110
return ctrl.Result {}, fmt .Errorf ("failed to bootstrap cluster config: %w" , err )
110
111
}
@@ -116,9 +117,11 @@ func (r *ClusterBootstrapConfigReconciler) Reconcile(ctx context.Context, req ct
116
117
},
117
118
},
118
119
})
120
+
119
121
if err != nil {
120
122
return ctrl.Result {}, fmt .Errorf ("failed to create a patch to update the cluster annotations: %w" , err )
121
123
}
124
+
122
125
if err := r .Client .Patch (ctx , cluster , client .RawPatch (types .MergePatchType , mergePatch )); err != nil {
123
126
return ctrl.Result {}, fmt .Errorf ("failed to annotate cluster %s/%s as bootstrapped: %w" , cluster .ObjectMeta .Name , cluster .ObjectMeta .Namespace , err )
124
127
}
@@ -127,10 +130,22 @@ func (r *ClusterBootstrapConfigReconciler) Reconcile(ctx context.Context, req ct
127
130
}
128
131
129
132
func appendClusterConfigToBootstrappedList (config capiv1alpha1.ClusterBootstrapConfig , cluster * clustersv1.GitopsCluster ) string {
130
- current := cluster .GetAnnotations ()[capiv1alpha1 .BootstrapConfigsAnnotation ]
131
- set := sets .NewString (strings .Split (current , "," )... )
132
- id := fmt .Sprintf ("%s/%s" , config .GetNamespace (), config .GetName ())
133
- set .Insert (id )
133
+ set := sets .NewString ()
134
+
135
+ current := func (ann string ) []string {
136
+ nonempty := []string {}
137
+ for _ , s := range strings .Split (ann , "," ) {
138
+ if s != "" {
139
+ nonempty = append (nonempty , s )
140
+ }
141
+ }
142
+
143
+ return nonempty
144
+ }(cluster .GetAnnotations ()[capiv1alpha1 .BootstrapConfigsAnnotation ])
145
+ set .Insert (current ... )
146
+
147
+ set .Insert (fmt .Sprintf ("%s/%s" , config .GetNamespace (), config .GetName ()))
148
+
134
149
return strings .Join (set .List (), "," )
135
150
}
136
151
0 commit comments