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

fix: Device Plugin daemonset keep restarting #805

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions controllers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,27 @@ func nodeSelectorTermsForPolicyList(policies []sriovnetworkv1.SriovNetworkNodePo
terms = append(terms, nodeSelector)
}

// sorting is needed to keep the daemon spec stable.
// the policies can come in a random order
sort.Slice(terms, func(i, j int) bool {
expressionsA := terms[i].MatchExpressions
expressionsB := terms[j].MatchExpressions
if len(expressionsA) != len(expressionsB) {
return len(expressionsA) < len(expressionsB)
}
for k := range expressionsA {
expressionA := expressionsA[k]
expressionB := expressionsB[k]
if expressionA.Key != expressionB.Key {
return expressionA.Key < expressionB.Key
}
if expressionA.Values[0] != expressionB.Values[0] {
return expressionA.Values[0] != expressionB.Values[0]
armandpicard marked this conversation as resolved.
Show resolved Hide resolved
}
}
return true
})

return terms
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ func TestNodeSelectorMerge(t *testing.T) {
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Operator: corev1.NodeSelectorOpIn,
Key: "foo",
Values: []string{"bar"},
Key: "bb",
Values: []string{"cc"},
},
},
},
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Operator: corev1.NodeSelectorOpIn,
Key: "bb",
Values: []string{"cc"},
Key: "foo",
Values: []string{"bar"},
},
},
},
Expand Down
Loading