Skip to content

Commit

Permalink
Merge pull request #2039 from joelanford/fix-selectors-by-object-scheme
Browse files Browse the repository at this point in the history
馃悰 fix: improve semantics of combining cache selectorsByObject
  • Loading branch information
k8s-ci-robot committed Nov 9, 2022
2 parents ff622bd + 06a9617 commit 5378660
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/cache/cache.go
Expand Up @@ -272,7 +272,7 @@ func combineSelectors(inherited, options Options, scheme *runtime.Scheme) (Selec
//
// There is a bunch of complexity here because we need to convert to SelectorsByGVK
// to be able to match keys between options and inherited and then convert back to SelectorsByObject
optionsSelectorsByGVK, err := convertToByGVK(options.SelectorsByObject, options.DefaultSelector, options.Scheme)
optionsSelectorsByGVK, err := convertToByGVK(options.SelectorsByObject, options.DefaultSelector, scheme)
if err != nil {
return nil, ObjectSelector{}, err
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/cache/cache_unit_test.go
Expand Up @@ -177,6 +177,28 @@ var _ = Describe("cache.inheritFrom", func() {
Expect(selector.Field.Matches(fields.Set{"metadata.name": "other", "metadata.namespace": "inherited"})).To(BeFalse())
Expect(selector.Field.Matches(fields.Set{"metadata.name": "specified", "metadata.namespace": "inherited"})).To(BeTrue())
})
It("uses inherited scheme for inherited selectors", func() {
inherited.Scheme = coreScheme
inherited.SelectorsByObject = map[client.Object]ObjectSelector{&corev1.ConfigMap{}: {}}
Expect(checkError(specified.inheritFrom(inherited)).SelectorsByObject).To(HaveLen(1))
})
It("does not use specified scheme for inherited selectors", func() {
inherited.Scheme = runtime.NewScheme()
specified.Scheme = coreScheme
inherited.SelectorsByObject = map[client.Object]ObjectSelector{&corev1.ConfigMap{}: {}}
_, err := specified.inheritFrom(inherited)
Expect(err).To(WithTransform(runtime.IsNotRegisteredError, BeTrue()))
})
It("uses inherited scheme for specified selectors", func() {
inherited.Scheme = coreScheme
specified.SelectorsByObject = map[client.Object]ObjectSelector{&corev1.ConfigMap{}: {}}
Expect(checkError(specified.inheritFrom(inherited)).SelectorsByObject).To(HaveLen(1))
})
It("uses specified scheme for specified selectors", func() {
specified.Scheme = coreScheme
specified.SelectorsByObject = map[client.Object]ObjectSelector{&corev1.ConfigMap{}: {}}
Expect(checkError(specified.inheritFrom(inherited)).SelectorsByObject).To(HaveLen(1))
})
})
Context("DefaultSelector", func() {
It("is unchanged when specified and inherited are unset", func() {
Expand Down

0 comments on commit 5378660

Please sign in to comment.