Skip to content

Commit 657fded

Browse files
authored
Merge pull request kubernetes#90796 from Danil-Grigorev/get-credential-lowercase
Ensure the server FQIN is stored and searched in lowercase (vsphere)
2 parents 07e916b + 9770574 commit 657fded

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

staging/src/k8s.io/legacy-cloud-providers/vsphere/credentialmanager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func (secretCredentialManager *SecretCredentialManager) GetCredential(server str
7777
klog.Warningf("secret %q not found in namespace %q", secretCredentialManager.SecretName, secretCredentialManager.SecretNamespace)
7878
}
7979

80+
// Converting server FQIN to lowercase to consolidate with config parsing approach
81+
server = strings.ToLower(server)
8082
credential, found := secretCredentialManager.Cache.GetCredential(server)
8183
if !found {
8284
klog.Errorf("credentials not found for server %q", server)

staging/src/k8s.io/legacy-cloud-providers/vsphere/credentialmanager_test.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package vsphere
2020

2121
import (
2222
"reflect"
23+
"strings"
2324
"testing"
2425

2526
corev1 "k8s.io/api/core/v1"
@@ -37,6 +38,7 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
3738
testPassword = "password"
3839
testServer = "0.0.0.0"
3940
testServer2 = "0.0.1.1"
41+
testServerFQIN = "ExAmple.com"
4042
testUserServer2 = "user1"
4143
testPasswordServer2 = "password1"
4244
testIncorrectServer = "1.1.1.1"
@@ -89,6 +91,14 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
8991
},
9092
}
9193

94+
fqinSecret := &corev1.Secret{
95+
ObjectMeta: metaObj,
96+
Data: map[string][]byte{
97+
testServerFQIN + "." + userKey: []byte(testUser),
98+
testServerFQIN + "." + passwordKey: []byte(testPassword),
99+
},
100+
}
101+
92102
emptySecret := &corev1.Secret{
93103
ObjectMeta: metaObj,
94104
Data: map[string][]byte{},
@@ -183,6 +193,20 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
183193
},
184194
},
185195
},
196+
{
197+
testName: "GetCredential for FQIN server name",
198+
ops: []string{addSecretOp, getCredentialsOp},
199+
expectedValues: []interface{}{
200+
OpSecretTest{
201+
fqinSecret,
202+
},
203+
GetCredentialsTest{
204+
username: testUser,
205+
password: testPassword,
206+
server: testServerFQIN,
207+
},
208+
},
209+
},
186210
}
187211

188212
// TODO: replace 0 with NoResyncPeriodFunc() once it moved out pkg/controller/controller_utils.go in k/k.
@@ -254,9 +278,10 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
254278

255279
func TestParseSecretConfig(t *testing.T) {
256280
var (
257-
testUsername = "Admin"
258-
testPassword = "Password"
259-
testIP = "10.20.30.40"
281+
testUsername = "Admin"
282+
testPassword = "Password"
283+
testIP = "10.20.30.40"
284+
testServerFQIN = "ExAmple.com"
260285
)
261286
var testcases = []struct {
262287
testName string
@@ -311,6 +336,20 @@ func TestParseSecretConfig(t *testing.T) {
311336
},
312337
expectedError: ErrCredentialMissing,
313338
},
339+
{
340+
testName: "FQIN stored as lowercase",
341+
data: map[string][]byte{
342+
testServerFQIN + ".username": []byte(testUsername),
343+
testServerFQIN + ".password": []byte(testPassword),
344+
},
345+
config: map[string]*Credential{
346+
strings.ToLower(testServerFQIN): {
347+
User: testUsername,
348+
Password: testPassword,
349+
},
350+
},
351+
expectedError: nil,
352+
},
314353
{
315354
testName: "IP with unknown key",
316355
data: map[string][]byte{

0 commit comments

Comments
 (0)