Просмотр исходного кода

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 лет назад
Родитель
Сommit
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"