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

Add GCP check

Signed-off-by: Bianca Burtoiu <bianca@kubecost.com>
Bianca Burtoiu 3 лет назад
Родитель
Сommit
38ff796efe
4 измененных файлов с 21 добавлено и 9 удалено
  1. 3 5
      pkg/cloud/awsprovider.go
  2. 7 2
      pkg/cloud/gcpprovider.go
  3. 8 2
      pkg/cloud/gcpprovider_test.go
  4. 3 0
      pkg/cloud/provider.go

+ 3 - 5
pkg/cloud/awsprovider.go

@@ -55,11 +55,9 @@ const (
 	InUseState    = "in-use"
 	AttachedState = "attached"
 
-	AWSHourlyPublicIPCost          = 0.005
-	EKSCapacityTypeLabel           = "eks.amazonaws.com/capacityType"
-	EKSCapacitySpotTypeValue       = "SPOT"
-	KarpenterCapacityTypeLabel     = "karpenter.sh/capacity-type"
-	KarpenterCapacitySpotTypeValue = "spot"
+	AWSHourlyPublicIPCost    = 0.005
+	EKSCapacityTypeLabel     = "eks.amazonaws.com/capacityType"
+	EKSCapacitySpotTypeValue = "SPOT"
 )
 
 var (

+ 7 - 2
pkg/cloud/gcpprovider.go

@@ -42,6 +42,9 @@ const (
 	GCPMonthlyBasicDiskCost = 0.04
 	GCPMonthlySSDDiskCost   = 0.17
 	GCPMonthlyGP2DiskCost   = 0.1
+
+	GKEPreemptibleLabel = "cloud.google.com/gke-preemptible"
+	GKESpotLabel        = "cloud.google.com/gke-spot"
 )
 
 // List obtained by installing the `gcloud` CLI tool,
@@ -1563,11 +1566,13 @@ func parseGCPProjectID(id string) string {
 }
 
 func getUsageType(labels map[string]string) string {
-	if t, ok := labels["cloud.google.com/gke-preemptible"]; ok && t == "true" {
+	if t, ok := labels[GKEPreemptibleLabel]; ok && t == "true" {
 		return "preemptible"
-	} else if t, ok := labels["cloud.google.com/gke-spot"]; ok && t == "true" {
+	} else if t, ok := labels[GKESpotLabel]; ok && t == "true" {
 		// https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms
 		return "preemptible"
+	} else if t, ok := labels[KarpenterCapacityTypeLabel]; ok && t == KarpenterCapacitySpotTypeValue {
+		return "preemptible"
 	}
 	return "ondemand"
 }

+ 8 - 2
pkg/cloud/gcpprovider_test.go

@@ -73,13 +73,19 @@ func TestGetUsageType(t *testing.T) {
 	}{
 		{
 			input: map[string]string{
-				"cloud.google.com/gke-preemptible": "true",
+				GKEPreemptibleLabel: "true",
 			},
 			expected: "preemptible",
 		},
 		{
 			input: map[string]string{
-				"cloud.google.com/gke-spot": "true",
+				GKESpotLabel: "true",
+			},
+			expected: "preemptible",
+		},
+		{
+			input: map[string]string{
+				KarpenterCapacityTypeLabel: KarpenterCapacitySpotTypeValue,
 			},
 			expected: "preemptible",
 		},

+ 3 - 0
pkg/cloud/provider.go

@@ -32,6 +32,9 @@ const authSecretPath = "/var/secrets/service-key.json"
 const storageConfigSecretPath = "/var/azure-storage-config/azure-storage-config.json"
 const defaultShareTenancyCost = "true"
 
+const KarpenterCapacityTypeLabel = "karpenter.sh/capacity-type"
+const KarpenterCapacitySpotTypeValue = "spot"
+
 var createTableStatements = []string{
 	`CREATE TABLE IF NOT EXISTS names (
 		cluster_id VARCHAR(255) NOT NULL,