Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ type MatchingLabelsSelector struct {

// ApplyToList applies this configuration to the given list options.
func (m MatchingLabelsSelector) ApplyToList(opts *ListOptions) {
if m.Selector == nil {
m.Selector = labels.Nothing()
}
opts.LabelSelector = m
}

Expand Down Expand Up @@ -677,6 +680,9 @@ type MatchingFieldsSelector struct {

// ApplyToList applies this configuration to the given list options.
func (m MatchingFieldsSelector) ApplyToList(opts *ListOptions) {
if m.Selector == nil {
m.Selector = fields.Nothing()
}
opts.FieldSelector = m
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/client/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,38 @@ var _ = Describe("ListOptions", func() {
o.ApplyToList(newListOpts)
Expect(newListOpts).To(Equal(o))
})
It("Should set LabelSelector with MatchingLabelsSelector", func() {
labelSelector, err := labels.Parse("a=b")
Expect(err).NotTo(HaveOccurred())
newListOpts := &client.ListOptions{}
newListOpts.ApplyOptions([]client.ListOption{client.MatchingLabelsSelector{Selector: labelSelector}})
expectedListOpts := &client.ListOptions{LabelSelector: client.MatchingLabelsSelector{Selector: labelSelector}}
Expect(newListOpts).To(Equal(expectedListOpts))
})
It("Should set LabelSelector to nothing with empty MatchingLabelsSelector", func() {
newListOpts := &client.ListOptions{}
newListOpts.ApplyOptions([]client.ListOption{client.MatchingLabelsSelector{}})
expectedListOpts := &client.ListOptions{LabelSelector: client.MatchingLabelsSelector{Selector: labels.Nothing()}}
Expect(newListOpts).To(Equal(expectedListOpts))
})
It("Should set FieldSelector", func() {
o := &client.ListOptions{FieldSelector: fields.Nothing()}
newListOpts := &client.ListOptions{}
o.ApplyToList(newListOpts)
Expect(newListOpts).To(Equal(o))
})
It("Should set FieldSelector with MatchingFieldsSelector", func() {
newListOpts := &client.ListOptions{}
newListOpts.ApplyOptions([]client.ListOption{client.MatchingFieldsSelector{Selector: fields.Nothing()}})
expectedListOpts := &client.ListOptions{FieldSelector: client.MatchingFieldsSelector{Selector: fields.Nothing()}}
Expect(newListOpts).To(Equal(expectedListOpts))
})
It("Should set FieldSelector to nothing with empty MatchingFieldsSelector", func() {
newListOpts := &client.ListOptions{}
newListOpts.ApplyOptions([]client.ListOption{client.MatchingFieldsSelector{}})
expectedListOpts := &client.ListOptions{FieldSelector: client.MatchingFieldsSelector{Selector: fields.Nothing()}}
Expect(newListOpts).To(Equal(expectedListOpts))
})
It("Should set Namespace", func() {
o := &client.ListOptions{Namespace: "my-ns"}
newListOpts := &client.ListOptions{}
Expand Down