Merge pull request #3307 from nilo19/cleanup/enrich-cloudprovider-test
Azure: Enrich unit tests for azure_cloud_provider
This commit is contained in:
commit
c452eee46d
|
|
@ -18,10 +18,14 @@ package azure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
apiv1 "k8s.io/api/core/v1"
|
apiv1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
|
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
|
||||||
|
"k8s.io/autoscaler/cluster-autoscaler/config"
|
||||||
|
azclients "k8s.io/legacy-cloud-providers/azure/clients"
|
||||||
"k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient"
|
"k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient"
|
||||||
"k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient"
|
"k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient"
|
||||||
|
|
||||||
|
|
@ -153,3 +157,115 @@ func TestNodeGroupForNodeWithNoProviderId(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, group, nil)
|
assert.Equal(t, group, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildAzure(t *testing.T) {
|
||||||
|
expectedConfig := &Config{
|
||||||
|
Cloud: "AzurePublicCloud",
|
||||||
|
Location: "southeastasia",
|
||||||
|
TenantID: "tenantId",
|
||||||
|
SubscriptionID: "subId",
|
||||||
|
ResourceGroup: "rg",
|
||||||
|
VMType: "vmss",
|
||||||
|
AADClientID: "clientId",
|
||||||
|
AADClientSecret: "clientsecret",
|
||||||
|
MaxDeploymentsCount: 10,
|
||||||
|
CloudProviderRateLimitConfig: CloudProviderRateLimitConfig{
|
||||||
|
RateLimitConfig: azclients.RateLimitConfig{
|
||||||
|
CloudProviderRateLimit: false,
|
||||||
|
CloudProviderRateLimitBucket: 5,
|
||||||
|
CloudProviderRateLimitBucketWrite: 5,
|
||||||
|
CloudProviderRateLimitQPS: 1,
|
||||||
|
CloudProviderRateLimitQPSWrite: 1,
|
||||||
|
},
|
||||||
|
InterfaceRateLimit: &azclients.RateLimitConfig{
|
||||||
|
CloudProviderRateLimit: false,
|
||||||
|
CloudProviderRateLimitBucket: 5,
|
||||||
|
CloudProviderRateLimitBucketWrite: 5,
|
||||||
|
CloudProviderRateLimitQPS: 1,
|
||||||
|
CloudProviderRateLimitQPSWrite: 1,
|
||||||
|
},
|
||||||
|
VirtualMachineRateLimit: &azclients.RateLimitConfig{
|
||||||
|
CloudProviderRateLimit: false,
|
||||||
|
CloudProviderRateLimitBucket: 5,
|
||||||
|
CloudProviderRateLimitBucketWrite: 5,
|
||||||
|
CloudProviderRateLimitQPS: 1,
|
||||||
|
CloudProviderRateLimitQPSWrite: 1,
|
||||||
|
},
|
||||||
|
StorageAccountRateLimit: &azclients.RateLimitConfig{
|
||||||
|
CloudProviderRateLimit: false,
|
||||||
|
CloudProviderRateLimitBucket: 5,
|
||||||
|
CloudProviderRateLimitBucketWrite: 5,
|
||||||
|
CloudProviderRateLimitQPS: 1,
|
||||||
|
CloudProviderRateLimitQPSWrite: 1,
|
||||||
|
},
|
||||||
|
DiskRateLimit: &azclients.RateLimitConfig{
|
||||||
|
CloudProviderRateLimit: false,
|
||||||
|
CloudProviderRateLimitBucket: 5,
|
||||||
|
CloudProviderRateLimitBucketWrite: 5,
|
||||||
|
CloudProviderRateLimitQPS: 1,
|
||||||
|
CloudProviderRateLimitQPSWrite: 1,
|
||||||
|
},
|
||||||
|
VirtualMachineScaleSetRateLimit: &azclients.RateLimitConfig{
|
||||||
|
CloudProviderRateLimit: false,
|
||||||
|
CloudProviderRateLimitBucket: 5,
|
||||||
|
CloudProviderRateLimitBucketWrite: 5,
|
||||||
|
CloudProviderRateLimitQPS: 1,
|
||||||
|
CloudProviderRateLimitQPSWrite: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cloudConfig := "cfg.json"
|
||||||
|
azureCfg := `{
|
||||||
|
"cloud": "AzurePublicCloud",
|
||||||
|
"tenantId": "tenantId",
|
||||||
|
"subscriptionId": "subId",
|
||||||
|
"aadClientId": "clientId",
|
||||||
|
"aadClientSecret": "clientsecret",
|
||||||
|
"resourceGroup": "rg",
|
||||||
|
"location": "southeastasia"
|
||||||
|
}`
|
||||||
|
err := ioutil.WriteFile(cloudConfig, []byte(azureCfg), 0644)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
defer os.Remove(cloudConfig)
|
||||||
|
|
||||||
|
os.Setenv("ARM_CLOUD", "AzurePublicCloud")
|
||||||
|
os.Setenv("LOCATION", "southeastasia")
|
||||||
|
os.Setenv("ARM_RESOURCE_GROUP", "rg")
|
||||||
|
os.Setenv("ARM_SUBSCRIPTION_ID", "subId")
|
||||||
|
os.Setenv("ARM_TENANT_ID", "tenantId")
|
||||||
|
os.Setenv("ARM_CLIENT_ID", "clientId")
|
||||||
|
os.Setenv("ARM_CLIENT_SECRET", "clientsecret")
|
||||||
|
|
||||||
|
resourceLimiter := &cloudprovider.ResourceLimiter{}
|
||||||
|
discoveryOptions := cloudprovider.NodeGroupDiscoveryOptions{}
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
cloudConfig string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "BuildAzure should create Azure Manager using cloud-config file",
|
||||||
|
cloudConfig: cloudConfig,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BuildAzure should create Azure Manager using environment variable",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
opts := config.AutoscalingOptions{
|
||||||
|
CloudConfig: test.cloudConfig,
|
||||||
|
}
|
||||||
|
cloudProvider := BuildAzure(opts, discoveryOptions, resourceLimiter)
|
||||||
|
assert.Equal(t, expectedConfig, cloudProvider.(*AzureCloudProvider).azureManager.config, test.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Unsetenv("ARM_CLOUD")
|
||||||
|
os.Unsetenv("LOCATION")
|
||||||
|
os.Unsetenv("ARM_RESOURCE_GROUP")
|
||||||
|
os.Unsetenv("ARM_SUBSCRIPTION_ID")
|
||||||
|
os.Unsetenv("ARM_TENANT_ID")
|
||||||
|
os.Unsetenv("ARM_CLIENT_ID")
|
||||||
|
os.Unsetenv("ARM_CLIENT_SECRET")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue