diff --git a/pkg/zk/generators.go b/pkg/zk/generators.go index f13ae37b..a8d4167c 100644 --- a/pkg/zk/generators.go +++ b/pkg/zk/generators.go @@ -11,6 +11,8 @@ package zk import ( + "crypto/sha256" + "encoding/hex" "fmt" "reflect" "strconv" @@ -98,7 +100,7 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet { "kind": "ZookeeperMember", }, ), - Annotations: z.Spec.Pod.Annotations, + Annotations: makeZkPodAnnotations(z), }, Spec: makeZkPodSpec(z, extraVolumes), }, @@ -107,6 +109,22 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet { } } +// makeZkPodAnnotations returns a map of annotations containing hashed zk config +// and annotations from CR +func makeZkPodAnnotations(z *v1beta1.ZookeeperCluster) map[string]string { + podAnnotationFromCR := z.Spec.Pod.Annotations + hashedZkConfig := sha256.Sum256([]byte(makeZkConfigString(z))) + + annotations := []map[string]string{ + { + "zookeeperConfig": hex.EncodeToString(hashedZkConfig[:]), + }, + podAnnotationFromCR, + } + + return mergeAnnotations(annotations...) +} + func makeZkPodSpec(z *v1beta1.ZookeeperCluster, volumes []v1.Volume) v1.PodSpec { zkContainer := v1.Container{ Name: "zookeeper", @@ -401,6 +419,18 @@ func mergeLabels(l ...map[string]string) map[string]string { return res } +// mergeAnnotations merges annotation maps +func mergeAnnotations(annotations ...map[string]string) map[string]string { + res := make(map[string]string) + + for _, a := range annotations { + for k, v := range a { + res[k] = v + } + } + return res +} + // Make a copy of map func copyMap(s map[string]string) map[string]string { res := make(map[string]string)