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

[release-1.26] fix: ensure Kubernets conformant format for location #1990

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ func GetCloudProviderFromClient(ctx context.Context, kubeClient *clientset.Clien
return nil, fmt.Errorf("no cloud config provided, error: %v", err)
}
} else {
// Location may be either upper case with spaces (e.g. "East US") or lower case without spaces (e.g. "eastus")
// Kubernetes does not allow whitespaces in label values, e.g. for topology keys
// ensure Kubernetes compatible format for Location by enforcing lowercase-no-space format
config.Location = strings.ToLower(strings.ReplaceAll(config.Location, " ", ""))

// disable disk related rate limit
config.DiskRateLimit = &azclients.RateLimitConfig{
CloudProviderRateLimit: false,
Expand Down
17 changes: 17 additions & 0 deletions pkg/azureutils/azure_disk_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"os"
"reflect"
"regexp"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -267,6 +268,7 @@ users:
}

func TestGetCloudProvider(t *testing.T) {
locationRxp := regexp.MustCompile("(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?")
fakeCredFile, err := testutil.GetWorkDirPath("fake-cred-file.json")
if err != nil {
t.Errorf("GetWorkDirPath failed with %v", err)
Expand Down Expand Up @@ -318,6 +320,7 @@ users:
desc string
createFakeCredFile bool
createFakeKubeConfig bool
credFile string
kubeconfig string
userAgent string
allowEmptyCloudConfig bool
Expand Down Expand Up @@ -353,6 +356,15 @@ users:
allowEmptyCloudConfig: true,
expectedErr: nil,
},
{
desc: "[success] out of cluster & in cluster, no kubeconfig, a fake credential file with upper case Location format",
createFakeCredFile: true,
kubeconfig: "",
credFile: "location: \"East US\"\n",
userAgent: "useragent",
allowEmptyCloudConfig: false,
expectedErr: nil,
},
}

for _, test := range tests {
Expand All @@ -364,6 +376,10 @@ users:
os.Remove(fakeCredFile)
}()

if err := os.WriteFile(fakeCredFile, []byte(test.credFile), 0666); err != nil {
t.Error(err)
}

t.Setenv(consts.DefaultAzureCredentialFileEnv, fakeCredFile)
}
if test.createFakeKubeConfig {
Expand All @@ -383,6 +399,7 @@ users:
t.Errorf("desc: %s,\n input: %q, GetCloudProvider err: %v, expectedErr: %v", test.desc, test.kubeconfig, err, test.expectedErr)
}
if cloud != nil {
assert.Regexp(t, locationRxp, cloud.Location)
assert.Equal(t, cloud.UserAgent, test.userAgent)
assert.Equal(t, cloud.DiskRateLimit != nil && cloud.DiskRateLimit.CloudProviderRateLimit, false)
assert.Equal(t, cloud.SnapshotRateLimit != nil && cloud.SnapshotRateLimit.CloudProviderRateLimit, false)
Expand Down
Loading