11
11
package zk
12
12
13
13
import (
14
+ "crypto/sha256"
15
+ "encoding/hex"
14
16
"fmt"
15
17
"reflect"
16
18
"strconv"
@@ -96,7 +98,7 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
96
98
"kind" : "ZookeeperMember" ,
97
99
},
98
100
),
99
- Annotations : z . Spec . Pod . Annotations ,
101
+ Annotations : makeZkPodAnnotations ( z ) ,
100
102
},
101
103
Spec : makeZkPodSpec (z , extraVolumes ),
102
104
},
@@ -105,6 +107,22 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
105
107
}
106
108
}
107
109
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
+
108
126
func makeZkPodSpec (z * v1beta1.ZookeeperCluster , volumes []v1.Volume ) v1.PodSpec {
109
127
zkContainer := v1.Container {
110
128
Name : "zookeeper" ,
@@ -398,6 +416,18 @@ func mergeLabels(l ...map[string]string) map[string]string {
398
416
return res
399
417
}
400
418
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
+
401
431
// Make a copy of map
402
432
func copyMap (s map [string ]string ) map [string ]string {
403
433
res := make (map [string ]string )
0 commit comments