Skip to content

Commit df180ac

Browse files
authored
Merge pull request #882 from alvaroaleman/fix-selector
🐛 MatchingLabels: Make sure requests with invalid labels fail
2 parents be3a066 + 1c4a481 commit df180ac

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pkg/client/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ type MatchingLabels map[string]string
381381

382382
func (m MatchingLabels) ApplyToList(opts *ListOptions) {
383383
// TODO(directxman12): can we avoid reserializing this over and over?
384-
sel := labels.SelectorFromSet(map[string]string(m))
384+
sel := labels.SelectorFromValidatedSet(map[string]string(m))
385385
opts.LabelSelector = sel
386386
}
387387

pkg/client/options_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,17 @@ var _ = Describe("DeleteAllOfOptions", func() {
215215
Expect(newDeleteAllOfOpts).To(Equal(o))
216216
})
217217
})
218+
219+
var _ = Describe("MatchingLabels", func() {
220+
It("Should produce an invalid selector when given invalid input", func() {
221+
matchingLabels := client.MatchingLabels(map[string]string{"k": "axahm2EJ8Phiephe2eixohbee9eGeiyees1thuozi1xoh0GiuH3diewi8iem7Nui"})
222+
listOpts := &client.ListOptions{}
223+
matchingLabels.ApplyToList(listOpts)
224+
225+
r, _ := listOpts.LabelSelector.Requirements()
226+
_, err := labels.NewRequirement(r[0].Key(), r[0].Operator(), r[0].Values().List())
227+
Expect(err).ToNot(BeNil())
228+
expectedErrMsg := `invalid label value: "axahm2EJ8Phiephe2eixohbee9eGeiyees1thuozi1xoh0GiuH3diewi8iem7Nui": at key: "k": must be no more than 63 characters`
229+
Expect(err.Error()).To(Equal(expectedErrMsg))
230+
})
231+
})

0 commit comments

Comments
 (0)