Set vmType in azure cloud config

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2022-03-29 13:28:23 +02:00 committed by Daniel Weiße
parent eb3411f2c1
commit 71b5a0c6c0
2 changed files with 27 additions and 1 deletions

View File

@ -57,12 +57,18 @@ func (c *CloudControllerManager) Secrets(instance core.Instance, cloudServiceAcc
return resources.Secrets{}, err return resources.Secrets{}, err
} }
vmType := "standard"
if _, _, _, _, err := splitScaleSetProviderID(instance.ProviderID); err == nil {
vmType = "vmss"
}
config := cloudConfig{ config := cloudConfig{
Cloud: "AzurePublicCloud", Cloud: "AzurePublicCloud",
TenantID: creds.TenantID, TenantID: creds.TenantID,
SubscriptionID: subscriptionID, SubscriptionID: subscriptionID,
ResourceGroup: resourceGroup, ResourceGroup: resourceGroup,
UseInstanceMetadata: true, UseInstanceMetadata: true,
VmType: vmType,
AADClientID: creds.ClientID, AADClientID: creds.ClientID,
AADClientSecret: creds.ClientSecret, AADClientSecret: creds.ClientSecret,
} }
@ -145,6 +151,7 @@ type cloudConfig struct {
VNetResourceGroup string `json:"vnetResourceGroup,omitempty"` VNetResourceGroup string `json:"vnetResourceGroup,omitempty"`
CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"` CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"`
UseInstanceMetadata bool `json:"useInstanceMetadata,omitempty"` UseInstanceMetadata bool `json:"useInstanceMetadata,omitempty"`
VmType string `json:"vmType,omitempty"`
AADClientID string `json:"aadClientId,omitempty"` AADClientID string `json:"aadClientId,omitempty"`
AADClientSecret string `json:"aadClientSecret,omitempty"` AADClientSecret string `json:"aadClientSecret,omitempty"`
} }

View File

@ -32,7 +32,26 @@ func TestSecrets(t *testing.T) {
Namespace: "kube-system", Namespace: "kube-system",
}, },
Data: map[string][]byte{ 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"}`),
}, },
}, },
}, },