From 2a64a7b2a847323b96eb41a4096d9e133ed827bb Mon Sep 17 00:00:00 2001 From: apedriza Date: Thu, 31 Oct 2024 15:42:49 +0100 Subject: [PATCH] Fix cluster annotations propagation to statefulset and pods (#800) Signed-off-by: Adrian Pedriza Co-authored-by: Adrian Pedriza --- .../k0smotron.io/k0smotroncluster_statefulset.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go b/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go index 9a4c5665f..2ff1e6d7a 100644 --- a/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go +++ b/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go @@ -52,6 +52,7 @@ func (r *ClusterReconciler) findStatefulSetPod(ctx context.Context, statefulSet func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulSet, error) { labels := labelsForCluster(kmc) + annotations := annotationsForCluster(kmc) statefulSet := apps.StatefulSet{ TypeMeta: metav1.TypeMeta{ @@ -59,10 +60,9 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS Kind: "StatefulSet", }, ObjectMeta: metav1.ObjectMeta{ - Name: kmc.GetStatefulSetName(), - Namespace: kmc.Namespace, - Labels: labels, - Annotations: annotationsForCluster(kmc), + Name: kmc.GetStatefulSetName(), + Namespace: kmc.Namespace, + Labels: labels, }, Spec: apps.StatefulSetSpec{ Selector: &metav1.LabelSelector{ @@ -71,7 +71,8 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS Replicas: &kmc.Spec.Replicas, Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: labels, + Labels: labels, + Annotations: annotations, }, Spec: v1.PodSpec{ AutomountServiceAccountToken: ptr.To(false), @@ -310,6 +311,9 @@ data: statefulSet.Annotations = map[string]string{ statefulSetAnnotation: controller.ComputeHash(&statefulSet.Spec.Template, statefulSet.Status.CollisionCount), } + for k, v := range annotations { + statefulSet.Annotations[k] = v + } return statefulSet, err }