소스 검색

Allocation properties: Add support for aliased labels (#2396)

* Add aliased label props

Signed-off-by: Bianca Burtoiu <bianca@kubecost.com>

* Add nil check

Signed-off-by: Bianca Burtoiu <bianca@kubecost.com>

---------

Signed-off-by: Bianca Burtoiu <bianca@kubecost.com>
Bianca Burtoiu 2 년 전
부모
커밋
be2a49067c
1개의 변경된 파일31개의 추가작업 그리고 0개의 파일을 삭제
  1. 31 0
      pkg/kubecost/allocationprops.go

+ 31 - 0
pkg/kubecost/allocationprops.go

@@ -41,6 +41,37 @@ func (apt *AllocationProperty) GetAnnotation() string {
 	return ""
 }
 
+// IsAliasedLabel returns true if the allocation property corresponds to an aliased label
+func (apt *AllocationProperty) IsAliasedLabel() bool {
+	if apt == nil {
+		return false
+	}
+
+	return *apt == AllocationDepartmentProp ||
+		*apt == AllocationEnvironmentProp ||
+		*apt == AllocationOwnerProp ||
+		*apt == AllocationProductProp ||
+		*apt == AllocationTeamProp
+}
+
+// GetAliasedLabelDefault returns the corresponding default aliased label name
+func (apt *AllocationProperty) GetAliasedLabelDefault() string {
+	switch *apt {
+	case AllocationDepartmentProp:
+		return "department"
+	case AllocationEnvironmentProp:
+		return "env"
+	case AllocationOwnerProp:
+		return "owner"
+	case AllocationProductProp:
+		return "app"
+	case AllocationTeamProp:
+		return "team"
+	default:
+		return ""
+	}
+}
+
 const (
 	AllocationNilProp            AllocationProperty = ""
 	AllocationClusterProp                           = "cluster"