Browse Source

KCM-5277 add account to allocation field (#3632)

Signed-off-by: Hudong Wang <Hudong.Wang@ibm.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Hudong Wang 2 tháng trước cách đây
mục cha
commit
a8a07b0303

+ 1 - 0
core/pkg/filter/allocation/fields.go

@@ -21,6 +21,7 @@ const (
 	FieldPod            AllocationField = AllocationField(fieldstrings.FieldPod)
 	FieldContainer      AllocationField = AllocationField(fieldstrings.FieldContainer)
 	FieldProvider       AllocationField = AllocationField(fieldstrings.FieldProvider)
+	FieldAccount        AllocationField = AllocationField(fieldstrings.FieldAccount)
 	FieldServices       AllocationField = AllocationField(fieldstrings.FieldServices)
 	FieldLabel          AllocationField = AllocationField(fieldstrings.FieldLabel)
 	FieldAnnotation     AllocationField = AllocationField(fieldstrings.FieldAnnotation)

+ 1 - 0
core/pkg/filter/allocation/parser.go

@@ -13,6 +13,7 @@ var allocationFilterFields []*ast.Field = []*ast.Field{
 	ast.NewField(FieldContainer),
 	ast.NewField(FieldPod),
 	ast.NewField(FieldProvider),
+	ast.NewField(FieldAccount),
 	ast.NewAliasField(AliasDepartment),
 	ast.NewAliasField(AliasEnvironment),
 	ast.NewAliasField(AliasOwner),

+ 4 - 0
core/pkg/filter/allocation/parser_test.go

@@ -26,6 +26,10 @@ func TestParse(t *testing.T) {
 			name:  "Single",
 			input: `namespace: "kubecost"`,
 		},
+		{
+			name:  "Single: account",
+			input: `account: "aws-account-123"`,
+		},
 		{
 			name:  "Single: namespace label",
 			input: `namespaceLabel[app]:"kubecost"`,

+ 10 - 0
core/pkg/opencost/allocationfilter_test.go

@@ -497,6 +497,16 @@ func Test_AllocationFilterCondition_Matches(t *testing.T) {
 			},
 			expected: true,
 		},
+		{
+			name: "Account Equals -> not implemented (returns false)",
+			a: &Allocation{
+				Properties: &AllocationProperties{
+					Cluster: "cluster-one",
+				},
+			},
+			filter:   ops.Eq(afilter.FieldAccount, "account-123"),
+			expected: false,
+		},
 	}
 
 	for _, c := range cases {

+ 2 - 0
core/pkg/opencost/allocationmatcher.go

@@ -72,6 +72,8 @@ func allocationFieldMap(a *Allocation, identifier ast.Identifier) (string, error
 		return a.Properties.Container, nil
 	case afilter.FieldProvider:
 		return a.Properties.ProviderID, nil
+	case afilter.FieldAccount:
+		return "", fmt.Errorf("account property not implemented")
 	case afilter.FieldLabel:
 		return a.Properties.Labels[identifier.Key], nil
 	case afilter.FieldAnnotation: