Skip to content

Commit

Permalink
Merge pull request #3509 from luthermonson/azenv-aks
Browse files Browse the repository at this point in the history
Add AzureEnvironment to AzureManagedControlPlane
  • Loading branch information
k8s-ci-robot authored May 22, 2023
2 parents eb77ec4 + 571b771 commit bee83d3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
8 changes: 8 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ type AzureManagedControlPlaneSpec struct {
// AutoscalerProfile is the parameters to be applied to the cluster-autoscaler when enabled
// +optional
AutoScalerProfile *AutoScalerProfile `json:"autoscalerProfile,omitempty"`

// AzureEnvironment is the name of the AzureCloud to be used.
// The default value that would be used by most users is "AzurePublicCloud", other values are:
// - ChinaCloud: "AzureChinaCloud"
// - PublicCloud: "AzurePublicCloud"
// - USGovernmentCloud: "AzureUSGovernmentCloud"
// +optional
AzureEnvironment string `json:"azureEnvironment,omitempty"`
}

// AADProfile - AAD integration managed by AKS.
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o
allErrs = append(allErrs, err)
}

if err := webhookutils.ValidateImmutable(
field.NewPath("Spec", "AzureEnvironment"),
old.Spec.AzureEnvironment,
m.Spec.AzureEnvironment); err != nil {
allErrs = append(allErrs, err)
}

if old.Spec.AADProfile != nil {
if m.Spec.AADProfile == nil {
allErrs = append(allErrs,
Expand Down
4 changes: 3 additions & 1 deletion api/v1beta1/types_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ limitations under the License.

package v1beta1

import corev1 "k8s.io/api/core/v1"
import (
corev1 "k8s.io/api/core/v1"
)

// AzureClusterClassSpec defines the AzureCluster properties that may be shared across several Azure clusters.
type AzureClusterClassSpec struct {
Expand Down
4 changes: 2 additions & 2 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane
}

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

if err := params.AzureClients.setCredentialsWithProvider(ctx, params.ControlPlane.Spec.SubscriptionID, "", credentialsProvider); err != nil {
if err := params.AzureClients.setCredentialsWithProvider(ctx, params.ControlPlane.Spec.SubscriptionID, params.ControlPlane.Spec.AzureEnvironment, credentialsProvider); err != nil {
return nil, errors.Wrap(err, "failed to configure azure settings and credentials for Identity")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ spec:
- "false"
type: string
type: object
azureEnvironment:
description: 'AzureEnvironment is the name of the AzureCloud to be
used. The default value that would be used by most users is "AzurePublicCloud",
other values are: - ChinaCloud: "AzureChinaCloud" - PublicCloud:
"AzurePublicCloud" - USGovernmentCloud: "AzureUSGovernmentCloud"'
type: string
controlPlaneEndpoint:
description: ControlPlaneEndpoint represents the endpoint used to
communicate with the control plane.
Expand Down
22 changes: 14 additions & 8 deletions controllers/azuremanagedmachinepool_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,28 @@ func (a *AgentPoolVMSSNotFoundError) Is(target error) bool {

// newAzureManagedMachinePoolService populates all the services based on input scope.
func newAzureManagedMachinePoolService(scope *scope.ManagedMachinePoolScope) (*azureManagedMachinePoolService, error) {
var authorizer azure.Authorizer = scope
if scope.Location() != "" {
regionalAuthorizer, err := azure.WithRegionalBaseURI(scope, scope.Location())
if err != nil {
return nil, errors.Wrap(err, "failed to create a regional authorizer")
}
authorizer = regionalAuthorizer
scaleSetAuthorizer, err := scaleSetAuthorizer(scope)
if err != nil {
return nil, err
}

return &azureManagedMachinePoolService{
scope: scope,
agentPoolsSvc: agentpools.New(scope),
scaleSetsSvc: scalesets.NewClient(authorizer),
scaleSetsSvc: scalesets.NewClient(scaleSetAuthorizer),
}, nil
}

// scaleSetAuthorizer takes a scope and determines if a regional authorizer is needed for scale sets
// see https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/1850 for context on region based authorizer.
func scaleSetAuthorizer(scope *scope.ManagedMachinePoolScope) (azure.Authorizer, error) {
if scope.ControlPlane.Spec.AzureEnvironment == azure.PublicCloudName {
return azure.WithRegionalBaseURI(scope, scope.Location()) // public cloud supports regional end points
}

return scope, nil
}

// Reconcile reconciles all the services in a predetermined order.
func (s *azureManagedMachinePoolService) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(ctx, "controllers.azureManagedMachinePoolService.Reconcile")
Expand Down

0 comments on commit bee83d3

Please sign in to comment.