From 66fcc71b23cf57203cc923e98b5a2e80071549e4 Mon Sep 17 00:00:00 2001 From: Nick Huanca <1903525+endzyme@users.noreply.github.com> Date: Thu, 12 Jan 2023 21:10:45 -0700 Subject: [PATCH] Adjust behavior for pod labels (#521) Pod labels from the Spec.Pod.Labels were previously not propagated to the StatefulSet.Template. This change notes the differences between the two Label locations in the ZookeeperCluster CRD and denotes priority ordering. Signed-off-by: Nick Huanca <1903525+endzyme@users.noreply.github.com> Signed-off-by: Nick Huanca <1903525+endzyme@users.noreply.github.com> Co-authored-by: anishakj <43978302+anishakj@users.noreply.github.com> --- api/v1beta1/zookeepercluster_types.go | 9 +++++---- .../zookeeper.pravega.io_zookeeperclusters_crd.yaml | 8 +++++--- .../bases/zookeeper.pravega.io_zookeeperclusters.yaml | 8 +++++--- pkg/zk/generators.go | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/api/v1beta1/zookeepercluster_types.go b/api/v1beta1/zookeepercluster_types.go index 8985daba..a1269b86 100644 --- a/api/v1beta1/zookeepercluster_types.go +++ b/api/v1beta1/zookeepercluster_types.go @@ -82,8 +82,9 @@ type ZookeeperClusterSpec struct { // Image is the container image. default is zookeeper:0.2.10 Image ContainerImage `json:"image,omitempty"` - // Labels specifies the labels to attach to pods the operator creates for - // the zookeeper cluster. + // Labels specifies the labels to attach to all resources the operator + // creates for the zookeeper cluster, including StatefulSet, Pod, + // PersistentVolumeClaim, Service, ConfigMap, et al. Labels map[string]string `json:"labels,omitempty"` // Replicas is the expected size of the zookeeper cluster. @@ -433,8 +434,8 @@ func (c *ContainerImage) ToString() string { // PodPolicy defines the common pod configuration for Pods, including when used // in deployments, stateful-sets, etc. type PodPolicy struct { - // Labels specifies the labels to attach to pods the operator creates for - // the zookeeper cluster. + // Labels specifies the labels to attach to pods the operator creates for the + // zookeeper cluster. Overrides any values specified in Spec.Labels. Labels map[string]string `json:"labels,omitempty"` // NodeSelector specifies a map of key-value pairs. For the pod to be diff --git a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml index c38f3a43..c6597475 100644 --- a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml +++ b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml @@ -2684,8 +2684,9 @@ spec: labels: additionalProperties: type: string - description: Labels specifies the labels to attach to pods the operator - creates for the zookeeper cluster. + description: Labels specifies the labels to attach to all resources + the operator creates for the zookeeper cluster, including StatefulSet, + Pod, PersistentVolumeClaim, Service, ConfigMap, et al. type: object maxUnavailableReplicas: description: MaxUnavailableReplicas defines the MaxUnavailable Replicas @@ -3875,7 +3876,8 @@ spec: additionalProperties: type: string description: Labels specifies the labels to attach to pods the - operator creates for the zookeeper cluster. + operator creates for the zookeeper cluster. Overrides any values + specified in Spec.Labels. type: object nodeSelector: additionalProperties: diff --git a/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml b/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml index af5084e8..44b0d742 100644 --- a/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml +++ b/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml @@ -2683,8 +2683,9 @@ spec: labels: additionalProperties: type: string - description: Labels specifies the labels to attach to pods the operator - creates for the zookeeper cluster. + description: Labels specifies the labels to attach to all resources + the operator creates for the zookeeper cluster, including StatefulSet, + Pod, PersistentVolumeClaim, Service, ConfigMap, et al. type: object maxUnavailableReplicas: description: MaxUnavailableReplicas defines the MaxUnavailable Replicas @@ -3874,7 +3875,8 @@ spec: additionalProperties: type: string description: Labels specifies the labels to attach to pods the - operator creates for the zookeeper cluster. + operator creates for the zookeeper cluster. Overrides any values + specified in Spec.Labels. type: object nodeSelector: additionalProperties: diff --git a/pkg/zk/generators.go b/pkg/zk/generators.go index fddb4872..f13ae37b 100644 --- a/pkg/zk/generators.go +++ b/pkg/zk/generators.go @@ -92,6 +92,7 @@ func MakeStatefulSet(z *v1beta1.ZookeeperCluster) *appsv1.StatefulSet { GenerateName: z.GetName(), Labels: mergeLabels( z.Spec.Labels, + z.Spec.Pod.Labels, map[string]string{ "app": z.GetName(), "kind": "ZookeeperMember",