Skip to content

Commit 47cc941

Browse files
committed
bugfix: disallow users from creating a vCluster in the platform namespace
1 parent 90f9dbc commit 47cc941

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

chart/templates/service.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{{- if .Values.controlPlane.service.enabled }}
1+
{{- $platform_svc_exists := lookup "v1" "Service" .Release.Namespace "loft" }}
2+
{{- if $platform_svc_exists }}
3+
{{- fail (printf "a vCluster platform installation exists in the namespace '%s'. Aborting install" .Release.Namespace) }}
4+
{{- else if .Values.controlPlane.service.enabled }}
25
apiVersion: v1
36
kind: Service
47
metadata:

pkg/cli/create_helm.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/loft-sh/vcluster/pkg/embed"
3434
"github.com/loft-sh/vcluster/pkg/helm"
3535
"github.com/loft-sh/vcluster/pkg/platform"
36+
platformclihelper "github.com/loft-sh/vcluster/pkg/platform/clihelper"
3637
"github.com/loft-sh/vcluster/pkg/snapshot"
3738
"github.com/loft-sh/vcluster/pkg/snapshot/pod"
3839
"github.com/loft-sh/vcluster/pkg/telemetry"
@@ -164,6 +165,13 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.
164165
return fmt.Errorf("get current helm release: %w", err)
165166
}
166167

168+
_, err = cmd.kubeClient.CoreV1().Services(globalFlags.Namespace).Get(ctx, platformclihelper.DefaultPlatformServiceName, metav1.GetOptions{})
169+
if err == nil {
170+
return fmt.Errorf("a vCluster platform installation exists in the namespace '%s'. Aborting install", globalFlags.Namespace)
171+
} else if !kerrors.IsNotFound(err) {
172+
return fmt.Errorf("get platform service: %w", err)
173+
}
174+
167175
// check if vcluster already exists
168176
if !cmd.Upgrade {
169177
if isVClusterDeployed(release) {

pkg/platform/clihelper/clihelper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const LoftRouterDomainSecret = "loft-router-domain"
5959

6060
const DefaultPlatformNamespace = "vcluster-platform"
6161

62+
const DefaultPlatformServiceName = "loft"
63+
6264
const defaultTimeout = 10 * time.Minute
6365

6466
const timeoutEnvVariable = "LOFT_TIMEOUT"

0 commit comments

Comments
 (0)