-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathvalidate.go
More file actions
81 lines (67 loc) · 2.92 KB
/
validate.go
File metadata and controls
81 lines (67 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cluster
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"fmt"
"net/http"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/azcore"
"github.com/Azure/ARO-RP/pkg/util/azurezones"
"github.com/Azure/ARO-RP/pkg/util/computeskus"
"github.com/Azure/ARO-RP/pkg/validate"
)
func (m *manager) validateResources(ctx context.Context) error {
var clusterMSICredential azcore.TokenCredential
if m.doc.OpenShiftCluster.UsesWorkloadIdentity() {
clusterMSICredential = m.userAssignedIdentities.GetClusterMSICredential()
}
return validate.NewOpenShiftClusterDynamicValidator(
m.log, m.env, m.doc.OpenShiftCluster, m.subscriptionDoc, m.fpAuthorizer, m.armRoleDefinitions, m.clusterMsiFederatedIdentityCredentials, m.platformWorkloadIdentities, m.platformWorkloadIdentityRolesByVersion, clusterMSICredential,
).Dynamic(ctx)
}
// validateZones validates the SKU availability and zones of the cluster being
// created. This function is only to be called during cluster bootstrap!
func (m *manager) validateZones(ctx context.Context) error {
location := m.doc.OpenShiftCluster.Location
filteredSkus, err := computeskus.SelectVMSkusInCurrentRegion(ctx, m.armResourceSKUs, location, []string{
string(m.doc.OpenShiftCluster.Properties.MasterProfile.VMSize),
string(m.doc.OpenShiftCluster.Properties.WorkerProfiles[0].VMSize),
})
if err != nil {
return err
}
controlPlaneSKU, err := checkSKUAvailability(filteredSkus, location, "properties.masterProfile.VMSize", string(m.doc.OpenShiftCluster.Properties.MasterProfile.VMSize))
if err != nil {
return err
}
workerSKU, err := checkSKUAvailability(filteredSkus, location, "properties.workerProfiles[0].VMSize", string(m.doc.OpenShiftCluster.Properties.WorkerProfiles[0].VMSize))
if err != nil {
return err
}
// Set RP-level options for expanded AZs
zoneChecker := azurezones.NewManager(
m.env.FeatureIsSet(env.FeatureEnableClusterExpandedAvailabilityZones))
_, _, originalZones, err := zoneChecker.DetermineAvailabilityZones(controlPlaneSKU, workerSKU)
if err != nil {
return err
}
// Update the document with configured zones
updatedDoc, err := m.db.PatchWithLease(ctx, m.doc.Key, func(oscd *api.OpenShiftClusterDocument) error {
oscd.OpenShiftCluster.Properties.Zones = originalZones
return nil
})
m.doc = updatedDoc
return err
}
// see pkg/frontend/sku_validation.go
func checkSKUAvailability(skus map[string]*armcompute.ResourceSKU, location, path, vmsize string) (*armcompute.ResourceSKU, error) {
// Ensure desired sku exists in target region
sku, ok := skus[vmsize]
if !ok {
return nil, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path, fmt.Sprintf("The selected SKU '%v' is unavailable in region '%v'", vmsize, location))
}
return sku, nil
}