From 71b5a0c6c07863fd070586aeef52d76f2237cd34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= Date: Tue, 29 Mar 2022 13:28:23 +0200 Subject: [PATCH] Set vmType in azure cloud config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- coordinator/cloudprovider/azure/ccm.go | 7 +++++++ coordinator/cloudprovider/azure/ccm_test.go | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/coordinator/cloudprovider/azure/ccm.go b/coordinator/cloudprovider/azure/ccm.go index 31da083d9..4ca53acc1 100644 --- a/coordinator/cloudprovider/azure/ccm.go +++ b/coordinator/cloudprovider/azure/ccm.go @@ -57,12 +57,18 @@ func (c *CloudControllerManager) Secrets(instance core.Instance, cloudServiceAcc return resources.Secrets{}, err } + vmType := "standard" + if _, _, _, _, err := splitScaleSetProviderID(instance.ProviderID); err == nil { + vmType = "vmss" + } + config := cloudConfig{ Cloud: "AzurePublicCloud", TenantID: creds.TenantID, SubscriptionID: subscriptionID, ResourceGroup: resourceGroup, UseInstanceMetadata: true, + VmType: vmType, AADClientID: creds.ClientID, AADClientSecret: creds.ClientSecret, } @@ -145,6 +151,7 @@ type cloudConfig struct { VNetResourceGroup string `json:"vnetResourceGroup,omitempty"` CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"` UseInstanceMetadata bool `json:"useInstanceMetadata,omitempty"` + VmType string `json:"vmType,omitempty"` AADClientID string `json:"aadClientId,omitempty"` AADClientSecret string `json:"aadClientSecret,omitempty"` } diff --git a/coordinator/cloudprovider/azure/ccm_test.go b/coordinator/cloudprovider/azure/ccm_test.go index b0da5f9d5..9275b0a49 100644 --- a/coordinator/cloudprovider/azure/ccm_test.go +++ b/coordinator/cloudprovider/azure/ccm_test.go @@ -32,7 +32,26 @@ func TestSecrets(t *testing.T) { Namespace: "kube-system", }, Data: map[string][]byte{ - "azure.json": []byte(`{"cloud":"AzurePublicCloud","tenantId":"tenant-id","subscriptionId":"subscription-id","resourceGroup":"resource-group","useInstanceMetadata":true,"aadClientId":"client-id","aadClientSecret":"client-secret"}`), + "azure.json": []byte(`{"cloud":"AzurePublicCloud","tenantId":"tenant-id","subscriptionId":"subscription-id","resourceGroup":"resource-group","useInstanceMetadata":true,"vmType":"standard","aadClientId":"client-id","aadClientSecret":"client-secret"}`), + }, + }, + }, + }, + "Secrets works for scale sets": { + instance: core.Instance{ProviderID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scale-set-name/virtualMachines/instance-id"}, + cloudServiceAccountURI: "serviceaccount://azure?tenant_id=tenant-id&client_id=client-id&client_secret=client-secret", + expectedSecrets: resources.Secrets{ + &k8s.Secret{ + TypeMeta: meta.TypeMeta{ + Kind: "Secret", + APIVersion: "v1", + }, + ObjectMeta: meta.ObjectMeta{ + Name: "azureconfig", + Namespace: "kube-system", + }, + Data: map[string][]byte{ + "azure.json": []byte(`{"cloud":"AzurePublicCloud","tenantId":"tenant-id","subscriptionId":"subscription-id","resourceGroup":"resource-group","useInstanceMetadata":true,"vmType":"vmss","aadClientId":"client-id","aadClientSecret":"client-secret"}`), }, }, },