Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hashed configs to pod annotations #469

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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),
},
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
Loading