Skip to content

Commit

Permalink
Remove duplication
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Sep 12, 2018
1 parent bd39ddc commit 70d2193
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions pkg/skaffold/deploy/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ func merge(sources ...Labeller) map[string]string {
merged := make(map[string]string)

for _, src := range sources {
if src != nil {
for k, v := range src.Labels() {
merged[k] = v
}
}
copyMap(merged, src.Labels())
}

return merged
Expand Down Expand Up @@ -118,19 +114,13 @@ func labelDeployResults(labels map[string]string, results []Artifact) {
}

func addLabels(labels map[string]string, accessor metav1.Object) {
objLabels := accessor.GetLabels()
if objLabels == nil {
objLabels = make(map[string]string)
}
for k, v := range constants.Labels.DefaultLabels {
if _, ok := objLabels[k]; !ok {
objLabels[k] = v
}
}
for key, value := range labels {
objLabels[key] = value
}
accessor.SetLabels(objLabels)
kv := make(map[string]string)

copyMap(kv, constants.Labels.DefaultLabels)
copyMap(kv, accessor.GetLabels())
copyMap(kv, labels)

accessor.SetLabels(kv)
}

func updateRuntimeObject(client dynamic.Interface, disco discovery.DiscoveryInterface, labels map[string]string, res Artifact) error {
Expand Down Expand Up @@ -202,3 +192,9 @@ func groupVersionResource(disco discovery.DiscoveryInterface, gvk schema.GroupVe

return schema.GroupVersionResource{}, fmt.Errorf("Could not find resource for %s", gvk.String())
}

func copyMap(dest, from map[string]string) {
for k, v := range from {
dest[k] = v
}
}

0 comments on commit 70d2193

Please sign in to comment.