Skip to content

Commit

Permalink
[enhancement] added hidden flag to override number of virtual cluster
Browse files Browse the repository at this point in the history
restriction
  • Loading branch information
facchettos committed Aug 14, 2024
1 parent fb5034c commit f62193f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit f62193f

Please sign in to comment.