From 13c2f22d0fd7be2645c0b703856fbebe9086bcfe Mon Sep 17 00:00:00 2001 From: akutz Date: Wed, 25 May 2022 11:04:15 -0500 Subject: [PATCH] crdgen: compare metav1 pkg by ID This patch updates the way the CRD generator compares an imported metav1 package. Previously the comparison occurred using a Golang equality operator, !=, against two, in-memory data structures. However, this fails when multiple root paths are loaded. Their metav1 packages are identical, just not identical objects in memory. This patch updates the comparison to compare the package IDs, not the instance of the object. --- pkg/crd/gen.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/crd/gen.go b/pkg/crd/gen.go index 43293d2a9..92eefb4ae 100644 --- a/pkg/crd/gen.go +++ b/pkg/crd/gen.go @@ -247,7 +247,12 @@ func FindKubeKinds(parser *Parser, metav1Pkg *loader.Package) map[schema.GroupKi } fieldPkgPath := loader.NonVendorPath(namedField.Obj().Pkg().Path()) fieldPkg := pkg.Imports()[fieldPkgPath] - if fieldPkg != metav1Pkg { + + // Compare the metav1 package by ID and not by the actual instance + // of the object. The objects in memory could be different due to + // loading from different root paths, even when they both refer to + // the same metav1 package. + if fieldPkg == nil || fieldPkg.ID != metav1Pkg.ID { continue }