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

Enforce reuse-namespace config for creating multiple vClusters in same ns #2538

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 9 additions & 4 deletions cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ func ExecuteStart(ctx context.Context, options *StartOptions) error {
break
}
}
// add a note for setting reuse-namespace config in v0.24 and a deprecation warning for multiple vCluster creation scenario
// add a deprecation warning for multiple vCluster creation scenario
if vClusterExists {
logger.Warnf("Please note that in next release i.e. v0.24, for creating multiple virtual clusters within the " +
"same namespace, it'll be mandatory to set 'reuse-namespace=true' in vcluster config. " +
"This config and the scenario of creating multiple virtual clusters in the same namespace is deprecated and will be removed soon.")
logger.Warnf("Please note that the scenario of creating multiple virtual clusters in the same namespace " +
"and the 'reuseNamespace' config both are deprecated and will be removed soon.")

// throw an error if reuseNamespace config is not set
if !vConfig.Experimental.ReuseNamespace {
return fmt.Errorf("there is already a virtual cluster in namespace %s. To create multiple virtual clusters "+
"within the same namespace, it is mandatory to set 'reuse-namespace=true' in vCluster config", vConfig.ControlPlaneNamespace)
}
}

err = setup.Initialize(ctx, vConfig)
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/create_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.
return err
}

// multiple vCluster creation inside same ns should fail if `reuseNamespace` is not set as true in vCluster config
if reuseNamespace && !vClusterConfig.Experimental.ReuseNamespace {
return fmt.Errorf("there is already a virtual cluster in namespace %s; to create multiple virtual clusters "+
"within the same namespace, please set 'reuse-namespace=true' in vCluster config", cmd.Namespace)
}

if vClusterConfig.Experimental.IsolatedControlPlane.Headless {
cmd.Connect = false
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e_cli/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = ginkgo.Describe("Connect to vCluster", func() {

ginkgo.It("should fail saying the client timeout exceeded", func() {
connectCmd := cmd.NewConnectCmd(&flags.GlobalFlags{})
connectCmd.SetArgs([]string{f.VclusterName})
connectCmd.SetArgs([]string{f.VClusterName})
err := connectCmd.Flags().Set("kube-config", f.VClusterKubeConfigFile.Name())
framework.ExpectNoError(err)
err = connectCmd.Flags().Set("server", "testdomain.org")
Expand Down
Loading