Skip to content

Commit

Permalink
Update applyconfig-gen for pacakges where group and dir differ in name
Browse files Browse the repository at this point in the history
It is possible that package paths might differ from the group name, see
https://github.com/openshift/api/blob/master/operatorcontrolplane/v1alpha1/doc.go
notice that pacakge name is `operatorcontrolplane` whereas the group is
`controlplane.operator...`. This confuses the generator since it tries
to extrapolate the name of the package based on the group name. Whereas
the ImportTracker can properly recognize the import path. This leads to
cyclical imports in packages where the group name is different from the
actual import path.

Kubernetes-commit: 4d1dd9cd07912190cffc68c54c17395391c8b4d1
  • Loading branch information
soltysh authored and k8s-publishing-bot committed Apr 5, 2024
1 parent 64318e9 commit b23df5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/applyconfiguration-gen/generators/applyconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type applyConfigurationGenerator struct {
generator.GoGenerator
// outPkgBase is the base package, under which the "internal" and GV-specific subdirs live
outPkgBase string // must be a Go import-path
localPkg string
groupVersion clientgentypes.GroupVersion
applyConfig applyConfig
imports namer.ImportTracker
Expand All @@ -49,9 +50,8 @@ func (g *applyConfigurationGenerator) Filter(_ *generator.Context, t *types.Type
}

func (g *applyConfigurationGenerator) Namers(*generator.Context) namer.NameSystems {
localPkg := path.Join(g.outPkgBase, g.groupVersion.Group.PackageName(), g.groupVersion.Version.PackageName())
return namer.NameSystems{
"raw": namer.NewRawNamer(localPkg, g.imports),
"raw": namer.NewRawNamer(g.localPkg, g.imports),
"singularKind": namer.NewPublicNamer(0),
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (b *$.ApplyConfig.ApplyConfiguration|public$) ensure$.MemberType.Elem|publi

var clientgenTypeConstructorNamespaced = `
// $.ApplyConfig.Type|public$ constructs an declarative configuration of the $.ApplyConfig.Type|public$ type for use with
// apply.
// apply.
func $.ApplyConfig.Type|public$(name, namespace string) *$.ApplyConfig.ApplyConfiguration|public$ {
b := &$.ApplyConfig.ApplyConfiguration|public${}
b.WithName(name)
Expand Down
1 change: 1 addition & 0 deletions cmd/applyconfiguration-gen/generators/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir
OutputFilename: strings.ToLower(toGenerate.Type.Name.Name) + ".go",
},
outPkgBase: outputPkgBase,
localPkg: outputPkg,
groupVersion: gv,
applyConfig: toGenerate,
imports: generator.NewImportTracker(),
Expand Down

0 comments on commit b23df5e

Please sign in to comment.