diff --git a/pkg/cloud/azure/actuators/machine/reconciler.go b/pkg/cloud/azure/actuators/machine/reconciler.go index 658ac0dcb..cf260b275 100644 --- a/pkg/cloud/azure/actuators/machine/reconciler.go +++ b/pkg/cloud/azure/actuators/machine/reconciler.go @@ -562,7 +562,11 @@ func (s *Reconciler) createNetworkInterface(ctx context.Context, nicName string) skuI, err := s.resourcesSkus.Get(ctx, skuSpec) if err != nil { - return fmt.Errorf("failed to find sku %s", s.scope.MachineConfig.VMSize) + if errors.Is(err, resourceskus.ErrResourceNotFound) { + return machinecontroller.InvalidMachineConfiguration("failed to obtain instance type information for VMSize '%s' from Azure: %s", skuSpec.Name, err) + } else { + return fmt.Errorf("failed to obtain instance type information for VMSize '%s' from Azure: %w", skuSpec.Name, err) + } } sku := skuI.(resourceskus.SKU) diff --git a/pkg/cloud/azure/actuators/machineset/controller.go b/pkg/cloud/azure/actuators/machineset/controller.go index daff7e36e..fa4cde3e9 100644 --- a/pkg/cloud/azure/actuators/machineset/controller.go +++ b/pkg/cloud/azure/actuators/machineset/controller.go @@ -169,9 +169,10 @@ func getStockKeepUnit(r *Reconciler, machineSet *machinev1.MachineSet) (resource skuI, err := resourceSkusService.Get(context.Background(), skuSpec) if err != nil { if errors.Is(err, resourceskus.ErrResourceNotFound) { - return resourceskus.SKU{}, mapierrors.InvalidMachineConfiguration("machine SKU information for machine type %s does not exist: %v", providerConfig.VMSize, err) + return resourceskus.SKU{}, mapierrors.InvalidMachineConfiguration("failed to obtain instance type information for VMSize '%s' from Azure: %s", skuSpec.Name, err) + } else { + return resourceskus.SKU{}, fmt.Errorf("failed to obtain instance type information for VMSize '%s' from Azure: %w", skuSpec.Name, err) } - return resourceskus.SKU{}, fmt.Errorf("failed to get SKU information for %s: %w", providerConfig.VMSize, err) } sku := skuI.(resourceskus.SKU) diff --git a/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go b/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go index c91243c61..a42913e68 100644 --- a/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go +++ b/pkg/cloud/azure/services/networkinterfaces/networkinterfaces.go @@ -23,6 +23,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-02-01/network" "github.com/Azure/go-autorest/autorest/to" + machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine" "github.com/openshift/machine-api-provider-azure/pkg/cloud/azure" "github.com/openshift/machine-api-provider-azure/pkg/cloud/azure/services/applicationsecuritygroups" "github.com/openshift/machine-api-provider-azure/pkg/cloud/azure/services/internalloadbalancers" @@ -92,7 +93,11 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { } skuI, err := skuService.Get(ctx, skuSpec) if err != nil { - return fmt.Errorf("failed to find sku %s", s.Scope.MachineConfig.VMSize) + if errors.Is(err, resourceskus.ErrResourceNotFound) { + return machinecontroller.InvalidMachineConfiguration("failed to obtain instance type information for VMSize '%s' from Azure: %s", skuSpec.Name, err) + } else { + return fmt.Errorf("failed to obtain instance type information for VMSize '%s' from Azure: %w", skuSpec.Name, err) + } } sku := skuI.(resourceskus.SKU) diff --git a/pkg/cloud/azure/services/resourceskus/cache.go b/pkg/cloud/azure/services/resourceskus/cache.go index 402bf0a44..38b7aa0a2 100644 --- a/pkg/cloud/azure/services/resourceskus/cache.go +++ b/pkg/cloud/azure/services/resourceskus/cache.go @@ -26,6 +26,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-03-01/compute" "github.com/pkg/errors" + "k8s.io/utils/pointer" "github.com/openshift/machine-api-provider-azure/pkg/cloud/azure/actuators" "github.com/openshift/machine-api-provider-azure/pkg/util/cache/ttllru" @@ -133,7 +134,15 @@ func (c *Cache) Get(ctx context.Context, name string, kind ResourceType) (SKU, e return SKU(sku), nil } } - return SKU{}, fmt.Errorf("resource SKU with name '%s' and category '%s' not found in location '%s': %w", name, string(kind), c.location, ErrResourceNotFound) + + availableInRegion := []string{} + for _, sku := range c.data { + if pointer.StringDeref(sku.ResourceType, "") == string(kind) { + availableInRegion = append(availableInRegion, pointer.StringDeref(sku.Name, "")) + } + } + + return SKU{}, fmt.Errorf("resource SKU with name '%s' and category '%s' not found in location '%s': %w: The valid %s in the current region are: %q. Find out more on the valid resources in each region at https://aka.ms/azure-regionservices", name, string(kind), c.location, ErrResourceNotFound, string(kind), availableInRegion) } // Map invokes a function over all cached values. diff --git a/pkg/cloud/azure/services/resourceskus/cache_test.go b/pkg/cloud/azure/services/resourceskus/cache_test.go index afe19a2cb..cbb17e9c1 100644 --- a/pkg/cloud/azure/services/resourceskus/cache_test.go +++ b/pkg/cloud/azure/services/resourceskus/cache_test.go @@ -55,10 +55,15 @@ func TestCacheGet(t *testing.T) { resourceType: "bar", have: []compute.ResourceSku{ { - Name: to.StringPtr("other"), + Name: to.StringPtr("other"), + ResourceType: to.StringPtr("bar"), + }, + { + Name: to.StringPtr("other2"), + ResourceType: to.StringPtr("bar"), }, }, - err: "resource SKU with name 'foo' and category 'bar' not found in location 'test': resource not found", + err: "resource SKU with name 'foo' and category 'bar' not found in location 'test': resource not found: The valid bar in the current region are: [\"other\" \"other2\"]. Find out more on the valid resources in each region at https://aka.ms/azure-regionservices", }, }