Skip to content

Commit

Permalink
Changed label parsing to handle nested use case
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrokethecloud committed Apr 7, 2021
1 parent 5903aa6 commit c085dd6
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions pkg/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,7 @@ func addClusterLabels(opts *fleet.BundleDeploymentOptions, labels map[string]str
return
}

prefix := "global.fleet.clusterLabels."

for key, val := range opts.Helm.Values.Data {
valStr, ok := val.(string)
if ok && strings.HasPrefix(valStr, prefix) {
label := strings.TrimPrefix(valStr, prefix)
labelVal, labelPresent := clusterLabels[label]
if labelPresent {
opts.Helm.Values.Data[key] = labelVal
}
}
}
processLabelValues(opts.Helm.Values.Data, clusterLabels)

opts.Helm.Values.Data = data.MergeMaps(opts.Helm.Values.Data, newValues)

Expand Down Expand Up @@ -512,3 +501,21 @@ func Summary(targets []*Target) fleet.BundleSummary {
}
return bundleSummary
}

func processLabelValues(valuesMap map[string]interface{}, clusterLabels map[string]string) {
prefix := "global.fleet.clusterLabels."
for key, val := range valuesMap {
valStr, ok := val.(string)
if ok && strings.HasPrefix(valStr, prefix) {
label := strings.TrimPrefix(valStr, prefix)
labelVal, labelPresent := clusterLabels[label]
if labelPresent {
valuesMap[key] = labelVal
}
}

if valMap, ok := val.(map[string]interface{}); ok {
processLabelValues(valMap, clusterLabels)
}
}
}

0 comments on commit c085dd6

Please sign in to comment.