Преглед изворни кода

Added support for GCP N4 compute instances #3109 (#3289)

Signed-off-by: Sparsh <sparsh.raj30@gmail.com>
Sparsh Raj пре 8 месеци
родитељ
комит
6d4d490e3e
2 измењених фајлова са 19 додато и 1 уклоњено
  1. 7 1
      pkg/cloud/gcp/provider.go
  2. 12 0
      pkg/cloud/gcp/provider_test.go

+ 7 - 1
pkg/cloud/gcp/provider.go

@@ -735,6 +735,10 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]models.Key, pvKeys m
 					}
 				}
 
+				if (instanceType == "ram" || instanceType == "cpu") && strings.Contains(strings.ToUpper(product.Description), "N4 INSTANCE") {
+					instanceType = "n4standard"
+				}
+
 				if (instanceType == "ram" || instanceType == "cpu") && strings.Contains(strings.ToUpper(product.Description), "A2 INSTANCE") {
 					instanceType = "a2"
 				}
@@ -1501,6 +1505,8 @@ func parseGCPInstanceTypeLabel(it string) string {
 			instanceType = "n1standard" // These are priced the same. TODO: support n1ultrahighmem
 		} else if instanceType == "n2highmem" || instanceType == "n2highcpu" {
 			instanceType = "n2standard"
+		} else if instanceType == "n4highmem" || instanceType == "n4highcpu" {
+			instanceType = "n4standard" // N4 variants are priced the same per vCPU and RAM
 		} else if instanceType == "e2highmem" || instanceType == "e2highcpu" {
 			instanceType = "e2standard"
 		} else if instanceType == "n2dhighmem" || instanceType == "n2dhighcpu" {
@@ -1642,7 +1648,7 @@ func sustainedUseDiscount(class string, defaultDiscount float64, isPreemptible b
 	}
 	discount := defaultDiscount
 	switch class {
-	case "e2", "f1", "g1":
+	case "e2", "f1", "g1", "n4":
 		discount = 0.0
 	case "n2", "n2d":
 		discount = 0.2

+ 12 - 0
pkg/cloud/gcp/provider_test.go

@@ -36,6 +36,18 @@ func TestParseGCPInstanceTypeLabel(t *testing.T) {
 			input:    "n2d-highmem-8",
 			expected: "n2dstandard",
 		},
+		{
+			input:    "n4-standard-4",
+			expected: "n4standard",
+		},
+		{
+			input:    "n4-highcpu-8",
+			expected: "n4standard",
+		},
+		{
+			input:    "n4-highmem-16",
+			expected: "n4standard",
+		},
 	}
 
 	for _, test := range cases {