Skip to content

Commit

Permalink
Fix node spec podLabels bug
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
owais committed Sep 13, 2024
1 parent e5f726e commit fff64f6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions controllers/druid/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fff64f6

Please sign in to comment.