@@ -513,19 +513,15 @@ type MatchingLabels map[string]string
513
513
// ApplyToList applies this configuration to the given list options.
514
514
func (m MatchingLabels ) ApplyToList (opts * ListOptions ) {
515
515
// 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 ()
521
518
}
522
519
// If there's already a selector, we need to AND the two together.
523
520
noValidSel := labels .SelectorFromValidatedSet (map [string ]string (m ))
524
521
reqs , _ := noValidSel .Requirements ()
525
522
for _ , req := range reqs {
526
- sel = sel .Add (req )
523
+ opts . LabelSelector = opts . LabelSelector .Add (req )
527
524
}
528
- opts .LabelSelector = sel
529
525
}
530
526
531
527
// ApplyToDeleteAllOf applies this configuration to the given an List options.
@@ -539,21 +535,17 @@ type HasLabels []string
539
535
540
536
// ApplyToList applies this configuration to the given list options.
541
537
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 ()
547
540
}
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 .
550
543
for _ , label := range m {
551
544
r , err := labels .NewRequirement (label , selection .Exists , nil )
552
545
if err == nil {
553
- sel = sel .Add (* r )
546
+ opts . LabelSelector = opts . LabelSelector .Add (* r )
554
547
}
555
548
}
556
- opts .LabelSelector = sel
557
549
}
558
550
559
551
// ApplyToDeleteAllOf applies this configuration to the given an List options.
0 commit comments