Skip to content

Commit

Permalink
Add ImportPath for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
rmweir committed Sep 1, 2023
1 parent 3604a6b commit b9331c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

func main() {
controllergen.Run(args.Options{
ImportPackage: "github.com/rancher/wrangler/v2/pkg/generated",
OutputPackage: "github.com/rancher/wrangler/pkg/generated",
Boilerplate: "scripts/boilerplate.go.txt",
Groups: map[string]args.Group{
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller-gen/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
)

type CustomArgs struct {
Package string
TypesByGroup map[schema.GroupVersion][]*types.Name
Options Options
OutputBase string
Package string
ImportPackage string
TypesByGroup map[schema.GroupVersion][]*types.Name
Options Options
OutputBase string
}

type Options struct {
ImportPackage string
OutputPackage string
Groups map[string]Group
Boilerplate string
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller-gen/generators/group_interface_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func (f *interfaceGo) Imports(context *generator.Context) []string {
if gv.Group != f.group {
continue
}
packages = append(packages, fmt.Sprintf("%s \"%s/controllers/%s/%s\"", gv.Version, f.customArgs.Package,
pkg := f.customArgs.ImportPackage
if pkg == "" {
pkg = f.customArgs.Package
}
packages = append(packages, fmt.Sprintf("%s \"%s/controllers/%s/%s\"", gv.Version, pkg,
groupPackageName(gv.Group, f.customArgs.Options.Groups[gv.Group].OutputControllerPackageName), gv.Version))
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/controller-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (

func Run(opts cgargs.Options) {
customArgs := &cgargs.CustomArgs{
Options: opts,
TypesByGroup: map[schema.GroupVersion][]*types.Name{},
Package: opts.OutputPackage,
ImportPackage: opts.ImportPackage,
Options: opts,
TypesByGroup: map[schema.GroupVersion][]*types.Name{},
Package: opts.OutputPackage,
}

genericArgs := args.Default().WithoutDefaultFlagParsing()
genericArgs.CustomArgs = customArgs
genericArgs.GoHeaderFilePath = opts.Boilerplate
Expand Down

0 comments on commit b9331c2

Please sign in to comment.