Skip to content

Commit

Permalink
ISSUE-257 Propagate labels to ZookeeperCluster underlying resources
Browse files Browse the repository at this point in the history
  • Loading branch information
amuraru committed Oct 12, 2020
1 parent 0c54143 commit 5f382bd
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions pkg/zk/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
} else {
pvcs = append(pvcs, v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: zkDataVolume,
Labels: map[string]string{"app": z.GetName()},
Name: zkDataVolume,
Labels: mergeLabels(
z.Spec.Labels,
map[string]string{"app": z.GetName()},
),
},
Spec: persistence.PersistentVolumeClaimSpec,
})
Expand Down Expand Up @@ -85,10 +88,13 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet {
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
GenerateName: z.GetName(),
Labels: map[string]string{
"app": z.GetName(),
"kind": "ZookeeperMember",
},
Labels: mergeLabels(
z.Spec.Labels,
map[string]string{
"app": z.GetName(),
"kind": "ZookeeperMember",
},
),
},
Spec: makeZkPodSpec(z, extraVolumes),
},
Expand Down Expand Up @@ -282,7 +288,10 @@ func makeService(name string, ports []v1.ServicePort, clusterIP bool, z *v1beta1
Name: name,
Namespace: z.Namespace,

Labels: map[string]string{"app": z.GetName(), "headless": strconv.FormatBool(!clusterIP)},
Labels: mergeLabels(
z.Spec.Labels,
map[string]string{"app": z.GetName(), "headless": strconv.FormatBool(!clusterIP)},
),
Annotations: annotationMap,
},
Spec: v1.ServiceSpec{
Expand Down Expand Up @@ -318,3 +327,15 @@ func MakePodDisruptionBudget(z *v1beta1.ZookeeperCluster) *policyv1beta1.PodDisr
},
}
}

// MergeLabels merges label maps
func mergeLabels(l ...map[string]string) map[string]string {
res := make(map[string]string)

for _, v := range l {
for lKey, lValue := range v {
res[lKey] = lValue
}
}
return res
}

0 comments on commit 5f382bd

Please sign in to comment.