2
0
Эх сурвалжийг харах

Merge pull request #1216 from kubecost/sean/gcp-reconciliation

Add provider id for PV for GCP
Sean Holcomb 4 жил өмнө
parent
commit
3c4e3eff43

+ 7 - 1
pkg/cloud/gcpprovider.go

@@ -1189,6 +1189,7 @@ func (gcp *GCP) getReservedInstances() ([]*GCPReservedInstance, error) {
 }
 
 type pvKey struct {
+	ProviderID             string
 	Labels                 map[string]string
 	StorageClass           string
 	StorageClassParameters map[string]string
@@ -1196,7 +1197,7 @@ type pvKey struct {
 }
 
 func (key *pvKey) ID() string {
-	return ""
+	return key.ProviderID
 }
 
 func (key *pvKey) GetStorageClass() string {
@@ -1204,7 +1205,12 @@ func (key *pvKey) GetStorageClass() string {
 }
 
 func (gcp *GCP) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) PVKey {
+	providerID := ""
+	if pv.Spec.GCEPersistentDisk != nil {
+		providerID = pv.Spec.GCEPersistentDisk.PDName
+	}
 	return &pvKey{
+		ProviderID:             providerID,
 		Labels:                 pv.Labels,
 		StorageClass:           pv.Spec.StorageClassName,
 		StorageClassParameters: parameters,

+ 3 - 5
pkg/costmodel/cluster.go

@@ -296,11 +296,9 @@ func ClusterDisks(client prometheus.Client, provider cloud.Provider, start, end
 		// Apply all remaining RAM to Idle
 		disk.Breakdown.Idle = 1.0 - (disk.Breakdown.System + disk.Breakdown.Other + disk.Breakdown.User)
 
-		// Set provider Id to the name for reconciliation on Azure
-		if fmt.Sprintf("%T", provider) == "*provider.Azure" {
-			if disk.ProviderID == "" {
-				disk.ProviderID = disk.Name
-			}
+		// Set provider Id to the name for reconciliation
+		if disk.ProviderID == "" {
+			disk.ProviderID = disk.Name
 		}
 	}