Skip to content

Commit 571b771

Browse files
committed
add AzureEnvironment to AzureManagedControlPlaneSpec
1 parent 4c0d8c7 commit 571b771

6 files changed

+40
-11
lines changed

api/v1beta1/azuremanagedcontrolplane_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ type AzureManagedControlPlaneSpec struct {
138138
// AutoscalerProfile is the parameters to be applied to the cluster-autoscaler when enabled
139139
// +optional
140140
AutoScalerProfile *AutoScalerProfile `json:"autoscalerProfile,omitempty"`
141+
142+
// AzureEnvironment is the name of the AzureCloud to be used.
143+
// The default value that would be used by most users is "AzurePublicCloud", other values are:
144+
// - ChinaCloud: "AzureChinaCloud"
145+
// - PublicCloud: "AzurePublicCloud"
146+
// - USGovernmentCloud: "AzureUSGovernmentCloud"
147+
// +optional
148+
AzureEnvironment string `json:"azureEnvironment,omitempty"`
141149
}
142150

143151
// AADProfile - AAD integration managed by AKS.

api/v1beta1/azuremanagedcontrolplane_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o
193193
allErrs = append(allErrs, err)
194194
}
195195

196+
if err := webhookutils.ValidateImmutable(
197+
field.NewPath("Spec", "AzureEnvironment"),
198+
old.Spec.AzureEnvironment,
199+
m.Spec.AzureEnvironment); err != nil {
200+
allErrs = append(allErrs, err)
201+
}
202+
196203
if old.Spec.AADProfile != nil {
197204
if m.Spec.AADProfile == nil {
198205
allErrs = append(allErrs,

api/v1beta1/types_class.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ limitations under the License.
1616

1717
package v1beta1
1818

19-
import corev1 "k8s.io/api/core/v1"
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
)
2022

2123
// AzureClusterClassSpec defines the AzureCluster properties that may be shared across several Azure clusters.
2224
type AzureClusterClassSpec struct {

azure/scope/managedcontrolplane.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane
7373
}
7474

7575
if params.ControlPlane.Spec.IdentityRef == nil {
76-
if err := params.AzureClients.setCredentials(params.ControlPlane.Spec.SubscriptionID, ""); err != nil {
76+
if err := params.AzureClients.setCredentials(params.ControlPlane.Spec.SubscriptionID, params.ControlPlane.Spec.AzureEnvironment); err != nil {
7777
return nil, errors.Wrap(err, "failed to create Azure session")
7878
}
7979
} else {
@@ -82,7 +82,7 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane
8282
return nil, errors.Wrap(err, "failed to init credentials provider")
8383
}
8484

85-
if err := params.AzureClients.setCredentialsWithProvider(ctx, params.ControlPlane.Spec.SubscriptionID, "", credentialsProvider); err != nil {
85+
if err := params.AzureClients.setCredentialsWithProvider(ctx, params.ControlPlane.Spec.SubscriptionID, params.ControlPlane.Spec.AzureEnvironment, credentialsProvider); err != nil {
8686
return nil, errors.Wrap(err, "failed to configure azure settings and credentials for Identity")
8787
}
8888
}

config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ spec:
217217
- "false"
218218
type: string
219219
type: object
220+
azureEnvironment:
221+
description: 'AzureEnvironment is the name of the AzureCloud to be
222+
used. The default value that would be used by most users is "AzurePublicCloud",
223+
other values are: - ChinaCloud: "AzureChinaCloud" - PublicCloud:
224+
"AzurePublicCloud" - USGovernmentCloud: "AzureUSGovernmentCloud"'
225+
type: string
220226
controlPlaneEndpoint:
221227
description: ControlPlaneEndpoint represents the endpoint used to
222228
communicate with the control plane.

controllers/azuremanagedmachinepool_reconciler.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,28 @@ func (a *AgentPoolVMSSNotFoundError) Is(target error) bool {
7474

7575
// newAzureManagedMachinePoolService populates all the services based on input scope.
7676
func newAzureManagedMachinePoolService(scope *scope.ManagedMachinePoolScope) (*azureManagedMachinePoolService, error) {
77-
var authorizer azure.Authorizer = scope
78-
if scope.Location() != "" {
79-
regionalAuthorizer, err := azure.WithRegionalBaseURI(scope, scope.Location())
80-
if err != nil {
81-
return nil, errors.Wrap(err, "failed to create a regional authorizer")
82-
}
83-
authorizer = regionalAuthorizer
77+
scaleSetAuthorizer, err := scaleSetAuthorizer(scope)
78+
if err != nil {
79+
return nil, err
8480
}
8581

8682
return &azureManagedMachinePoolService{
8783
scope: scope,
8884
agentPoolsSvc: agentpools.New(scope),
89-
scaleSetsSvc: scalesets.NewClient(authorizer),
85+
scaleSetsSvc: scalesets.NewClient(scaleSetAuthorizer),
9086
}, nil
9187
}
9288

89+
// scaleSetAuthorizer takes a scope and determines if a regional authorizer is needed for scale sets
90+
// see https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/1850 for context on region based authorizer.
91+
func scaleSetAuthorizer(scope *scope.ManagedMachinePoolScope) (azure.Authorizer, error) {
92+
if scope.ControlPlane.Spec.AzureEnvironment == azure.PublicCloudName {
93+
return azure.WithRegionalBaseURI(scope, scope.Location()) // public cloud supports regional end points
94+
}
95+
96+
return scope, nil
97+
}
98+
9399
// Reconcile reconciles all the services in a predetermined order.
94100
func (s *azureManagedMachinePoolService) Reconcile(ctx context.Context) error {
95101
ctx, log, done := tele.StartSpanWithLogger(ctx, "controllers.azureManagedMachinePoolService.Reconcile")

0 commit comments

Comments
 (0)