Skip to content

Commit

Permalink
Merge pull request #121496 from benluddy/metav1-labelselector-fuzz
Browse files Browse the repository at this point in the history
Deduplicate set expression values in metav1.LabelSelector fuzzer.
  • Loading branch information
k8s-ci-robot committed May 3, 2024
2 parents f97ac22 + a4c2f78 commit 99129ed
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
)

func genericFuzzerFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
Expand Down Expand Up @@ -249,8 +250,9 @@ func v1FuzzerFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
}

if j.MatchExpressions != nil {
// NB: the label selector parser code sorts match expressions by key, and sorts the values,
// so we need to make sure ours are sorted as well here to preserve round-trip comparison.
// NB: the label selector parser code sorts match expressions by key, and
// sorts and deduplicates the values, so we need to make sure ours are
// sorted and deduplicated as well here to preserve round-trip comparison.
// In practice, not sorting doesn't hurt anything...

for i := range j.MatchExpressions {
Expand All @@ -266,7 +268,7 @@ func v1FuzzerFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
for i := range req.Values {
req.Values[i] = randomLabelPart(c, true)
}
sort.Strings(req.Values)
req.Values = sets.List(sets.New(req.Values...))
} else {
req.Values = nil
}
Expand Down

0 comments on commit 99129ed

Please sign in to comment.