From 75e98ff3265133f0deb0a458161f69fb34f4518d Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Mon, 15 Apr 2024 10:43:57 +0200 Subject: [PATCH] refactor: allow skipping pro check --- chart/values.schema.json | 3 +-- cmd/vcluster/cmd/start.go | 3 ++- cmd/vclusterctl/cmd/create.go | 2 +- cmd/vclusterctl/cmd/pro/start.go | 7 +++++-- config/config.go | 35 +++++++++++++++++++++++++++++--- pkg/config/config.go | 14 ------------- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/chart/values.schema.json b/chart/values.schema.json index b8e6cc9f7..797b7ef4c 100755 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -1071,8 +1071,7 @@ }, "syncSettings": { "$ref": "#/$defs/ExperimentalSyncSettings", - "description": "SyncSettings are advanced settings for the syncer controller.", - "pro": true + "description": "SyncSettings are advanced settings for the syncer controller." }, "genericSync": { "$ref": "#/$defs/ExperimentalGenericSync", diff --git a/cmd/vcluster/cmd/start.go b/cmd/vcluster/cmd/start.go index 29e7a23c7..cf5aed03c 100644 --- a/cmd/vcluster/cmd/start.go +++ b/cmd/vcluster/cmd/start.go @@ -7,6 +7,7 @@ import ( "runtime/debug" "github.com/go-logr/logr" + vconfig "github.com/loft-sh/vcluster/config" "github.com/loft-sh/vcluster/pkg/config" "github.com/loft-sh/vcluster/pkg/leaderelection" "github.com/loft-sh/vcluster/pkg/plugin" @@ -52,7 +53,7 @@ func ExecuteStart(ctx context.Context, options *StartOptions) error { return err } - if vConfig.Config.IsProFeatureEnabled() { + if vconfig.ShouldCheckForProFeatures() && vConfig.IsProFeatureEnabled() { log, err := logr.FromContext(ctx) if err != nil { return err diff --git a/cmd/vclusterctl/cmd/create.go b/cmd/vclusterctl/cmd/create.go index 021604bf5..9166cf8ee 100644 --- a/cmd/vclusterctl/cmd/create.go +++ b/cmd/vclusterctl/cmd/create.go @@ -228,7 +228,7 @@ func (cmd *CreateCmd) Run(ctx context.Context, args []string) error { return err } - if cfg.IsProFeatureEnabled() { + if config.ShouldCheckForProFeatures() && cfg.IsProFeatureEnabled() { cmd.log.Warnf("In order to use a Pro feature, please contact us at https://www.vcluster.com/pro-demo or downgrade by running `vcluster upgrade --version v0.19.5`") os.Exit(0) } diff --git a/cmd/vclusterctl/cmd/pro/start.go b/cmd/vclusterctl/cmd/pro/start.go index 983eb4c2e..0f7517703 100644 --- a/cmd/vclusterctl/cmd/pro/start.go +++ b/cmd/vclusterctl/cmd/pro/start.go @@ -11,6 +11,7 @@ import ( "github.com/loft-sh/log/survey" "github.com/loft-sh/log/terminal" "github.com/loft-sh/vcluster/cmd/vclusterctl/cmd/find" + "github.com/loft-sh/vcluster/config" "github.com/loft-sh/vcluster/pkg/procli" "github.com/spf13/cobra" "k8s.io/client-go/tools/clientcmd" @@ -76,8 +77,10 @@ before running this command: } func (cmd *StartCmd) Run(ctx context.Context) error { - cmd.Log.Warnf("In order to use a Pro feature, please contact us at https://www.vcluster.com/pro-demo or downgrade by running `vcluster upgrade --version v0.19.5`") - os.Exit(0) + if config.ShouldCheckForProFeatures() { + cmd.Log.Warnf("In order to use a Pro feature, please contact us at https://www.vcluster.com/pro-demo or downgrade by running `vcluster upgrade --version v0.19.5`") + os.Exit(0) + } // get version to deploy if cmd.Version == "latest" || cmd.Version == "" { diff --git a/config/config.go b/config/config.go index 260c965f6..99b1ef5b7 100644 --- a/config/config.go +++ b/config/config.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "os" "reflect" "regexp" "strings" @@ -101,23 +102,51 @@ func (c *Config) DecodeYAML(r io.Reader) error { return nil } +func (c *Config) Distro() string { + if c.ControlPlane.Distro.K3S.Enabled { + return K3SDistro + } else if c.ControlPlane.Distro.K0S.Enabled { + return K0SDistro + } else if c.ControlPlane.Distro.K8S.Enabled { + return K8SDistro + } else if c.ControlPlane.Distro.EKS.Enabled { + return EKSDistro + } + + return K8SDistro +} + +func ShouldCheckForProFeatures() bool { + return os.Getenv("FORCE_VCLUSTER_PRO") != "true" +} + func (c *Config) IsProFeatureEnabled() bool { if len(c.Networking.ResolveDNS) > 0 { return true } - if len(c.Policies.CentralAdmission.MutatingWebhooks) > 0 { + if c.ControlPlane.CoreDNS.Embedded { return true } - if len(c.Policies.CentralAdmission.ValidatingWebhooks) > 0 { - return true + if c.Distro() == K8SDistro || c.Distro() == EKSDistro { + if c.ControlPlane.BackingStore.Database.External.Enabled { + return true + } } if c.ControlPlane.BackingStore.Etcd.Embedded.Enabled { return true } + if len(c.Policies.CentralAdmission.MutatingWebhooks) > 0 { + return true + } + + if len(c.Policies.CentralAdmission.ValidatingWebhooks) > 0 { + return true + } + if c.ControlPlane.HostPathMapper.Central { return true } diff --git a/pkg/config/config.go b/pkg/config/config.go index b556f2cd5..693743c43 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -57,20 +57,6 @@ func (v VirtualClusterConfig) EmbeddedDatabase() bool { return !v.Config.ControlPlane.BackingStore.Database.External.Enabled && !v.Config.ControlPlane.BackingStore.Etcd.Embedded.Enabled && !v.Config.ControlPlane.BackingStore.Etcd.Deploy.Enabled } -func (v VirtualClusterConfig) Distro() string { - if v.Config.ControlPlane.Distro.K3S.Enabled { - return config.K3SDistro - } else if v.Config.ControlPlane.Distro.K0S.Enabled { - return config.K0SDistro - } else if v.Config.ControlPlane.Distro.K8S.Enabled { - return config.K8SDistro - } else if v.Config.ControlPlane.Distro.EKS.Enabled { - return config.EKSDistro - } - - return config.K8SDistro -} - func (v VirtualClusterConfig) VirtualClusterKubeConfig() config.VirtualClusterKubeConfig { distroConfig := config.VirtualClusterKubeConfig{} switch v.Distro() {