1111package zk
1212
1313import (
14+ "crypto/sha256"
15+ "encoding/hex"
1416 "fmt"
1517 "reflect"
1618 "strconv"
@@ -96,7 +98,7 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
9698 "kind" : "ZookeeperMember" ,
9799 },
98100 ),
99- Annotations : z . Spec . Pod . Annotations ,
101+ Annotations : makeZkPodAnnotations ( z ) ,
100102 },
101103 Spec : makeZkPodSpec (z , extraVolumes ),
102104 },
@@ -105,6 +107,22 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
105107 }
106108}
107109
110+ // makeZkPodAnnotations returns a map of annotations containing hashed zk config
111+ // and annotations from CR
112+ func makeZkPodAnnotations (z * v1beta1.ZookeeperCluster ) map [string ]string {
113+ podAnnotationFromCR := z .Spec .Pod .Annotations
114+ hashedZkConfig := sha256 .Sum256 ([]byte (makeZkConfigString (z )))
115+
116+ annotations := []map [string ]string {
117+ {
118+ "zookeeperConfig" : hex .EncodeToString (hashedZkConfig [:]),
119+ },
120+ podAnnotationFromCR ,
121+ }
122+
123+ return mergeAnnotations (annotations ... )
124+ }
125+
108126func makeZkPodSpec (z * v1beta1.ZookeeperCluster , volumes []v1.Volume ) v1.PodSpec {
109127 zkContainer := v1.Container {
110128 Name : "zookeeper" ,
@@ -398,6 +416,18 @@ func mergeLabels(l ...map[string]string) map[string]string {
398416 return res
399417}
400418
419+ // mergeAnnotations merges annotation maps
420+ func mergeAnnotations (annotations ... map [string ]string ) map [string ]string {
421+ res := make (map [string ]string )
422+
423+ for _ , a := range annotations {
424+ for k , v := range a {
425+ res [k ] = v
426+ }
427+ }
428+ return res
429+ }
430+
401431// Make a copy of map
402432func copyMap (s map [string ]string ) map [string ]string {
403433 res := make (map [string ]string )
0 commit comments