Skip to content

Commit 6bb3cae

Browse files
Merge pull request openshift#8134 from patrickdillon/azure-sku-perf
OCPBUGS-31546: azure: use filter when listing SKUs
2 parents 63ec490 + 9ff7906 commit 6bb3cae

28 files changed

+23
-18989
lines changed

pkg/asset/installconfig/azure/client.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88
"time"
99

10-
azsku "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/compute/mgmt/compute"
1110
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/network/mgmt/network"
1211
azres "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/resources"
1312
azsubs "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/subscriptions"
@@ -25,9 +24,9 @@ type API interface {
2524
GetControlPlaneSubnet(ctx context.Context, resourceGroupName, virtualNetwork, subnet string) (*aznetwork.Subnet, error)
2625
ListLocations(ctx context.Context) (*[]azsubs.Location, error)
2726
GetResourcesProvider(ctx context.Context, resourceProviderNamespace string) (*azres.Provider, error)
28-
GetVirtualMachineSku(ctx context.Context, name, region string) (*azsku.ResourceSku, error)
27+
GetVirtualMachineSku(ctx context.Context, name, region string) (*azenc.ResourceSku, error)
2928
GetVirtualMachineFamily(ctx context.Context, name, region string) (string, error)
30-
GetDiskSkus(ctx context.Context, region string) ([]azsku.ResourceSku, error)
29+
GetDiskSkus(ctx context.Context, region string) ([]azenc.ResourceSku, error)
3130
GetGroup(ctx context.Context, groupName string) (*azres.Group, error)
3231
ListResourceIDsByGroup(ctx context.Context, groupName string) ([]string, error)
3332
GetStorageEndpointSuffix(ctx context.Context) (string, error)
@@ -170,20 +169,19 @@ func (c *Client) getProvidersClient(ctx context.Context) (azres.ProvidersClient,
170169
}
171170

172171
// GetDiskSkus returns all the disk SKU pages for a given region.
173-
func (c *Client) GetDiskSkus(ctx context.Context, region string) ([]azsku.ResourceSku, error) {
174-
client := azsku.NewResourceSkusClientWithBaseURI(c.ssn.Environment.ResourceManagerEndpoint, c.ssn.Credentials.SubscriptionID)
172+
func (c *Client) GetDiskSkus(ctx context.Context, region string) ([]azenc.ResourceSku, error) {
173+
client := azenc.NewResourceSkusClientWithBaseURI(c.ssn.Environment.ResourceManagerEndpoint, c.ssn.Credentials.SubscriptionID)
175174
client.Authorizer = c.ssn.Authorizer
176-
177175
// See https://issues.redhat.com/browse/OCPBUGS-29469 before changing this timeout
178176
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
179177
defer cancel()
180178

181-
var sku []azsku.ResourceSku
182-
179+
var sku []azenc.ResourceSku
180+
filter := fmt.Sprintf("location eq '%s'", region)
183181
// This has to be initialized outside the `for` because we need access to
184182
// `err`. If initialized in the loop and the API call fails right away,
185183
// `page.NotDone()` will return `false` and we'll never check for the error
186-
skuPage, err := client.List(ctx)
184+
skuPage, err := client.List(ctx, filter, "false")
187185
if err != nil {
188186
return nil, fmt.Errorf("failed to list SKUs: %w", err)
189187
}
@@ -245,18 +243,19 @@ func (c *Client) ListResourceIDsByGroup(ctx context.Context, groupName string) (
245243
}
246244

247245
// GetVirtualMachineSku retrieves the resource SKU of a specified virtual machine SKU in the specified region.
248-
func (c *Client) GetVirtualMachineSku(ctx context.Context, name, region string) (*azsku.ResourceSku, error) {
249-
client := azsku.NewResourceSkusClientWithBaseURI(c.ssn.Environment.ResourceManagerEndpoint, c.ssn.Credentials.SubscriptionID)
246+
func (c *Client) GetVirtualMachineSku(ctx context.Context, name, region string) (*azenc.ResourceSku, error) {
247+
client := azenc.NewResourceSkusClientWithBaseURI(c.ssn.Environment.ResourceManagerEndpoint, c.ssn.Credentials.SubscriptionID)
250248
client.Authorizer = c.ssn.Authorizer
251249

252250
// See https://issues.redhat.com/browse/OCPBUGS-29469 before chaging this timeout
253251
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
254252
defer cancel()
255253

254+
filter := fmt.Sprintf("location eq '%s'", region)
256255
// This has to be initialized outside the `for` because we need access to
257256
// `err`. If initialized in the loop and the API call fails right away,
258257
// `page.NotDone()` will return `false` and we'll never check for the error
259-
page, err := client.List(ctx)
258+
page, err := client.List(ctx, filter, "false")
260259
if err != nil {
261260
return nil, fmt.Errorf("failed to list SKUs: %w", err)
262261
}

pkg/asset/installconfig/azure/mock/azureclient_generated.go

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/asset/installconfig/azure/validation_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"net"
66
"testing"
77

8-
azsku "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/compute/mgmt/compute"
98
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/network/mgmt/network"
109
azres "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/resources"
1110
azsubs "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/subscriptions"
@@ -54,16 +53,16 @@ var (
5453
"Standard_DC8s_v3": {"vCPUsAvailable": "8", "MemoryGB": "32", "PremiumIO": "True", "HyperVGenerations": "V2", "AcceleratedNetworkingEnabled": "True", "CpuArchitectureType": "x64", "ConfidentialComputingType": "SGX"},
5554
}
5655

57-
instanceTypeSku = func() []*azsku.ResourceSku {
58-
instances := make([]*azsku.ResourceSku, 0, len(vmCapabilities))
56+
instanceTypeSku = func() []*azenc.ResourceSku {
57+
instances := make([]*azenc.ResourceSku, 0, len(vmCapabilities))
5958
for typeName, capsMap := range vmCapabilities {
60-
capabilities := make([]azsku.ResourceSkuCapabilities, 0, len(capsMap))
59+
capabilities := make([]azenc.ResourceSkuCapabilities, 0, len(capsMap))
6160
for name, value := range capsMap {
62-
capabilities = append(capabilities, azsku.ResourceSkuCapabilities{
61+
capabilities = append(capabilities, azenc.ResourceSkuCapabilities{
6362
Name: to.StringPtr(name), Value: to.StringPtr(value),
6463
})
6564
}
66-
instances = append(instances, &azsku.ResourceSku{
65+
instances = append(instances, &azenc.ResourceSku{
6766
Name: to.StringPtr(typeName), Capabilities: &capabilities,
6867
})
6968
}

pkg/asset/installconfig/gcp/mock/usertags_mock.go

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)