Skip to content

Commit 70bea61

Browse files
committed
Set ARMClientOptions for Azure Stack
Sets ARM Client Options when using the Azure Stack environment. Sets the APIVersion to a hybrid cloud profile to ensure compatibility with hybrid environments.
1 parent 2212107 commit 70bea61

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

azure/defaults.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
2828
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
2929
"github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel"
30+
azureautorest "github.com/Azure/go-autorest/autorest/azure"
3031
"go.opentelemetry.io/otel"
3132

3233
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
@@ -111,6 +112,12 @@ const (
111112
CustomHeaderPrefix = "infrastructure.cluster.x-k8s.io/custom-header-"
112113
)
113114

115+
const (
116+
// StackAPIVersionProfile is the API version profile to set for ARM clients. See:
117+
// https://learn.microsoft.com/en-us/azure-stack/user/azure-stack-profiles-azure-resource-manager-versions?view=azs-2408#overview-of-the-2020-09-01-hybrid-profile
118+
StackAPIVersionProfile = "2020-06-01"
119+
)
120+
114121
var (
115122
// LinuxBootstrapExtensionCommand is the command the VM bootstrap extension will execute to verify Linux nodes bootstrap completes successfully.
116123
LinuxBootstrapExtensionCommand = fmt.Sprintf("for i in $(seq 1 %d); do test -f %s && break; if [ $i -eq %d ]; then echo 'Error joining node to cluster: kubeadm init or join failed. To debug, check the cloud-init, kubelet, or other bootstrap logs: https://capz.sigs.k8s.io/self-managed/troubleshooting.html#checking-cloud-init-logs-ubuntu'; exit 1; else sleep %d; fi; done", bootstrapExtensionRetries, bootstrapSentinelFile, bootstrapExtensionRetries, bootstrapExtensionSleep)
@@ -369,6 +376,21 @@ func ARMClientOptions(azureEnvironment string, extraPolicies ...policy.Policy) (
369376
opts.Cloud = cloud.AzureChina
370377
case USGovernmentCloudName:
371378
opts.Cloud = cloud.AzureGovernment
379+
case StackCloudName:
380+
cloudEnv, err := azureautorest.EnvironmentFromName(azureEnvironment)
381+
if err != nil {
382+
return nil, fmt.Errorf("unable to get Azure Stack cloud environment: %w", err)
383+
}
384+
opts.APIVersion = StackAPIVersionProfile
385+
opts.Cloud = cloud.Configuration{
386+
ActiveDirectoryAuthorityHost: cloudEnv.ActiveDirectoryEndpoint,
387+
Services: map[cloud.ServiceName]cloud.ServiceConfiguration{
388+
cloud.ResourceManager: {
389+
Audience: cloudEnv.TokenAudience,
390+
Endpoint: cloudEnv.ResourceManagerEndpoint,
391+
},
392+
},
393+
}
372394
case "":
373395
// No cloud name provided, so leave at defaults.
374396
default:

0 commit comments

Comments
 (0)