فهرست منبع

Add append method for AssetLabels

Bianca Burtoiu 4 سال پیش
والد
کامیت
cb2ed10c30
1فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 19 0
      pkg/kubecost/asset.go

+ 19 - 0
pkg/kubecost/asset.go

@@ -358,6 +358,25 @@ func (al AssetLabels) Merge(that AssetLabels) AssetLabels {
 	return result
 }
 
+// Append joins the existing AssetLabels with a given map of labels
+func (al AssetLabels) Append(newLabels map[string]string) AssetLabels {
+	if al == nil {
+		// If the asset didn't have labels before, it will now
+		return newLabels
+	}
+
+	if len(newLabels) == 0 {
+		return al
+	}
+
+	// If a label with the given name already exists, its value will be overwritten by this input
+	for label, value := range newLabels {
+		al[label] = value
+	}
+
+	return al
+}
+
 // 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