Skip to content

Commit 54f788d

Browse files
committed
Use azure cloud as ARM endpoint fallback
1 parent 206cfa5 commit 54f788d

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

docs/usages/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ aks-flex-node start --config /etc/aks-flex-node/config.json
2525
|------|------|-------------|--------------|
2626
| `azure.subscriptionId` | string | Optional Azure subscription that owns the target AKS cluster. Defaults from `azure.targetCluster.resourceId` when omitted. | `44654aed-2753-4b88-9142-af7132933b6b` |
2727
| `azure.tenantId` | string | Microsoft Entra tenant ID. Required only when Azure Arc is enabled. | `70a036f6-8e4d-4615-bad6-149c02e7720d` |
28-
| `azure.cloud` | string | Optional legacy Azure cloud environment label. Resource Manager calls use `azure.resourceManagerEndpoint`. | `AzurePublicCloud` in legacy configs |
29-
| `azure.resourceManagerEndpoint` | string | Optional Azure Resource Manager endpoint emitted by RP bootstrap data. Defaults to `https://management.azure.com`. | `https://management.azure.com` |
28+
| `azure.cloud` | string | Optional Azure cloud environment label used as a fallback when `azure.resourceManagerEndpoint` is omitted. | `AzurePublicCloud` |
29+
| `azure.resourceManagerEndpoint` | string | Optional Azure Resource Manager endpoint emitted by RP bootstrap data. When omitted, it is derived from `azure.cloud` and defaults to public Azure. | `https://management.azure.com` |
3030
| `azure.targetCluster` | object | Target AKS cluster metadata. | `{}` |
3131
| `azure.targetAgentPoolName` | string | Optional target AKS agent pool for FlexNode machine registration (`TargetAgentPoolName` in the agent config). Defaults to `aksflexnodes`. | `flexnode-edge` |
3232

pkg/config/config.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Config struct {
5757
type AzureConfig struct {
5858
SubscriptionID string `json:"subscriptionId"` // Azure subscription ID; defaults from targetCluster.resourceId when omitted
5959
TenantID string `json:"tenantId"` // Azure tenant ID
60-
Cloud string `json:"cloud,omitempty"` // Legacy Azure cloud label; Resource Manager uses resourceManagerEndpoint
60+
Cloud string `json:"cloud,omitempty"` // Optional Azure cloud label used when resourceManagerEndpoint is omitted
6161
ResourceManagerEndpointURL string `json:"resourceManagerEndpoint,omitempty"` // Azure Resource Manager endpoint; defaults to https://management.azure.com
6262
ServicePrincipal *ServicePrincipalConfig `json:"servicePrincipal,omitempty"` // Optional service principal authentication
6363
ManagedIdentity *ManagedIdentityConfig `json:"managedIdentity,omitempty"` // Optional managed identity authentication
@@ -312,7 +312,7 @@ func (c *Config) setDefaults() {
312312

313313
func (c *Config) setAzureDefaults() {
314314
if endpoint := strings.TrimSpace(c.Azure.ResourceManagerEndpointURL); endpoint == "" {
315-
c.Azure.ResourceManagerEndpointURL = DefaultResourceManagerEndpointURL
315+
c.Azure.ResourceManagerEndpointURL = resourceManagerEndpointFromCloud(c.Azure.Cloud)
316316
} else {
317317
c.Azure.ResourceManagerEndpointURL = strings.TrimRight(endpoint, "/")
318318
}
@@ -322,6 +322,19 @@ func (c *Config) setAzureDefaults() {
322322
}
323323
}
324324

325+
func resourceManagerEndpointFromCloud(cloud string) string {
326+
switch strings.TrimSpace(cloud) {
327+
case "AzureUSGovernment", "AzureGovernmentCloud":
328+
return "https://management.usgovcloudapi.net"
329+
case "AzureChinaCloud":
330+
return "https://management.chinacloudapi.cn"
331+
case "", "AzurePublicCloud":
332+
return DefaultResourceManagerEndpointURL
333+
default:
334+
return DefaultResourceManagerEndpointURL
335+
}
336+
}
337+
325338
func (c *Config) setAgentDefaults() {
326339
// Set default agent configuration if not provided
327340
if c.Agent.LogLevel == "" {

pkg/config/config_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func TestSetDefaults(t *testing.T) {
4343
name: "existing values are preserved",
4444
config: &Config{
4545
Azure: AzureConfig{
46-
Cloud: "AzurePublicCloud",
47-
TargetAgentPoolName: " flexnode-edge ",
46+
Cloud: "AzurePublicCloud",
47+
ResourceManagerEndpointURL: "https://management.example.test/",
48+
TargetAgentPoolName: " flexnode-edge ",
4849
},
4950
Agent: AgentConfig{
5051
LogLevel: "debug",
@@ -55,9 +56,32 @@ func TestSetDefaults(t *testing.T) {
5556
return c.Agent.LogLevel == "debug" &&
5657
c.Agent.LogDir == "/custom/log/dir" &&
5758
c.Azure.Cloud == "AzurePublicCloud" &&
59+
c.Azure.ResourceManagerEndpointURL == "https://management.example.test" &&
5860
c.Azure.TargetAgentPoolName == "flexnode-edge"
5961
},
6062
},
63+
{
64+
name: "cloud fallback sets sovereign endpoint",
65+
config: &Config{
66+
Azure: AzureConfig{
67+
Cloud: "AzureUSGovernment",
68+
},
69+
},
70+
want: func(c *Config) bool {
71+
return c.Azure.ResourceManagerEndpointURL == "https://management.usgovcloudapi.net"
72+
},
73+
},
74+
{
75+
name: "cloud fallback supports Azure China",
76+
config: &Config{
77+
Azure: AzureConfig{
78+
Cloud: "AzureChinaCloud",
79+
},
80+
},
81+
want: func(c *Config) bool {
82+
return c.Azure.ResourceManagerEndpointURL == "https://management.chinacloudapi.cn"
83+
},
84+
},
6185
{
6286
name: "node kubelet defaults are set correctly",
6387
config: &Config{

0 commit comments

Comments
 (0)