Skip to content

Commit

Permalink
feat: add multigroup flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yyy1000 committed Jul 5, 2023
1 parent a632400 commit 5cf508a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/rescaffold/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (opts *MigrateOptions) Rescaffold() error {
if err := kubebuilderInit(config); err != nil {
log.Fatal(err)
}
// call edit subcommands to enable or disable multigroup layout
if err := kubebuilderEdit(config); err != nil {
log.Fatal(err)
}
return nil
}

Expand Down Expand Up @@ -107,6 +111,14 @@ func kubebuilderInit(store store.Store) error {
return util.RunCmd("kubebuilder init", "kubebuilder", args...)
}

func kubebuilderEdit(store store.Store) error {
if store.Config().IsMultiGroup() {
args := []string{"edit", "--multigroup"}
return util.RunCmd("kubebuilder edit", "kubebuilder", args...)
}
return nil
}

func getInitArgs(store store.Store) []string {
var args []string
plugins := store.Config().GetPluginChain()
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/alphagenerate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,24 @@ func ReGenerateProject(kbc *utils.TestContext) {
filepath.Join(kbc.Dir, "testdir", "PROJECT"), version)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, fileContainsExpr).To(BeTrue())

By("editing a project with multigroup=true")
err = kbc.Edit(
"--multigroup=true",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("regenerating the project at another output directory")
err = kbc.Regenerate(
"--input-dir", kbc.Dir,
"--output-dir", filepath.Join(kbc.Dir, "testdir2"),
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("checking if the project file was generated with the expected multigroup flag")
var multiGroup = `multigroup: true`
fileContainsExpr, err = pluginutil.HasFileContentWith(
filepath.Join(kbc.Dir, "testdir2", "PROJECT"), multiGroup)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, fileContainsExpr).To(BeTrue())
}

0 comments on commit 5cf508a

Please sign in to comment.