Explorar o código

Changed the label-key format to match allocation. Format for a label's key entry is now '/key=value/' rather than '/value/'

Neal Ormsbee %!s(int64=5) %!d(string=hai) anos
pai
achega
266896ba17
Modificáronse 2 ficheiros con 7 adicións e 3 borrados
  1. 5 1
      pkg/kubecost/asset.go
  2. 2 2
      pkg/kubecost/asset_test.go

+ 5 - 1
pkg/kubecost/asset.go

@@ -107,7 +107,11 @@ func key(a Asset, aggregateBy []string) (string, error) {
 			key = a.Properties().Name
 		case strings.HasPrefix(s, "label:"):
 			if labelKey := strings.TrimPrefix(s, "label:"); labelKey != "" {
-				key = a.Labels()[labelKey]
+				labelVal, ok := a.Labels()[labelKey]
+				if !ok {
+					labelVal = "__undefined__"
+				}
+				key = fmt.Sprintf("%s=%s", labelKey, labelVal)
 			} else {
 				// Don't allow aggregating on label ""
 				return "", fmt.Errorf("Attempted to aggregate on invalid key: %s", s)

+ 2 - 2
pkg/kubecost/asset_test.go

@@ -697,8 +697,8 @@ func TestAssetSet_AggregateBy(t *testing.T) {
 	}
 	fmt.Println(as.assets)
 	assertAssetSet(t, as, "1e", window, map[string]float64{
-		"__undefined__": 53.00,
-		"test":          7.00,
+		"test=__undefined__": 53.00,
+		"test=test":          7.00,
 	}, nil)
 
 	// 2  Multi-aggregation