Jelajahi Sumber

Merge pull request #384 from kubecost/niko/aggcontroller

Add CostData.GetController for aggregate by controller
Niko Kovacevic 6 tahun lalu
induk
melakukan
909e777c7e
1 mengubah file dengan 24 tambahan dan 0 penghapusan
  1. 24 0
      pkg/costmodel/costmodel.go

+ 24 - 0
pkg/costmodel/costmodel.go

@@ -97,6 +97,30 @@ func (cd *CostData) String() string {
 		len(cd.RAMReq), len(cd.RAMUsed), len(cd.RAMAllocation))
 }
 
+func (cd *CostData) GetController() (name string, kind string, hasController bool) {
+	hasController = false
+
+	if len(cd.Deployments) > 0 {
+		name = cd.Deployments[0]
+		kind = "deployment"
+		hasController = true
+	} else if len(cd.Statefulsets) > 0 {
+		name = cd.Statefulsets[0]
+		kind = "statefulset"
+		hasController = true
+	} else if len(cd.Daemonsets) > 0 {
+		name = cd.Daemonsets[0]
+		kind = "daemonset"
+		hasController = true
+	} else if len(cd.Jobs) > 0 {
+		name = cd.Jobs[0]
+		kind = "job"
+		hasController = true
+	}
+
+	return name, kind, hasController
+}
+
 // Error collection helper
 type ErrorCollector struct {
 	m      sync.Mutex