-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Description
When trying to get a List using the variadic ListOptions argument, I ran to unexpected behavior if applying both HasLabels and MatchingLabels.
List(ctx, podList, client.InNamespace(namespace)
client.MatchingLabels{
utils.ClusterLabelName: clusterName,
},
client.HasLabels{"role"}, // this ensures we are getting instance pods only
)
When watching the code in action, more pods than expected were being returned.
It seemed as if the ListOptions were being OR'ed rather than AND'ed.
Looking into the implementation of MatchingLabels
and HasLabels
, in their ApplyToList(opts *ListOptions)
,
both will overwrite whatever values the LabelSelector
had before.
opts.LabelSelector = sel
This means, likely, that if we apply both HasLabels and MatchingLabels, the last one applied will "win".
This is rather un-intuitive behavior.
If it is so by design, I think it should be documented.
If possible, I would think a logical AND would be the intuitive expectation.
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.Denotes an issue or PR that has aged beyond stale and will be auto-closed.