From 80d450e98012caf5f000fbcf752084cb064e4577 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Wed, 25 Sep 2024 18:26:50 +0400 Subject: [PATCH] fix(k8-operator): updating CRD does not reflect in operator --- k8-operator/controllers/infisicalsecret_controller.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/k8-operator/controllers/infisicalsecret_controller.go b/k8-operator/controllers/infisicalsecret_controller.go index 2d7089d5d..b40a9a2c8 100644 --- a/k8-operator/controllers/infisicalsecret_controller.go +++ b/k8-operator/controllers/infisicalsecret_controller.go @@ -187,12 +187,18 @@ func (r *InfisicalSecretReconciler) Reconcile(ctx context.Context, req ctrl.Requ func (r *InfisicalSecretReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&secretsv1alpha1.InfisicalSecret{}). + // For the Infisical Secret CRD we specifically watch for the update event, because we need to delete the entry in the resourceVariablesMap, so it will refresh the variables used to fetch secrets. + For(&secretsv1alpha1.InfisicalSecret{}, builder.WithPredicates(predicate.Funcs{ + UpdateFunc: func(e event.UpdateEvent) bool { + delete(resourceVariablesMap, string(e.ObjectNew.GetUID())) + return true + }, + })). + // We only monitor the delete events for the Secret resource, so we can handle them in a finalizer. Watches( &source.Kind{Type: &corev1.Secret{}}, handler.EnqueueRequestsFromMapFunc(r.handleManagedSecretDeletion), builder.WithPredicates(predicate.Funcs{ - // Always return true to ensure we process all delete events DeleteFunc: func(e event.DeleteEvent) bool { return true },