Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #92505: azure: use the parsed value from the configuration #94566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion staging/src/k8s.io/legacy-cloud-providers/azure/azure.go
Expand Up @@ -384,7 +384,7 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro
// No credentials provided, useInstanceMetadata should be enabled for Kubelet.
// TODO(feiskyer): print different error message for Kubelet and controller-manager, as they're
// requiring different credential settings.
if !config.UseInstanceMetadata && az.Config.CloudConfigType == cloudConfigTypeFile {
if !config.UseInstanceMetadata && config.CloudConfigType == cloudConfigTypeFile {
return fmt.Errorf("useInstanceMetadata must be enabled without Azure credentials")
}

Expand Down
28 changes: 28 additions & 0 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_test.go
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
servicehelpers "k8s.io/cloud-provider/service/helpers"
"k8s.io/legacy-cloud-providers/azure/auth"
"k8s.io/legacy-cloud-providers/azure/clients/subnetclient/mocksubnetclient"
"k8s.io/legacy-cloud-providers/azure/retry"
)
Expand Down Expand Up @@ -2831,3 +2832,30 @@ func TestGetNodeResourceGroup(t *testing.T) {
assert.Equal(t, test.expected, actual, test.name)
}
}

func TestInitializeCloudFromConfig(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
az := GetTestCloud(ctrl)

err := az.InitializeCloudFromConfig(nil, false)
assert.NoError(t, err)

config := Config{
DisableAvailabilitySetNodes: true,
VMType: vmTypeStandard,
}
err = az.InitializeCloudFromConfig(&config, false)
expectedErr := fmt.Errorf("disableAvailabilitySetNodes true is only supported when vmType is 'vmss'")
assert.Equal(t, expectedErr, err)

config = Config{
AzureAuthConfig: auth.AzureAuthConfig{
Cloud: "AZUREPUBLICCLOUD",
},
CloudConfigType: cloudConfigTypeFile,
}
err = az.InitializeCloudFromConfig(&config, false)
expectedErr = fmt.Errorf("useInstanceMetadata must be enabled without Azure credentials")
assert.Equal(t, expectedErr, err)
}