From 9180228048fafecf8add7797cae03776a438c595 Mon Sep 17 00:00:00 2001 From: "abhay.tomar" Date: Tue, 25 Feb 2025 19:46:13 +0530 Subject: [PATCH 1/3] enforce reuse-ns config --- cmd/vcluster/cmd/start.go | 13 +++++++++---- pkg/cli/create_helm.go | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/vcluster/cmd/start.go b/cmd/vcluster/cmd/start.go index a52118759..3ed02c7f7 100644 --- a/cmd/vcluster/cmd/start.go +++ b/cmd/vcluster/cmd/start.go @@ -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) diff --git a/pkg/cli/create_helm.go b/pkg/cli/create_helm.go index b26593416..df9b024d5 100644 --- a/pkg/cli/create_helm.go +++ b/pkg/cli/create_helm.go @@ -142,7 +142,8 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags. 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) + 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 the 'reuse-namespace' flag as true", cmd.Namespace) } } } else { From 3f644aba4c1672553d085c5a2afdea632296793a Mon Sep 17 00:00:00 2001 From: "abhay.tomar" Date: Tue, 25 Feb 2025 20:06:44 +0530 Subject: [PATCH 2/3] minor update in framework's field name to align with latest changes --- test/e2e_cli/connect/connect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e_cli/connect/connect.go b/test/e2e_cli/connect/connect.go index dd7f8b7ef..0e0f9d272 100644 --- a/test/e2e_cli/connect/connect.go +++ b/test/e2e_cli/connect/connect.go @@ -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") From 468564f0ef862c335bb4ab85a2bef087794555c4 Mon Sep 17 00:00:00 2001 From: "abhay.tomar" Date: Tue, 25 Feb 2025 22:11:45 +0530 Subject: [PATCH 3/3] enforce config for creation using CLI --- cmd/vclusterctl/cmd/create.go | 2 +- pkg/cli/create_helm.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/vclusterctl/cmd/create.go b/cmd/vclusterctl/cmd/create.go index 50ececeac..b0bdec398 100644 --- a/cmd/vclusterctl/cmd/create.go +++ b/cmd/vclusterctl/cmd/create.go @@ -68,7 +68,7 @@ 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 - _ = cobraCmd.Flags().MarkDeprecated("reuse-namespace", "creation of multiple virtual clusters within the same namespace will be deprecated soon.") + _ = cobraCmd.Flags().MarkDeprecated("reuse-namespace", "creation of multiple virtual clusters within the same namespace is deprecated.") create.AddCommonFlags(cobraCmd, &cmd.CreateOptions) create.AddHelmFlags(cobraCmd, &cmd.CreateOptions) diff --git a/pkg/cli/create_helm.go b/pkg/cli/create_helm.go index df9b024d5..57c88f7c6 100644 --- a/pkg/cli/create_helm.go +++ b/pkg/cli/create_helm.go @@ -142,8 +142,7 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags. 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. To create multiple virtual clusters "+ - "within the same namespace, it is mandatory to set the 'reuse-namespace' flag as true", cmd.Namespace) + return fmt.Errorf("there is already a virtual cluster in namespace %s", cmd.Namespace) } } } else { @@ -290,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 }