Quellcode durchsuchen

Continued work on KubeModel structure

Niko Kovacevic vor 6 Monaten
Ursprung
Commit
45f82f50f5

+ 4 - 5
core/pkg/model/kubemodel/cluster.go

@@ -1,13 +1,12 @@
 package kubemodel
 
+import "time"
+
 type Cluster struct {
 	UID      string
 	Provider Provider
 	Account  string
 	Name     string
-
-	// NOTE: Alternate hierarchical structure
-	Namespaces        map[string]*Namespace
-	Nodes             map[string]*Node
-	PersistentVolumes map[string]*PersistentVolume
+	Start    time.Time
+	End      time.Time
 }

+ 30 - 5
core/pkg/model/kubemodel/container.go

@@ -1,10 +1,35 @@
 package kubemodel
 
+import "time"
+
 // TODO complete
+// TODO (start, end) here, or defer to Pod?
+// TODO how to handle network bytes?
+// TODO how to handle GPUs?
+// TODO how to handle storage?
+// TODO how to handle devices?
+// TODO uint64 or float64 for numbers?
 type Container struct {
-	UID          string
-	PodUID       string
-	Name         string
-	Resources    ResourceQuantities
-	VolumeMounts map[string]ResourceQuantity
+	UID                           string
+	PodUID                        string
+	Name                          string
+	Start                         time.Time
+	End                           time.Time
+	CPUAllocationMillicoreSeconds uint64
+	CPURequestMillicoreAverage    uint64
+	CPULimitMillicoreAverage      uint64
+	CPUUsageMillicoreAverage      uint64
+	CPUUsageMillicoreMax          uint64
+	RAMAllocationByteSeconds      uint64
+	RAMRequestByteAverage         uint64
+	RAMLimitByteAverage           uint64
+	RAMUsageByteAverage           uint64
+	RAMUsageByteMax               uint64
+	PVCMounts                     map[string]*MountedVolume
+}
+
+type MountedVolume struct {
+	PersistentVolumeClaimUID string
+	Name                     string
+	StorageCapacityBytes     uint64
 }

+ 4 - 4
core/pkg/model/kubemodel/example.go

