Skip to content

Commit

Permalink
operator: speedup reloading of hooks configmap via annotating pods
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed May 24, 2022
1 parent 5c76782 commit 5a64da8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/go/k8s/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ rules:
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
Expand Down
2 changes: 1 addition & 1 deletion src/go/k8s/controllers/redpanda/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/go/k8s/pkg/resources/hooks_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ const (
defaultClusterHealthCheckTimeoutSeconds = 300
)

var (
hooksDigestAnnotationKey = redpandav1alpha1.GroupVersion.Group + "/hooks-digest"
)
var hooksHashAnnotationKey = redpandav1alpha1.GroupVersion.Group + "/hooks-hash"

var _ Resource = &HooksConfigMapResource{}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
})
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/go/k8s/pkg/resources/statefulset_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (r *StatefulSetResource) rollingUpdate(
ignoreKubernetesTokenVolumeMounts(),
ignoreDefaultToleration(),
ignoreExistingVolumes(volumes),
utils.IgnoreAnnotation(hooksHashAnnotationKey),
}

for i := range podList.Items {
Expand Down

0 comments on commit 5a64da8

Please sign in to comment.