diff --git a/pkg/client/options.go b/pkg/client/options.go index 32bdbac3e1..d81bf25de9 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -513,19 +513,15 @@ type MatchingLabels map[string]string // ApplyToList applies this configuration to the given list options. func (m MatchingLabels) ApplyToList(opts *ListOptions) { // TODO(directxman12): can we avoid reserializing this over and over? - var sel labels.Selector - if opts.LabelSelector != nil { - sel = opts.LabelSelector - } else { - sel = labels.NewSelector() + if opts.LabelSelector == nil { + opts.LabelSelector = labels.NewSelector() } // If there's already a selector, we need to AND the two together. noValidSel := labels.SelectorFromValidatedSet(map[string]string(m)) reqs, _ := noValidSel.Requirements() for _, req := range reqs { - sel = sel.Add(req) + opts.LabelSelector = opts.LabelSelector.Add(req) } - opts.LabelSelector = sel } // ApplyToDeleteAllOf applies this configuration to the given an List options. @@ -539,21 +535,17 @@ type HasLabels []string // ApplyToList applies this configuration to the given list options. func (m HasLabels) ApplyToList(opts *ListOptions) { - var sel labels.Selector - if opts.LabelSelector != nil { - sel = opts.LabelSelector - } else { - sel = labels.NewSelector() + if opts.LabelSelector == nil { + opts.LabelSelector = labels.NewSelector() } - // TODO: ignore invalid labels will result in empty selector. - // This is not consistent to the MatchingLabels behavior. + // TODO: ignore invalid labels will result in an empty selector. + // This is inconsistent to the that of MatchingLabels. for _, label := range m { r, err := labels.NewRequirement(label, selection.Exists, nil) if err == nil { - sel = sel.Add(*r) + opts.LabelSelector = opts.LabelSelector.Add(*r) } } - opts.LabelSelector = sel } // ApplyToDeleteAllOf applies this configuration to the given an List options.