Explorar el Código

Cherry Pick: Add Azure Disk Sku Nil Check (#3165) (#3173)

Signed-off-by: HMetcalfeW <106991365+HMetcalfeW@users.noreply.github.com>
Hunter Metcalfe hace 11 meses
padre
commit
05be740f9e
Se han modificado 3 ficheros con 16 adiciones y 0 borrados
  1. 1 0
      justfile
  2. 5 0
      pkg/cloud/azure/provider.go
  3. 10 0
      pkg/cloud/azure/provider_test.go

+ 1 - 0
justfile

@@ -14,6 +14,7 @@ test-core:
 # Run unit tests
 test: test-core
     {{commonenv}} go test ./... -coverprofile=coverage.out
+    {{commonenv}} go tool cover -html=coverage.out -o coverage.html
     {{commonenv}} go vet ./...
 
 # Run unit tests and integration tests

+ 5 - 0
pkg/cloud/azure/provider.go

@@ -1450,6 +1450,11 @@ func (az *Azure) findCostForDisk(d *compute.Disk) (float64, error) {
 	if d == nil {
 		return 0.0, fmt.Errorf("disk is empty")
 	}
+
+	if d.Sku == nil {
+		return 0.0, fmt.Errorf("disk sku is nil")
+	}
+
 	storageClass := string(d.Sku.Name)
 	if strings.EqualFold(storageClass, "Premium_LRS") {
 		storageClass = AzureDiskPremiumSSDStorageClass

+ 10 - 0
pkg/cloud/azure/provider_test.go

@@ -223,6 +223,16 @@ func TestAzure_findCostForDisk(t *testing.T) {
 			730.0,
 			nil,
 		},
+		{
+			"nil sku",
+			&compute.Disk{
+				Location:       nil,
+				Sku:            nil,
+				DiskProperties: nil,
+			},
+			0.0,
+			fmt.Errorf("disk sku is nil"),
+		},
 	}
 
 	for _, tc := range testCases {