From a085689358d66908290e27e42512c61a727b8921 Mon Sep 17 00:00:00 2001 From: nicolaferraro Date: Tue, 24 May 2022 12:06:24 +0200 Subject: [PATCH] operator: speedup reloading of hooks configmap via annotating pods --- src/go/k8s/config/rbac/role.yaml | 2 ++ src/go/k8s/controllers/redpanda/cluster_controller.go | 2 +- src/go/k8s/pkg/resources/hooks_configmap.go | 10 ++++------ src/go/k8s/pkg/resources/statefulset_update.go | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/go/k8s/config/rbac/role.yaml b/src/go/k8s/config/rbac/role.yaml index e960c798bd17..df4f131abd19 100644 --- a/src/go/k8s/config/rbac/role.yaml +++ b/src/go/k8s/config/rbac/role.yaml @@ -59,6 +59,8 @@ rules: - delete - get - list + - patch + - update - watch - apiGroups: - "" diff --git a/src/go/k8s/controllers/redpanda/cluster_controller.go b/src/go/k8s/controllers/redpanda/cluster_controller.go index 815caeff9fe1..31ab4dbdac50 100644 --- a/src/go/k8s/controllers/redpanda/cluster_controller.go +++ b/src/go/k8s/controllers/redpanda/cluster_controller.go @@ -60,7 +60,7 @@ type ClusterReconciler struct { //+kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch; //+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch; -//+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;delete +//+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;update;patch;delete //+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create; //+kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;list;watch;create;update;patch; //+kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings,verbs=get;list;watch;create;update;patch; diff --git a/src/go/k8s/pkg/resources/hooks_configmap.go b/src/go/k8s/pkg/resources/hooks_configmap.go index 97ec3d070c0c..c5a6e7f615c7 100644 --- a/src/go/k8s/pkg/resources/hooks_configmap.go +++ b/src/go/k8s/pkg/resources/hooks_configmap.go @@ -44,9 +44,7 @@ const ( defaultClusterHealthCheckTimeoutSeconds = 300 ) -var ( - hooksDigestAnnotationKey = redpandav1alpha1.GroupVersion.Group + "/hooks-digest" -) +var hooksHashAnnotationKey = redpandav1alpha1.GroupVersion.Group + "/hooks-hash" var _ Resource = &HooksConfigMapResource{} @@ -372,7 +370,7 @@ func (r *HooksConfigMapResource) getHealthCheckTimeout() int { func (r *HooksConfigMapResource) forceConfigMapReload( ctx context.Context, cm *corev1.ConfigMap, ) error { - digest, err := r.computeDigest(cm) + digest, err := r.computeHash(cm) if err != nil { return fmt.Errorf("could not compute digest for ConfigMap %s: %w", cm.Name, err) } @@ -396,7 +394,7 @@ func (r *HooksConfigMapResource) forceConfigMapReload( if pod.Annotations == nil { pod.Annotations = make(map[string]string, 1) } - pod.Annotations[hooksDigestAnnotationKey] = digest + pod.Annotations[hooksHashAnnotationKey] = digest return r.Update(ctx, pod) }) @@ -407,7 +405,7 @@ func (r *HooksConfigMapResource) forceConfigMapReload( return nil } -func (r *HooksConfigMapResource) computeDigest( +func (r *HooksConfigMapResource) computeHash( cm *corev1.ConfigMap, ) (string, error) { elements := make([]string, 0, len(cm.Data)) diff --git a/src/go/k8s/pkg/resources/statefulset_update.go b/src/go/k8s/pkg/resources/statefulset_update.go index 24e20989af30..163f615818e0 100644 --- a/src/go/k8s/pkg/resources/statefulset_update.go +++ b/src/go/k8s/pkg/resources/statefulset_update.go @@ -119,6 +119,7 @@ func (r *StatefulSetResource) rollingUpdate( ignoreKubernetesTokenVolumeMounts(), ignoreDefaultToleration(), ignoreExistingVolumes(volumes), + utils.IgnoreAnnotation(hooksHashAnnotationKey), } for i := range podList.Items {