mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Merge pull request #56099 from caesarxuchao/fix-client-gen-0-types
Automatic merge from submit-queue. 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>. Fix client-gen for groups that no types requiring clients If the group has no type with the `+genClient` tag, the group client is generated multiple times because the `Filter` function always returns true, resulting in bad output like https://gist.github.com/gmarek/9a11d5a305a52b193889684e56c103e4. unblock #49112 cc @gmarek
This commit is contained in:
commit
9d1e082105
@ -40,13 +40,19 @@ type genFakeForGroup struct {
|
|||||||
// types in this group
|
// types in this group
|
||||||
types []*types.Type
|
types []*types.Type
|
||||||
imports namer.ImportTracker
|
imports namer.ImportTracker
|
||||||
|
// If the genGroup has been called. This generator should only execute once.
|
||||||
|
called bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ generator.Generator = &genFakeForGroup{}
|
var _ generator.Generator = &genFakeForGroup{}
|
||||||
|
|
||||||
// We only want to call GenerateType() once per group.
|
// We only want to call GenerateType() once per group.
|
||||||
func (g *genFakeForGroup) Filter(c *generator.Context, t *types.Type) bool {
|
func (g *genFakeForGroup) Filter(c *generator.Context, t *types.Type) bool {
|
||||||
return len(g.types) == 0 || t == g.types[0]
|
if !g.called {
|
||||||
|
g.called = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *genFakeForGroup) Namers(c *generator.Context) namer.NameSystems {
|
func (g *genFakeForGroup) Namers(c *generator.Context) namer.NameSystems {
|
||||||
@ -56,7 +62,10 @@ func (g *genFakeForGroup) Namers(c *generator.Context) namer.NameSystems {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) {
|
func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) {
|
||||||
imports = append(g.imports.ImportLines(), strings.ToLower(fmt.Sprintf("%s \"%s\"", filepath.Base(g.realClientPackage), g.realClientPackage)))
|
imports = g.imports.ImportLines()
|
||||||
|
if len(g.types) != 0 {
|
||||||
|
imports = append(imports, strings.ToLower(fmt.Sprintf("%s \"%s\"", filepath.Base(g.realClientPackage), g.realClientPackage)))
|
||||||
|
}
|
||||||
return imports
|
return imports
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,13 +41,19 @@ type genGroup struct {
|
|||||||
imports namer.ImportTracker
|
imports namer.ImportTracker
|
||||||
inputPackage string
|
inputPackage string
|
||||||
clientsetPackage string
|
clientsetPackage string
|
||||||
|
// If the genGroup has been called. This generator should only execute once.
|
||||||
|
called bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ generator.Generator = &genGroup{}
|
var _ generator.Generator = &genGroup{}
|
||||||
|
|
||||||
// We only want to call GenerateType() once per group.
|
// We only want to call GenerateType() once per group.
|
||||||
func (g *genGroup) Filter(c *generator.Context, t *types.Type) bool {
|
func (g *genGroup) Filter(c *generator.Context, t *types.Type) bool {
|
||||||
return len(g.types) == 0 || t == g.types[0]
|
if !g.called {
|
||||||
|
g.called = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *genGroup) Namers(c *generator.Context) namer.NameSystems {
|
func (g *genGroup) Namers(c *generator.Context) namer.NameSystems {
|
||||||
|
Loading…
Reference in New Issue
Block a user