From 23ca61305e8e1eb5a074a6cd8432b2fad6b9b510 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Thu, 9 Jul 2020 13:25:17 -0700 Subject: [PATCH] add support for kubebuilder v2 tags --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 33d0858..86a67f2 100644 --- a/main.go +++ b/main.go @@ -299,9 +299,22 @@ func findTypeReferences(pkgs []*apiPackage) map[*types.Type][]*types.Type { } func isExportedType(t *types.Type) bool { - // TODO(ahmetb) use types.ExtractSingleBoolCommentTag() to parse +genclient - // https://godoc.org/k8s.io/gengo/types#ExtractCommentTags - return strings.Contains(strings.Join(t.SecondClosestCommentLines, "\n"), "+genclient") + comments := make([]string, 0, len(t.CommentLines)+len(t.SecondClosestCommentLines)) + comments = append(comments, t.CommentLines...) + comments = append(comments, t.SecondClosestCommentLines...) + commentTags := types.ExtractCommentTags("+", comments) + _, hasGenclient := commentTags["genclient"] + _, hasKubeBuilderRootObj := commentTags["kubebuilder:object:root"] + return hasGenclient || (hasKubeBuilderRootObj && !isObjectListType(t)) +} + +func isObjectListType(t *types.Type) bool { + for _, member := range t.Members { + if member.Name == "ListMeta" && member.Embedded { + return true + } + } + return false } func fieldName(m types.Member) string {