Skip to content

Commit

Permalink
feat: show a message if user attempts to use pro / platform features
Browse files Browse the repository at this point in the history
  • Loading branch information
lizardruss committed Apr 12, 2024
1 parent 00ffbb5 commit 80431d3
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
# RUN useradd -u 12345 nonroot
# USER nonroot

ENTRYPOINT ["go", "run", "-mod", "vendor", "cmd/vcluster/main.go"]
ENTRYPOINT ["go", "run", "-mod", "vendor", "cmd/vcluster/main.go", "start"]

# we use alpine for easier debugging
FROM alpine:3.19
Expand Down
15 changes: 10 additions & 5 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,8 @@
"properties": {
"enabled": {
"type": "boolean",
"description": "Enabled defines if the embedded etcd should be used."
"description": "Enabled defines if the embedded etcd should be used.",
"pro": true
},
"migrateFromDeployedEtcd": {
"type": "boolean",
Expand All @@ -1070,7 +1071,8 @@
},
"syncSettings": {
"$ref": "#/$defs/ExperimentalSyncSettings",
"description": "SyncSettings are advanced settings for the syncer controller."
"description": "SyncSettings are advanced settings for the syncer controller.",
"pro": true
},
"genericSync": {
"$ref": "#/$defs/ExperimentalGenericSync",
Expand All @@ -1082,7 +1084,8 @@
},
"isolatedControlPlane": {
"$ref": "#/$defs/ExperimentalIsolatedControlPlane",
"description": "IsolatedControlPlane is a feature to run the vCluster control plane in a different Kubernetes cluster than the workloads themselves."
"description": "IsolatedControlPlane is a feature to run the vCluster control plane in a different Kubernetes cluster than the workloads themselves.",
"pro": true
},
"virtualClusterKubeConfig": {
"$ref": "#/$defs/VirtualClusterKubeConfig",
Expand All @@ -1093,7 +1096,8 @@
"$ref": "#/$defs/DenyRule"
},
"type": "array",
"description": "DenyProxyRequests denies certain requests in the vCluster proxy."
"description": "DenyProxyRequests denies certain requests in the vCluster proxy.",
"pro": true
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -1793,7 +1797,8 @@
"$ref": "#/$defs/ResolveDNS"
},
"type": "array",
"description": "ResolveDNS allows to define extra DNS rules. This only works if embedded coredns is configured."
"description": "ResolveDNS allows to define extra DNS rules. This only works if embedded coredns is configured.",
"pro": true
},
"advanced": {
"$ref": "#/$defs/NetworkingAdvanced",
Expand Down
11 changes: 11 additions & 0 deletions cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"runtime/debug"

"github.com/go-logr/logr"
"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 @@ -51,6 +52,16 @@ func ExecuteStart(ctx context.Context, options *StartOptions) error {
return err
}

if vConfig.Config.IsProFeatureEnabled() {
log, err := logr.FromContext(ctx)
if err != nil {
return err
}

log.Info("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 current namespace
vConfig.ControlPlaneConfig, vConfig.ControlPlaneNamespace, vConfig.ControlPlaneService, vConfig.WorkloadConfig, vConfig.WorkloadNamespace, vConfig.WorkloadService, err = pro.GetRemoteClient(vConfig)
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions cmd/vclusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ func (cmd *CreateCmd) Run(ctx context.Context, args []string) error {
return err
}

err = cmd.prepare(ctx, args[0])
if err != nil {
return err
}

var newExtraValues []string
for _, value := range cmd.Values {
decodedString, err := getBase64DecodedString(value)
Expand Down Expand Up @@ -232,6 +227,16 @@ func (cmd *CreateCmd) Run(ctx context.Context, args []string) error {
}
return err
}

if 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)
}
}

err = cmd.prepare(ctx, args[0])
if err != nil {
return err
}

// resetting this as the base64 encoded strings should be removed and only valid file names should be kept.
Expand Down
4 changes: 4 additions & 0 deletions cmd/vclusterctl/cmd/pro/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pro
import (
"context"
"fmt"
"os"

loftctlflags "github.com/loft-sh/loftctl/v3/cmd/loftctl/flags"
"github.com/loft-sh/loftctl/v3/pkg/start"
Expand Down Expand Up @@ -75,6 +76,9 @@ 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)

// get version to deploy
if cmd.Version == "latest" || cmd.Version == "" {
cmd.Version = procli.MinimumVersionTag
Expand Down
66 changes: 59 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,46 @@ func (c *Config) DecodeYAML(r io.Reader) error {
return nil
}

func (c *Config) IsProFeatureEnabled() bool {
if len(c.Networking.ResolveDNS) > 0 {
return true
}

if len(c.Policies.CentralAdmission.MutatingWebhooks) > 0 {
return true
}

if len(c.Policies.CentralAdmission.ValidatingWebhooks) > 0 {
return true
}

if c.ControlPlane.BackingStore.Etcd.Embedded.Enabled {
return true
}

if c.ControlPlane.HostPathMapper.Central {
return true
}

if c.Experimental.SyncSettings.DisableSync {
return true
}

if c.Experimental.SyncSettings.RewriteKubernetesService {
return true
}

if c.Experimental.IsolatedControlPlane.Enabled {
return true
}

if len(c.Experimental.DenyProxyRequests) > 0 {
return true
}

return false
}

// ExportKubeConfig describes how vCluster should export the vCluster kubeconfig.
type ExportKubeConfig struct {
// Context is the name of the context within the generated kubeconfig to use.
Expand Down Expand Up @@ -300,12 +340,16 @@ type Networking struct {
ReplicateServices ReplicateServices `json:"replicateServices,omitempty"`

// ResolveDNS allows to define extra DNS rules. This only works if embedded coredns is configured.
ResolveDNS []ResolveDNS `json:"resolveDNS,omitempty"`
ResolveDNS []ResolveDNS `json:"resolveDNS,omitempty" product:"pro"`

// Advanced holds advanced network options.
Advanced NetworkingAdvanced `json:"advanced,omitempty"`
}

func (n Networking) JSONSchemaExtend(base *jsonschema.Schema) {
addProToJSONSchema(base, reflect.TypeOf(n))
}

type ReplicateServices struct {
// ToHost defines the services that should get synced from virtual cluster to the host cluster. If services are
// synced to a different namespace than the virtual cluster is in, additional permissions for the other namespace
Expand Down Expand Up @@ -713,12 +757,16 @@ type Etcd struct {

type EtcdEmbedded struct {
// Enabled defines if the embedded etcd should be used.
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled,omitempty" product:"pro"`

// MigrateFromDeployedEtcd signals that vCluster should migrate from the deployed external etcd to embedded etcd.
MigrateFromDeployedEtcd bool `json:"migrateFromDeployedEtcd,omitempty"`
}

func (e EtcdEmbedded) JSONSchemaExtend(base *jsonschema.Schema) {
addProToJSONSchema(base, reflect.TypeOf(e))
}

type EtcdDeploy struct {
// Enabled defines that an external etcd should be deployed.
Enabled bool `json:"enabled,omitempty"`
Expand Down Expand Up @@ -1429,13 +1477,17 @@ type Experimental struct {
MultiNamespaceMode ExperimentalMultiNamespaceMode `json:"multiNamespaceMode,omitempty"`

// IsolatedControlPlane is a feature to run the vCluster control plane in a different Kubernetes cluster than the workloads themselves.
IsolatedControlPlane ExperimentalIsolatedControlPlane `json:"isolatedControlPlane,omitempty"`
IsolatedControlPlane ExperimentalIsolatedControlPlane `json:"isolatedControlPlane,omitempty" product:"pro"`

// VirtualClusterKubeConfig allows you to override distro specifics and specify where vCluster will find the required certificates and vCluster config.
VirtualClusterKubeConfig VirtualClusterKubeConfig `json:"virtualClusterKubeConfig,omitempty"`

// DenyProxyRequests denies certain requests in the vCluster proxy.
DenyProxyRequests []DenyRule `json:"denyProxyRequests,omitempty" pro:"true"`
DenyProxyRequests []DenyRule `json:"denyProxyRequests,omitempty" product:"pro"`
}

func (e Experimental) JSONSchemaExtend(base *jsonschema.Schema) {
addProToJSONSchema(base, reflect.TypeOf(e))
}

type ExperimentalMultiNamespaceMode struct {
Expand All @@ -1448,7 +1500,7 @@ type ExperimentalMultiNamespaceMode struct {

type ExperimentalIsolatedControlPlane struct {
// Enabled specifies if the isolated control plane feature should be enabled.
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled,omitempty" product:"pro"`

// Headless states that Helm should deploy the vCluster in headless mode for the isolated control plane.
Headless bool `json:"headless,omitempty"`
Expand All @@ -1465,10 +1517,10 @@ type ExperimentalIsolatedControlPlane struct {

type ExperimentalSyncSettings struct {
// DisableSync will not sync any resources and disable most control plane functionality.
DisableSync bool `json:"disableSync,omitempty"`
DisableSync bool `json:"disableSync,omitempty" product:"pro"`

// RewriteKubernetesService will rewrite the Kubernetes service to point to the vCluster service if disableSync is enabled
RewriteKubernetesService bool `json:"rewriteKubernetesService,omitempty"`
RewriteKubernetesService bool `json:"rewriteKubernetesService,omitempty" product:"pro"`

// TargetNamespace is the namespace where the workloads should get synced to.
TargetNamespace string `json:"targetNamespace,omitempty"`
Expand Down
Loading

0 comments on commit 80431d3

Please sign in to comment.