Skip to content

Commit 2944dcb

Browse files
authored
squash (#8596)
1 parent d789bff commit 2944dcb

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

cluster-autoscaler/cloudprovider/azure/azure_cache.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,17 @@ type azureCache struct {
107107
}
108108

109109
func newAzureCache(client *azClient, cacheTTL time.Duration, config Config) (*azureCache, error) {
110+
nodeResourceGroup := config.ResourceGroup
111+
// Hosted (on-behalf-of) system pool node resources are in the AKS internal resource group within AME tenants,
112+
// which differs from the MC_* resource group found in the customer subscription.
113+
if config.HostedResourceGroup != "" {
114+
nodeResourceGroup = config.HostedResourceGroup
115+
}
110116
cache := &azureCache{
111117
interrupt: make(chan struct{}),
112118
azClient: client,
113119
refreshInterval: cacheTTL,
114-
resourceGroup: config.ResourceGroup,
120+
resourceGroup: nodeResourceGroup,
115121
clusterResourceGroup: config.ClusterResourceGroup,
116122
clusterName: config.ClusterName,
117123
enableVMsAgentPool: config.EnableVMsAgentPool,

cluster-autoscaler/cloudprovider/azure/azure_config.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ type Config struct {
6565
// It can override the default public ARM endpoint for VMs pool scale operations.
6666
ARMBaseURLForAPClient string `json:"armBaseURLForAPClient" yaml:"armBaseURLForAPClient"`
6767

68+
// Hosted (on-behalf-of) system pool configuration for automatic cluster.
69+
// HostedSubscriptionID is the subscription ID of the hosted resources under AKS internal tenant.
70+
HostedSubscriptionID string `json:"hostedSubscriptionID" yaml:"hostedSubscriptionID"`
71+
// HostedResourceGroup is the resource group of the hosted resources under AKS internal tenant.
72+
HostedResourceGroup string `json:"hostedResourceGroup" yaml:"hostedResourceGroup"`
73+
// HostedResourceProxyURL is the URL to use for retrieving hosted resources under AKS internal tenant.
74+
// It can override the default public ARM endpoint for operations like VM/SKU GET.
75+
HostedResourceProxyURL string `json:"hostedResourceProxyURL" yaml:"hostedResourceProxyURL"`
76+
6877
// AuthMethod determines how to authorize requests for the Azure
6978
// cloud. Valid options are "principal" (= the traditional
7079
// service principle approach) and "cli" (= load az command line
@@ -223,6 +232,15 @@ func BuildAzureConfig(configReader io.Reader) (*Config, error) {
223232
if _, err = assignFromEnvIfExists(&cfg.SubscriptionID, "ARM_SUBSCRIPTION_ID"); err != nil {
224233
return nil, err
225234
}
235+
if _, err = assignFromEnvIfExists(&cfg.HostedResourceProxyURL, "HOSTED_RESOURCE_PROXY_URL"); err != nil {
236+
return nil, err
237+
}
238+
if _, err = assignFromEnvIfExists(&cfg.HostedSubscriptionID, "HOSTED_SUBSCRIPTION_ID"); err != nil {
239+
return nil, err
240+
}
241+
if _, err = assignFromEnvIfExists(&cfg.HostedResourceGroup, "HOSTED_RESOURCE_GROUP"); err != nil {
242+
return nil, err
243+
}
226244
if _, err = assignBoolFromEnvIfExists(&cfg.UseManagedIdentityExtension, "ARM_USE_MANAGED_IDENTITY_EXTENSION"); err != nil {
227245
return nil, err
228246
}
@@ -380,6 +398,17 @@ func (cfg *Config) getAzureClientConfig(authorizer autorest.Authorizer, env *azu
380398
}
381399
}
382400

401+
// A proxy service is required to access resources for the Hosted (on-behalf-of) system pool within automatic clusters.
402+
if cfg.HostedResourceProxyURL != "" {
403+
azClientConfig.ResourceManagerEndpoint = cfg.HostedResourceProxyURL
404+
}
405+
406+
// Hosted (on-behalf-of) system pool resources are hosted under AKS internal tenant and subscription.
407+
// it is different from the customer subscription where the cluster is created.
408+
if cfg.HostedSubscriptionID != "" {
409+
azClientConfig.SubscriptionID = cfg.HostedSubscriptionID
410+
}
411+
383412
if cfg.HasExtendedLocation() {
384413
azClientConfig.ExtendedLocation = &azclients.ExtendedLocation{
385414
Name: cfg.ExtendedLocationName,

cluster-autoscaler/cloudprovider/azure/azure_vms_pool.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,16 @@ func (vmPool *VMPool) IncreaseSize(delta int) error {
154154
if len(versionedAP.Properties.VirtualMachinesProfile.Scale.Manual) > 0 {
155155
requestBody = buildRequestBodyForScaleUp(versionedAP, count, vmPool.sku)
156156

157-
} else { // AKS-managed CAS will use custom header for setting the target count
157+
}
158+
// hosted CAS will be using Autoscale scale profile
159+
// HostedSystem will be using manual scale profile
160+
// Both of them need to set the Target-Count and SKU headers
161+
if len(versionedAP.Properties.VirtualMachinesProfile.Scale.Autoscale) > 0 ||
162+
(versionedAP.Properties.Mode != nil &&
163+
strings.EqualFold(string(*versionedAP.Properties.Mode), "HostedSystem")) {
158164
header := make(http.Header)
159165
header.Set("Target-Count", fmt.Sprintf("%d", count))
166+
header.Set("SKU", fmt.Sprintf("%s", vmPool.sku))
160167
updateCtx = policy.WithHTTPHeader(updateCtx, header)
161168
}
162169

0 commit comments

Comments
 (0)