Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/cloud/azure/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions pkg/cloud/azure/actuators/machineset/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion pkg/cloud/azure/services/resourceskus/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions pkg/cloud/azure/services/resourceskus/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down