Przeglądaj źródła

Re-implemented 'propsEqual' check in accumulate(). Can't be exactly propsEqual() because they aren't props anymore...but wrote equivalent functions for []string

Neal Ormsbee 5 lat temu
rodzic
commit
7499872b48
1 zmienionych plików z 26 dodań i 2 usunięć
  1. 26 2
      pkg/kubecost/asset.go

+ 26 - 2
pkg/kubecost/asset.go

@@ -2672,8 +2672,10 @@ func (as *AssetSet) accumulate(that *AssetSet) (*AssetSet, error) {
 	// In the case of an AssetSetRange with empty entries, we may end up with
 	// In the case of an AssetSetRange with empty entries, we may end up with
 	// an incoming `as` without an `aggregateBy`, even though we are tring to
 	// an incoming `as` without an `aggregateBy`, even though we are tring to
 	// aggregate here. This handles that case by assigning the correct `aggregateBy`.
 	// aggregate here. This handles that case by assigning the correct `aggregateBy`.
-	if len(as.aggregateBy) == 0 {
-		as.aggregateBy = that.aggregateBy
+	if !sameContents(as.aggregateBy, that.aggregateBy) {
+		if len(as.aggregateBy) == 0 {
+			as.aggregateBy = that.aggregateBy
+		}
 	}
 	}
 
 
 	// Set start, end to min(start), max(end)
 	// Set start, end to min(start), max(end)
@@ -2865,3 +2867,25 @@ func jsonEncode(buffer *bytes.Buffer, name string, obj interface{}, comma string
 	}
 	}
 	buffer.WriteString(comma)
 	buffer.WriteString(comma)
 }
 }
+
+// Returns true if string slices a and b contain all of the same strings, in any order.
+func sameContents(a, b []string) bool {
+	if len(a) != len(b) {
+		return false
+	}
+	for i := range a {
+		if !contains(b, a[i]) {
+			return false
+		}
+	}
+	return true
+}
+
+func contains(slice []string, item string) bool {
+	for _, element := range slice {
+		if element == item {
+			return true
+		}
+	}
+	return false
+}