Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 fix: improve semantics of combining cache selectorsByObject #2039

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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