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

subset of supported topology keys are not working for waitforfirstconsumer #421

Merged
merged 1 commit into from
Apr 1, 2020
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
15 changes: 13 additions & 2 deletions pkg/controller/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func GenerateAccessibilityRequirements(
allowedTopologiesFlatten := flatten(allowedTopologies)
found := false
for _, t := range allowedTopologiesFlatten {
if t.equal(selectedTopology) {
if t.subset(selectedTopology) {
found = true
break
}
Expand Down Expand Up @@ -480,7 +480,7 @@ func sortAndShift(terms []topologyTerm, primary topologyTerm, shiftIndex uint32)
preferredTerms = append(terms[shiftIndex:], terms[:shiftIndex]...)
} else {
for i, t := range terms {
if t.equal(primary) {
if t.subset(primary) {
preferredTerms = append(terms[i:], terms[:i]...)
break
}
Expand Down Expand Up @@ -562,6 +562,17 @@ func (t topologyTerm) less(other topologyTerm) bool {
return t.hash() < other.hash()
}

func (t topologyTerm) subset(other topologyTerm) bool {
for key, tv := range t {
v, ok := other[key]
if !ok || v != tv {
return false
}
}

return true
}

func (t topologyTerm) equal(other topologyTerm) bool {
return t.hash() == other.hash()
}
Expand Down
67 changes: 67 additions & 0 deletions pkg/controller/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,73 @@ func TestPreferredTopologies(t *testing.T) {
},
expectError: true,
},
"allowedTopologies is subset of selected node's topology": {
pawanpraka1 marked this conversation as resolved.
Show resolved Hide resolved
allowedTopologies: []v1.TopologySelectorTerm{
{
MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
{
Key: "com.example.csi/disk",
Values: []string{"ssd"},
},
{
Key: "com.example.csi/zone",
Values: []string{"zone1"},
},
},
},
},
nodeLabels: []map[string]string{
{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rack1", "com.example.csi/disk": "ssd"},
{"com.example.csi/zone": "zone2", "com.example.csi/rack": "rack2", "com.example.csi/disk": "ssd"},
{"com.example.csi/zone": "zone2", "com.example.csi/rack": "rack1", "com.example.csi/disk": "nvme"},
},
topologyKeys: []map[string][]string{
{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack", "com.example.csi/disk"}},
{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack", "com.example.csi/disk"}},
{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack", "com.example.csi/disk"}},
},
expectError: false,
expectedPreferred: []*csi.Topology{
{
Segments: map[string]string{
"com.example.csi/disk": "ssd",
"com.example.csi/zone": "zone1",
pawanpraka1 marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
expectedStrictPreferred: []*csi.Topology{
{
Segments: map[string]string{
"com.example.csi/disk": "ssd",
"com.example.csi/rack": "rack1",
"com.example.csi/zone": "zone1",
},
},
},
},
"allowedTopologies is not the subset of selected node's topology": {
allowedTopologies: []v1.TopologySelectorTerm{
{
MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
{
Key: "com.example.csi/zone",
Values: []string{"zone1"},
},
},
},
},
nodeLabels: []map[string]string{
{"com.example.csi/zone": "zone10", "com.example.csi/rack": "rack1"},
{"com.example.csi/zone": "zone11", "com.example.csi/rack": "rack2"},
{"com.example.csi/zone": "zone12", "com.example.csi/rack": "rack1"},
},
topologyKeys: []map[string][]string{
{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
},
expectError: true,
},
}

for name, tc := range testcases {
Expand Down