Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add multigroup flag in alpha generate subcommand #3487

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pkg/rescaffold/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ const DefaultOutputDir = "output-dir"
func (opts *MigrateOptions) Rescaffold() error {
config := yaml.New(machinery.Filesystem{FS: afero.NewOsFs()})
if err := config.LoadFrom(opts.InputDir); err != nil {
log.Fatal(err)
log.Fatalf("Failed to load PROJECT file %v", err)
}
// create output directory
// nolint: gosec
if err := os.MkdirAll(opts.OutputDir, 0755); err != nil {
log.Fatal(err)
log.Fatalf("Failed to create output directory %v", err)
}
// use the new directory to set up the new project
if err := os.Chdir(opts.OutputDir); err != nil {
log.Fatal(err)
log.Fatalf("Failed to change the current working directory %v", err)
}
// init project with plugins
if err := kubebuilderInit(config); err != nil {
log.Fatal(err)
log.Fatalf("Failed to run init subcommand %v", err)
}
// call edit subcommands to enable or disable multigroup layout
if err := kubebuilderEdit(config); err != nil {
log.Fatalf("Failed to run edit subcommand %v", 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())
}
Loading