Skip to content

Commit cd65cb2

Browse files
authored
Merge pull request #2249 from joelanford/0-14-preserve-unstructured-gvk-cache-options
🐛 release-0.14: Preserve unstructured object GVKs when using *ByObject cache options
2 parents ffb74e5 + 1dcfec4 commit cd65cb2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/cache/cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ func convertToByObject[T any](byGVK map[schema.GroupVersionKind]T, scheme *runti
452452
if !ok {
453453
return nil, def, fmt.Errorf("object %T for GVK %q does not implement client.Object", obj, gvk)
454454
}
455+
cObj.GetObjectKind().SetGroupVersionKind(gvk)
455456
if byObject == nil {
456457
byObject = map[client.Object]T{}
457458
}

pkg/cache/cache_unit_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,27 @@ var _ = Describe("cache.inheritFrom", func() {
468468
))
469469
})
470470
})
471+
472+
Context("convertToByObject", func() {
473+
It("embeds the GVK in the returned objects", func() {
474+
gvk := gv.WithKind("Unstructured")
475+
obj := &unstructured.Unstructured{}
476+
477+
sch := runtime.NewScheme()
478+
sch.AddKnownTypeWithName(gvk, obj)
479+
480+
byObj, def, err := convertToByObject(map[schema.GroupVersionKind]struct{}{
481+
gvk: {},
482+
}, sch)
483+
484+
Expect(err).NotTo(HaveOccurred())
485+
Expect(def).To(Equal(struct{}{}))
486+
Expect(byObj).To(HaveLen(1))
487+
for obj := range byObj {
488+
Expect(obj.GetObjectKind().GroupVersionKind()).To(Equal(gvk))
489+
}
490+
})
491+
})
471492
})
472493

473494
func checkError[T any](v T, err error) T {

0 commit comments

Comments
 (0)