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

[enhancement] added hidden flag to override number of virtual cluster restriction #2064

Merged
merged 1 commit into from
Aug 14, 2024
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
7 changes: 5 additions & 2 deletions cmd/vclusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type CreateCmd struct {
*flags.GlobalFlags
cli.CreateOptions

log log.Logger
log log.Logger
reuseNamespace bool
}

// NewCreateCmd creates a new command
Expand Down Expand Up @@ -53,6 +54,8 @@ vcluster create test --namespace test
}

cobraCmd.Flags().StringVar(&cmd.Driver, "driver", "", "The driver to use for managing the virtual cluster, can be either helm or platform.")
cobraCmd.Flags().BoolVar(&cmd.reuseNamespace, "reuse-namespace", false, "Allows to create multiple virtual clusters in a single namespace")
cobraCmd.Flag("reuse-namespace").Hidden = true

create.AddCommonFlags(cobraCmd, &cmd.CreateOptions)
create.AddHelmFlags(cobraCmd, &cmd.CreateOptions)
Expand Down Expand Up @@ -82,5 +85,5 @@ func (cmd *CreateCmd) Run(ctx context.Context, args []string) error {
return cli.CreatePlatform(ctx, &cmd.CreateOptions, cmd.GlobalFlags, args[0], cmd.log)
}

return cli.CreateHelm(ctx, &cmd.CreateOptions, cmd.GlobalFlags, args[0], cmd.log)
return cli.CreateHelm(ctx, &cmd.CreateOptions, cmd.GlobalFlags, args[0], cmd.log, cmd.reuseNamespace)
}
11 changes: 7 additions & 4 deletions pkg/cli/create_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type createHelm struct {
localCluster bool
}

func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.GlobalFlags, vClusterName string, log log.Logger) error {
func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.GlobalFlags, vClusterName string, log log.Logger, reuseNamespace bool) error {
cmd := &createHelm{
GlobalFlags: globalFlags,
CreateOptions: options,
Expand Down Expand Up @@ -134,9 +134,12 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.
if err != nil {
return err
}
for _, v := range vclusters {
if v.Namespace == cmd.Namespace && v.Name != vClusterName {
return fmt.Errorf("there is already a virtual cluster in namespace %s", cmd.Namespace)

if !reuseNamespace {
for _, v := range vclusters {
if v.Namespace == cmd.Namespace && v.Name != vClusterName {
return fmt.Errorf("there is already a virtual cluster in namespace %s", cmd.Namespace)
}
}
}

Expand Down
Loading