Skip to content

Commit 0d08400

Browse files
authored
Merge pull request #856 from PavanNeerudu/user/pavanneerudu/addwatches-for-cm
✨ Add ConfigMap watching capability to trigger provider upgrades
2 parents 2f62be9 + 698b837 commit 0d08400

File tree

8 files changed

+845
-2
lines changed

8 files changed

+845
-2
lines changed

cmd/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
webhookCertDir string
7171
healthAddr string
7272
watchConfigSecretChanges bool
73+
watchConfigMapChanges bool
7374
managerOptions = flags.ManagerOptions{}
7475
)
7576

@@ -103,6 +104,9 @@ func InitFlags(fs *pflag.FlagSet) {
103104
fs.BoolVar(&watchConfigSecretChanges, "watch-configsecret", false,
104105
"Watch for changes to the ConfigSecret resource and reconcile all providers using it.")
105106

107+
fs.BoolVar(&watchConfigMapChanges, "watch-configmap", false,
108+
"Watch for changes to ConfigMaps used by providers with fetchConfig.selector and reconcile all providers using them.")
109+
106110
fs.StringVar(&watchNamespace, "namespace", "",
107111
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
108112

@@ -201,7 +205,7 @@ func main() {
201205
ctx := ctrl.SetupSignalHandler()
202206

203207
setupChecks(mgr)
204-
setupReconcilers(ctx, mgr, watchConfigSecretChanges)
208+
setupReconcilers(ctx, mgr, watchConfigSecretChanges, watchConfigMapChanges)
205209
setupWebhooks(mgr)
206210

207211
// +kubebuilder:scaffold:builder
@@ -225,13 +229,14 @@ func setupChecks(mgr ctrl.Manager) {
225229
}
226230
}
227231

228-
func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretChanges bool) {
232+
func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretChanges, watchConfigMapChanges bool) {
229233
if err := (&providercontroller.GenericProviderReconciler{
230234
Provider: &operatorv1.CoreProvider{},
231235
ProviderList: &operatorv1.CoreProviderList{},
232236
Client: mgr.GetClient(),
233237
Config: mgr.GetConfig(),
234238
WatchConfigSecretChanges: watchConfigSecretChanges,
239+
WatchConfigMapChanges: watchConfigMapChanges,
235240
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
236241
setupLog.Error(err, "unable to create controller", "controller", "CoreProvider")
237242
os.Exit(1)
@@ -243,6 +248,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretCh
243248
Client: mgr.GetClient(),
244249
Config: mgr.GetConfig(),
245250
WatchConfigSecretChanges: watchConfigSecretChanges,
251+
WatchConfigMapChanges: watchConfigMapChanges,
246252
WatchCoreProviderChanges: true,
247253
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
248254
setupLog.Error(err, "unable to create controller", "controller", "InfrastructureProvider")
@@ -255,6 +261,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretCh
255261
Client: mgr.GetClient(),
256262
Config: mgr.GetConfig(),
257263
WatchConfigSecretChanges: watchConfigSecretChanges,
264+
WatchConfigMapChanges: watchConfigMapChanges,
258265
WatchCoreProviderChanges: true,
259266
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
260267
setupLog.Error(err, "unable to create controller", "controller", "BootstrapProvider")
@@ -267,6 +274,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretCh
267274
Client: mgr.GetClient(),
268275
Config: mgr.GetConfig(),
269276
WatchConfigSecretChanges: watchConfigSecretChanges,
277+
WatchConfigMapChanges: watchConfigMapChanges,
270278
WatchCoreProviderChanges: true,
271279
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
272280
setupLog.Error(err, "unable to create controller", "controller", "ControlPlaneProvider")
@@ -279,6 +287,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretCh
279287
Client: mgr.GetClient(),
280288
Config: mgr.GetConfig(),
281289
WatchConfigSecretChanges: watchConfigSecretChanges,
290+
WatchConfigMapChanges: watchConfigMapChanges,
282291
WatchCoreProviderChanges: true,
283292
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
284293
setupLog.Error(err, "unable to create controller", "controller", "AddonProvider")
@@ -291,6 +300,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretCh
291300
Client: mgr.GetClient(),
292301
Config: mgr.GetConfig(),
293302
WatchConfigSecretChanges: watchConfigSecretChanges,
303+
WatchConfigMapChanges: watchConfigMapChanges,
294304
WatchCoreProviderChanges: true,
295305
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
296306
setupLog.Error(err, "unable to create controller", "controller", "IPAMProvider")
@@ -303,6 +313,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager, watchConfigSecretCh
303313
Client: mgr.GetClient(),
304314
Config: mgr.GetConfig(),
305315
WatchConfigSecretChanges: watchConfigSecretChanges,
316+
WatchConfigMapChanges: watchConfigMapChanges,
306317
WatchCoreProviderChanges: true,
307318
}).SetupWithManager(ctx, mgr, concurrency(concurrencyNumber)); err != nil {
308319
setupLog.Error(err, "unable to create controller", "controller", "RuntimeExtensionProvider")

hack/charts/cluster-api-operator/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ spec:
7474
{{- if .Values.watchConfigSecret }}
7575
- --watch-configsecret
7676
{{- end }}
77+
{{- if .Values.watchConfigMap }}
78+
- --watch-configmap
79+
{{- end }}
7780
{{- with .Values.leaderElection }}
7881
- --leader-elect={{ .enabled }}
7982
{{- if .leaseDuration }}

hack/charts/cluster-api-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ profilerAddress: ":6060"
6464
contentionProfiling: false
6565
insecureDiagnostics: false
6666
watchConfigSecret: false
67+
watchConfigMap: false
6768
imagePullSecrets: {}
6869
resources:
6970
manager:

0 commit comments

Comments
 (0)