Merge pull request #103750 from mattcary/allowedtopo

Pass unknown labels in allowedTopologies during CSI translation
This commit is contained in:
Kubernetes Prow Robot 2021-08-04 22:12:29 -07:00 committed by GitHub
commit bb817a911b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -306,7 +306,7 @@ func translateTopologyFromCSIToInTree(pv *v1.PersistentVolume, csiTopologyKey st
return nil
}
// translateAllowedTopologies translates allowed topologies within storage class
// translateAllowedTopologies translates allowed topologies within storage class or PV
// from legacy failure domain to given CSI topology key
func translateAllowedTopologies(terms []v1.TopologySelectorTerm, key string) ([]v1.TopologySelectorTerm, error) {
if terms == nil {
@ -323,10 +323,9 @@ func translateAllowedTopologies(terms []v1.TopologySelectorTerm, key string) ([]
Key: key,
Values: exp.Values,
}
} else if exp.Key == key {
newExp = exp
} else {
return nil, fmt.Errorf("unknown topology key: %v", exp.Key)
// Other topologies are passed through unchanged.
newExp = exp
}
newTerm.MatchLabelExpressions = append(newTerm.MatchLabelExpressions, newExp)
}

View File

@ -582,7 +582,6 @@ func TestTranslateAllowedTopologies(t *testing.T) {
name string
topology []v1.TopologySelectorTerm
expectedToplogy []v1.TopologySelectorTerm
expErr bool
}{
{
name: "no translation",
@ -664,18 +663,24 @@ func TestTranslateAllowedTopologies(t *testing.T) {
},
},
},
expErr: true,
expectedToplogy: []v1.TopologySelectorTerm{
{
MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
{
Key: "test",
Values: []string{"foo", "bar"},
},
},
},
},
},
}
for _, tc := range testCases {
t.Logf("Running test: %v", tc.name)
gotTop, err := translateAllowedTopologies(tc.topology, GCEPDTopologyKey)
if err != nil && !tc.expErr {
t.Errorf("Did not expect an error, got: %v", err)
}
if err == nil && tc.expErr {
t.Errorf("Expected an error but did not get one")
if err != nil {
t.Errorf("Unexpected error: %w", err)
}
if !reflect.DeepEqual(gotTop, tc.expectedToplogy) {