From 4d21a20e3b5e7b2bd1d98458861cd3e881fb854f Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Thu, 12 Sep 2024 16:03:58 -0700 Subject: [PATCH] Fix node spec podLabels bug The operator does not add node spec's podLabels to the statefulsets unless a user also defines podLabels for the cluster spec. This change will always add both cluster and node spec podLabels as long as they are defined. If same labels are defined for both cluster spec and pod spec then it'll prefer node spec values over cluster spec. --- controllers/druid/handler.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/controllers/druid/handler.go b/controllers/druid/handler.go index 7c951bbc..c47032cc 100644 --- a/controllers/druid/handler.go +++ b/controllers/druid/handler.go @@ -1268,17 +1268,16 @@ func makeLabelsForDruid(druid *v1alpha1.Druid) map[string]string { } // makeLabelsForDruid returns the labels for selecting the resources -// belonging to the given druid CR name. +// belonging to the given druid CR name. adds labels from both node & +// cluster specs. node spec labels will take precedence over clusters labels func makeLabelsForNodeSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, clusterName, nodeSpecUniqueStr string) map[string]string { var labels = map[string]string{} - // if both labels are present at both cluster and node spec - // labels should be merged. - if nodeSpec.PodLabels != nil && m.Spec.PodLabels != nil { - labels = nodeSpec.PodLabels + for k, v := range m.Spec.PodLabels { + labels[k] = v } - for k, v := range m.Spec.PodLabels { + for k, v := range nodeSpec.PodLabels { labels[k] = v }