mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #103750 from mattcary/allowedtopo
Pass unknown labels in allowedTopologies during CSI translation
This commit is contained in:
commit
bb817a911b
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user