mirror of https://github.com/k3s-io/k3s
Merge pull request #55233 from sttts/sttts-codegen-comment-blocks
Automatic merge from submit-queue (batch tested with PRs 55233, 55927, 55903, 54867, 55940). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. code-generators: remove distinction of 1st and 2nd comment block for tags Follow-up for https://github.com/kubernetes/kubernetes/pull/53579. Fixes #53893. ```release-note Allow code-generator tags in the 2nd closest comment block and directly above a statement. ```pull/6/head
commit
3b4be46683
|
@ -163,7 +163,7 @@ func packageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli
|
|||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient
|
||||
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
} else {
|
||||
// User has not specified any override for this group version.
|
||||
// filter out types which dont have genclient.
|
||||
if tags := util.MustParseClientGenTags(t.SecondClosestCommentLines); !tags.GenerateClient {
|
||||
if tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)); !tags.GenerateClient {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ type tagOverrideNamer struct {
|
|||
}
|
||||
|
||||
func (n *tagOverrideNamer) Name(t *types.Type) string {
|
||||
if nameOverride := extractTag(n.tagName, t.SecondClosestCommentLines); nameOverride != "" {
|
||||
if nameOverride := extractTag(n.tagName, append(t.SecondClosestCommentLines, t.CommentLines...)); nameOverride != "" {
|
||||
return nameOverride
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ func PackageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli
|
|||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient
|
||||
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io
|
|||
|
||||
sw.Do(groupClientTemplate, m)
|
||||
for _, t := range g.types {
|
||||
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func genStatus(t *types.Type) bool {
|
|||
}
|
||||
}
|
||||
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return hasStatus && !tags.NoStatus
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func hasObjectMeta(t *types.Type) bool {
|
|||
func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
pkg := filepath.Base(t.Name.Package)
|
||||
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
|
|||
sw.Do(groupInterfaceTemplate, m)
|
||||
sw.Do(groupClientTemplate, m)
|
||||
for _, t := range g.types {
|
||||
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -67,14 +67,14 @@ func genStatus(t *types.Type) bool {
|
|||
break
|
||||
}
|
||||
}
|
||||
return hasStatus && !util.MustParseClientGenTags(t.SecondClosestCommentLines).NoStatus
|
||||
return hasStatus && !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).NoStatus
|
||||
}
|
||||
|
||||
// GenerateType makes the body of a file implementing the individual typed client for type t.
|
||||
func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
pkg := filepath.Base(t.Name.Package)
|
||||
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
|
|||
clientSetInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"})
|
||||
informerFor := "InformerFor"
|
||||
|
||||
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func generatedBy() string {
|
|||
func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
|
||||
generatingForPackage := false
|
||||
for _, t := range p.Types {
|
||||
if !util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient {
|
||||
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
|
||||
continue
|
||||
}
|
||||
generatingForPackage = true
|
||||
|
@ -176,7 +176,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
|
||||
var typesToGenerate []*types.Type
|
||||
for _, t := range p.Types {
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if !tags.GenerateClient || tags.NoVerbs || !tags.HasVerb("list") || !tags.HasVerb("watch") {
|
||||
continue
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ func groupPackage(basePackage string, groupVersions clientgentypes.GroupVersions
|
|||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
|
||||
},
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ func versionPackage(basePackage string, groupPkgName string, gv clientgentypes.G
|
|||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
|
||||
},
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func (g *expansionGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
|||
func (g *expansionGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
for _, t := range g.types {
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if _, err := os.Stat(filepath.Join(g.packagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
|
||||
sw.Do(expansionInterfaceTemplate, t)
|
||||
if !tags.NonNamespaced {
|
||||
|
|
|
@ -118,7 +118,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
|
||||
var typesToGenerate []*types.Type
|
||||
for _, t := range p.Types {
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if !tags.GenerateClient || !tags.HasVerb("list") || !tags.HasVerb("get") {
|
||||
continue
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("get")
|
||||
},
|
||||
})
|
||||
|
@ -174,7 +174,7 @@ func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
|
|||
generatingForPackage := false
|
||||
for _, t := range p.Types {
|
||||
// filter out types which dont have genclient.
|
||||
if !util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient {
|
||||
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
|
||||
continue
|
||||
}
|
||||
generatingForPackage = true
|
||||
|
@ -238,7 +238,7 @@ func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io
|
|||
"objectMeta": g.objectMeta,
|
||||
}
|
||||
|
||||
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue