Skip to content

Commit

Permalink
refactor: allow skipping pro check
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Apr 15, 2024
1 parent 80431d3 commit 75e98ff
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
3 changes: 1 addition & 2 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/vclusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/vclusterctl/cmd/pro/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 == "" {
Expand Down
35 changes: 32 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"os"
"reflect"
"regexp"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 75e98ff

Please sign in to comment.