Skip to content

Commit

Permalink
Merge pull request #2246 from joelanford/preserve-unstructured-gvk-ca…
Browse files Browse the repository at this point in the history
…che-options

🐛 Preserve unstructured object GVKs in cache.Options.ByObject
  • Loading branch information
k8s-ci-robot committed Mar 26, 2023
2 parents c3c1f05 + db28b04 commit 3b0376c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cache/cache.go
Expand Up @@ -481,6 +481,7 @@ func convertToByObject(in map[schema.GroupVersionKind]internal.InformersOptsByGV
if !ok {
return nil, fmt.Errorf("object %T for GVK %q does not implement client.Object", obj, gvk)
}
cObj.GetObjectKind().SetGroupVersionKind(gvk)
out[cObj] = ByObject{
Field: opts.Selector.Field,
Label: opts.Selector.Label,
Expand Down
17 changes: 17 additions & 0 deletions pkg/cache/cache_unit_test.go
Expand Up @@ -126,6 +126,23 @@ var _ = Describe("cache.inheritFrom", func() {
Expect(checkError(specified.inheritFrom(inherited)).Namespaces).To(Equal(specified.Namespaces))
})
})
Context("ByObject", func() {
It("maintains GVKs of unstructured ByObject keys", func() {
gvk := gv.WithKind("Unstructured")
obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(gvk)
specified.Scheme = coreScheme
specified.Scheme.AddKnownTypeWithName(gvk, obj)
specified.ByObject = map[client.Object]ByObject{
obj: {},
}
byObject := checkError(specified.inheritFrom(inherited)).ByObject
Expect(byObject).To(HaveLen(1))
for obj := range byObject {
Expect(obj.GetObjectKind().GroupVersionKind()).To(Equal(gvk))
}
})
})
Context("SelectorsByObject", func() {
It("is unchanged when specified and inherited are unset", func() {
Expect(checkError(specified.inheritFrom(inherited)).ByObject).To(HaveLen(0))
Expand Down

0 comments on commit 3b0376c

Please sign in to comment.