Skip to content

Commit

Permalink
Add hashed configs to pod annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyhbx committed Apr 28, 2022
1 parent 1001aac commit 013762c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pkg/zk/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package zk

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"reflect"
"strconv"
Expand Down Expand Up @@ -96,7 +98,7 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
"kind": "ZookeeperMember",
},
),
Annotations: z.Spec.Pod.Annotations,
Annotations: makeZkPodAnnotations(z),
},
Spec: makeZkPodSpec(z, extraVolumes),
},
Expand All @@ -105,6 +107,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",
Expand Down Expand Up @@ -398,6 +416,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)
Expand Down

0 comments on commit 013762c

Please sign in to comment.