Skip to content

Commit 453920e

Browse files
committed
simplified code
1 parent 12dff25 commit 453920e

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

pkg/client/options.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,19 +513,15 @@ type MatchingLabels map[string]string
513513
// ApplyToList applies this configuration to the given list options.
514514
func (m MatchingLabels) ApplyToList(opts *ListOptions) {
515515
// TODO(directxman12): can we avoid reserializing this over and over?
516-
var sel labels.Selector
517-
if opts.LabelSelector != nil {
518-
sel = opts.LabelSelector
519-
} else {
520-
sel = labels.NewSelector()
516+
if opts.LabelSelector == nil {
517+
opts.LabelSelector = labels.NewSelector()
521518
}
522519
// If there's already a selector, we need to AND the two together.
523520
noValidSel := labels.SelectorFromValidatedSet(map[string]string(m))
524521
reqs, _ := noValidSel.Requirements()
525522
for _, req := range reqs {
526-
sel = sel.Add(req)
523+
opts.LabelSelector = opts.LabelSelector.Add(req)
527524
}
528-
opts.LabelSelector = sel
529525
}
530526

531527
// ApplyToDeleteAllOf applies this configuration to the given an List options.
@@ -539,21 +535,17 @@ type HasLabels []string
539535

540536
// ApplyToList applies this configuration to the given list options.
541537
func (m HasLabels) ApplyToList(opts *ListOptions) {
542-
var sel labels.Selector
543-
if opts.LabelSelector != nil {
544-
sel = opts.LabelSelector
545-
} else {
546-
sel = labels.NewSelector()
538+
if opts.LabelSelector == nil {
539+
opts.LabelSelector = labels.NewSelector()
547540
}
548-
// TODO: ignore invalid labels will result in empty selector.
549-
// This is not consistent to the MatchingLabels behavior.
541+
// TODO: ignore invalid labels will result in an empty selector.
542+
// This is inconsistent to the that of MatchingLabels.
550543
for _, label := range m {
551544
r, err := labels.NewRequirement(label, selection.Exists, nil)
552545
if err == nil {
553-
sel = sel.Add(*r)
546+
opts.LabelSelector = opts.LabelSelector.Add(*r)
554547
}
555548
}
556-
opts.LabelSelector = sel
557549
}
558550

559551
// ApplyToDeleteAllOf applies this configuration to the given an List options.

0 commit comments

Comments
 (0)