Przeglądaj źródła

Merge pull request #1166 from kubecost/biancaburtoiu/support-append-labels

Add append method for AssetLabels
Bianca Burtoiu 4 lat temu
rodzic
commit
257557bd70
1 zmienionych plików z 17 dodań i 0 usunięć
  1. 17 0
      pkg/kubecost/asset.go

+ 17 - 0
pkg/kubecost/asset.go

@@ -358,6 +358,23 @@ func (al AssetLabels) Merge(that AssetLabels) AssetLabels {
 	return result
 }
 
+// Append joins AssetLabels with a given map of labels
+func (al AssetLabels) Append(newLabels map[string]string, overwrite bool) {
+	if len(newLabels) == 0 {
+		return
+	}
+
+	for label, value := range newLabels {
+		if _, ok := al[label]; ok {
+			if overwrite {
+				al[label] = value
+			}
+		} else {
+			al[label] = value
+		}
+	}
+}
+
 // AssetMatchFunc is a function that can be used to match Assets by
 // returning true for any given Asset if a condition is met.
 type AssetMatchFunc func(Asset) bool