From dd6e5d9389f91efa1ca040ac48ff581ce061e3a2 Mon Sep 17 00:00:00 2001 From: zoetrope Date: Fri, 28 Jun 2024 04:46:32 +0000 Subject: [PATCH] Sort namespace in generated configmaps. Because the order of client-go's List is random, ConfigMap will be updated indefinitely. --- controllers/tenant_controller.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/controllers/tenant_controller.go b/controllers/tenant_controller.go index 3cec08b..f6af009 100644 --- a/controllers/tenant_controller.go +++ b/controllers/tenant_controller.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "slices" "strings" "text/template" @@ -611,6 +612,7 @@ func (r *TenantReconciler) updateConfigMap(ctx context.Context, controllerName s namespaces = append(namespaces, ns.Name) } } + slices.Sort(namespaces) op, err := ctrl.CreateOrUpdate(ctx, r.client, cm, func() error { cm.Labels = map[string]string{ @@ -635,7 +637,7 @@ func (r *TenantReconciler) updateConfigMap(ctx context.Context, controllerName s return err } if op != controllerutil.OperationResultNone { - logger.Info("ConfigMap successfully reconciled") + logger.Info("ConfigMap successfully reconciled", "namespaces", namespaces) } return nil @@ -665,6 +667,7 @@ func (r *TenantReconciler) updateAllTenantNamespacesConfigMap(ctx context.Contex allNamespaces = append(allNamespaces, ns.Name) } } + slices.Sort(allNamespaces) op, err := ctrl.CreateOrUpdate(ctx, r.client, cm, func() error { cm.Labels = map[string]string{ @@ -688,7 +691,7 @@ func (r *TenantReconciler) updateAllTenantNamespacesConfigMap(ctx context.Contex return err } if op != controllerutil.OperationResultNone { - logger.Info("ConfigMap successfully reconciled") + logger.Info("ConfigMap successfully reconciled", "allNamespaces", allNamespaces) } return nil