Skip to content

Commit

Permalink
add AzureEnvironment to AzureManagedControlPlaneSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed May 2, 2023
1 parent 7425764 commit a63c3a9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ 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"
// - GermanCloud: "AzureGermanCloud"
// - PublicCloud: "AzurePublicCloud"
// - USGovernmentCloud: "AzureUSGovernmentCloud"
// +optional
AzureEnvironment string `json:"azureEnvironment,omitempty"`
}

// AADProfile - AAD integration managed by AKS.
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 @@ -683,6 +683,13 @@ 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" - GermanCloud:
"AzureGermanCloud" - PublicCloud: "AzurePublicCloud" - USGovernmentCloud:
"AzureUSGovernmentCloud"'
type: string
controlPlaneEndpoint:
description: ControlPlaneEndpoint represents the endpoint used to
communicate with the control plane.
Expand Down
28 changes: 20 additions & 8 deletions controllers/azuremanagedmachinepool_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"time"

azureautorest "github.com/Azure/go-autorest/autorest/azure"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
"github.com/pkg/errors"
azprovider "sigs.k8s.io/cloud-provider-azure/pkg/provider"
Expand Down Expand Up @@ -74,22 +76,32 @@ 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.Location() == "" {
return scope, nil // no location so use default
}

if scope.ControlPlane.Spec.AzureEnvironment == azureautorest.USGovernmentCloud.Name {
return scope, nil // no region support in usgovcloud
}

return azure.WithRegionalBaseURI(scope, scope.Location())
}

// 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 a63c3a9

Please sign in to comment.