@@ -43,11 +43,11 @@ func flatAlgorithm(kms *KubeModelSet, pm PricingModel, out chan map[string]*Cont
 		nodePricing := pm.GetNodePricing(node)
 
 		// O(1)
-		cc.CPUCost = container.Resources[ResourceCPU].Values[stats.Val] * nodePricing[ResourceCPU].Price
-		cc.RAMCost = container.Resources[ResourceMemory].Values[stats.Val] * nodePricing[ResourceMemory].Price
+		cc.CPUCost = float64(container.CPUAllocationMillicoreSeconds) * nodePricing[ResourceCPU].Price
+		cc.RAMCost = float64(container.RAMAllocationByteSeconds) * nodePricing[ResourceMemory].Price
 
 		// O(PVC)
-		for pvcUID, storage := range container.VolumeMounts {
+		for pvcUID, mountedVolume := range container.PVCMounts {
 			// O(1)
 			pvc := kms.PersistentVolumeClaims[pvcUID]
 
@@ -58,7 +58,7 @@ func flatAlgorithm(kms *KubeModelSet, pm PricingModel, out chan map[string]*Cont
 			pvPricing := pm.GetPersistentVolumePricing(pv)
 
 			// O(1)
-			cc.StorageCost += storage.Values[stats.Val] * pvPricing[ResourceStorage].Price
+			cc.StorageCost += float64(mountedVolume.StorageCapacityBytes) * pvPricing[ResourceStorage].Price
 		}
 
 		// O(1)

+ 9 - 9
core/pkg/model/kubemodel/kubemodel.go

@@ -17,12 +17,12 @@ type KubeModelSet struct {
 	PersistentVolumeClaims map[string]*PersistentVolumeClaim
 	Pods                   map[string]*Pod
 	ResourceQuotas         map[string]*ResourceQuota
-	indexes                *kubeModelSetIndexes
+	Indices                *Indices
 }
 
 func NewKubeModelSet(start, end time.Time) *KubeModelSet {
-	indexes := &kubeModelSetIndexes{
-		namespaceToNamespaceUID: map[string]string{},
+	indices := &Indices{
+		NamespaceNameToUID: map[string]string{},
 	}
 
 	return &KubeModelSet{
@@ -35,7 +35,7 @@ func NewKubeModelSet(start, end time.Time) *KubeModelSet {
 		},
 		Namespaces:     map[string]*Namespace{},
 		ResourceQuotas: map[string]*ResourceQuota{},
-		indexes:        indexes,
+		Indices:        indices,
 	}
 }
 
@@ -51,7 +51,7 @@ func (kms *KubeModelSet) RegisterNamespace(uid, name string) error {
 			Name:       name,
 		}
 
-		kms.indexes.namespaceToNamespaceUID[name] = uid
+		kms.Indices.NamespaceNameToUID[name] = uid
 	}
 
 	return nil
@@ -59,14 +59,14 @@ func (kms *KubeModelSet) RegisterNamespace(uid, name string) error {
 
 func (kms *KubeModelSet) RegisterResourceQuota(uid, name, namespace string) error {
 	if _, ok := kms.ResourceQuotas[uid]; !ok {
-		if _, ok := kms.indexes.namespaceToNamespaceUID[namespace]; !ok {
+		if _, ok := kms.Indices.NamespaceNameToUID[namespace]; !ok {
 			return fmt.Errorf("KubeModelSet missing NamespaceUID for namespace=%s", namespace)
 		}
 
 		kms.ResourceQuotas[uid] = &ResourceQuota{
 			UID:          uid,
 			Name:         name,
-			NamespaceUID: kms.indexes.namespaceToNamespaceUID[namespace],
+			NamespaceUID: kms.Indices.NamespaceNameToUID[namespace],
 			Spec:         &ResourceQuotaSpec{Hard: &ResourceQuotaSpecHard{}},
 			Status:       &ResourceQuotaStatus{Used: &ResourceQuotaStatusUsed{}},
 		}
@@ -93,6 +93,6 @@ type KubeModelSetMetadata struct {
 	Warnings    []string
 }
 
-type kubeModelSetIndexes struct {
-	namespaceToNamespaceUID map[string]string
+type Indices struct {
+	NamespaceNameToUID map[string]string
 }

+ 4 - 0
core/pkg/model/kubemodel/namespace.go

@@ -1,9 +1,13 @@
 package kubemodel
 
+import "time"
+
 type Namespace struct {
 	UID         string
 	ClusterUID  string
 	Name        string
 	Labels      map[string]string
 	Annotations map[string]string
+	Start       time.Time
+	End         time.Time
 }

+ 10 - 7
core/pkg/model/kubemodel/node.go

@@ -1,12 +1,15 @@
 package kubemodel
 
+import "time"
+
 // TODO complete
+// TODO uint64 or float64 for numbers?
 type Node struct {
-	UID        string
-	ClusterUID string
-	Name       string
-	Resources  ResourceQuantities
-
-	// NOTE: Alternate hierarchical structure
-	Pods map[string]*Pod
+	UID                 string
+	ClusterUID          string
+	Name                string
+	Start               time.Time
+	End                 time.Time
+	CPUMillicoreSeconds uint64
+	RAMByteSeconds      uint64
 }

+ 9 - 4
core/pkg/model/kubemodel/persistentvolume.go

@@ -1,9 +1,14 @@
 package kubemodel
 
+import "time"
+
 // TODO complete
+// TODO uint64 or float64 for numbers?
 type PersistentVolume struct {
-	UID        string
-	ClusterUID string
-	Name       string
-	Capacity   ResourceQuantities
+	UID                        string
+	ClusterUID                 string
+	Name                       string
+	Start                      time.Time
+	End                        time.Time
+	StorageCapacityByteSeconds uint64
 }

+ 8 - 4
core/pkg/model/kubemodel/persistentvolumeclaim.go

@@ -1,9 +1,13 @@
 package kubemodel
 
+import "time"
+
 // TODO complete
 type PersistentVolumeClaim struct {
-	UID                 string
-	PersistentVolumeUID string
-	Name                string
-	Resources           ResourceQuantities
+	UID                        string
+	PersistentVolumeUID        string
+	Name                       string
+	Start                      time.Time
+	End                        time.Time
+	StorageCapacityByteSeconds uint64
 }

+ 10 - 5
core/pkg/model/kubemodel/pod.go

@@ -1,15 +1,20 @@
 package kubemodel
 
+import "time"
+
 // TODO complete
+// TODO how to handle PVCs?
+// TODO how to handle attached devices?
+// TODO how to handle labels and annos?
 type Pod struct {
 	UID                       string
 	NamespaceUID              string
 	NodeUID                   string
 	OwnerUID                  string
-	PersistentVolumeClaimUIDs []string
+	PersistentVolumeClaimUIDs map[string]struct{}
 	Name                      string
-
-	// NOTE: Alternate hierarchical structure
-	Containers             map[string]*Container
-	PersistentVolumeClaims map[string]*PersistentVolumeClaim
+	Labels                    map[string]string
+	Annotations               map[string]string
+	Start                     time.Time
+	End                       time.Time
 }

+ 13 - 13
core/pkg/model/kubemodel/resource.go

@@ -14,19 +14,19 @@ const (
 type Unit string
 
 const (
-	UnitCPUCore   = "vCPU"
-	UnitCPUm      = "m"
-	UnitByte      = "B"
-	UnitMi        = "Mi"
-	UnitGB        = "GB"
-	UnitGPU       = "GPU"
-	UnitTimeHr    = "hr"
-	UnitCPUCoreHr = "vCPU-hr"
-	UnitCPUmHr    = "m-hr"
-	UnitBHr       = "B-hr"
-	UnitMiHr      = "Mi-hr"
-	UnitGBHr      = "GB-hr"
-	UnitGPUHr     = "GPU-hr"
+	UnitMillicore     = "mCPU"
+	UnitByte          = "B"
+	UnitMi            = "Mi"
+	UnitGB            = "GB"
+	UnitGPU           = "GPU"
+	UnitSecond        = "s"
+	UnitMinute        = "m"
+	UnitHour          = "h"
+	UnitMillicoreHour = "m-h"
+	UnitByteHour      = "B-h"
+	UnitMiHour        = "Mi-h"
+	UnitGBHour        = "GB-h"
+	UnitGPUHour       = "GPU-h"
 )
 
 type ResourceQuantity struct {