diff --git a/pkg/cli/create_helm.go b/pkg/cli/create_helm.go index f6f8618e4..b4e074593 100644 --- a/pkg/cli/create_helm.go +++ b/pkg/cli/create_helm.go @@ -268,6 +268,14 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags. cmd.Connect = false } + if isSleepModeConfigured(vClusterConfig) { + if agentDeployed, err := cmd.isLoftAgentDeployed(ctx); err != nil { + return fmt.Errorf("is agent deployed: %w", err) + } else if !agentDeployed { + return fmt.Errorf("sleep mode is configured but requires an agent to be installed on the host cluster. To install the agent using the vCluster CLI, run: vcluster platform add cluster") + } + } + if isVClusterDeployed(release) { // While certain backing store changes are allowed we prohibit changes to another distro. if err := config.ValidateChanges(currentVClusterConfig, vClusterConfig); err != nil { @@ -365,6 +373,24 @@ func (cmd *createHelm) addVCluster(ctx context.Context, vClusterConfig *config.C return nil } +func (cmd *createHelm) isLoftAgentDeployed(ctx context.Context) (bool, error) { + podList, err := cmd.kubeClient.CoreV1().Pods("").List(ctx, metav1.ListOptions{ + LabelSelector: "app=loft", + }) + if err != nil && !kerrors.IsNotFound(err) { + return false, err + } + + return len(podList.Items) > 0, nil +} + +func isSleepModeConfigured(vClusterConfig *config.Config) bool { + if vClusterConfig == nil || vClusterConfig.External == nil || vClusterConfig.External["platform"] == nil { + return false + } + return vClusterConfig.External["platform"]["autoSleep"] != nil || vClusterConfig.External["platform"]["autoDelete"] != nil +} + func isVClusterDeployed(release *helm.Release) bool { return release != nil && release.Chart != nil && diff --git a/pkg/cli/delete_platform.go b/pkg/cli/delete_platform.go index ce9d44851..11cffb063 100644 --- a/pkg/cli/delete_platform.go +++ b/pkg/cli/delete_platform.go @@ -24,7 +24,7 @@ func DeletePlatform(ctx context.Context, options *DeleteOptions, config *config. vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log) if err != nil { return err - } else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.NetworkPeer { + } else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.External { return fmt.Errorf("cannot delete a virtual cluster that was created via helm, please run 'vcluster use driver helm' or use the '--driver helm' flag") } diff --git a/pkg/cli/pause_platform.go b/pkg/cli/pause_platform.go index 454a84ab1..e5bf54856 100644 --- a/pkg/cli/pause_platform.go +++ b/pkg/cli/pause_platform.go @@ -25,7 +25,7 @@ func PausePlatform(ctx context.Context, options *PauseOptions, cfg *cliconfig.CL vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log) if err != nil { return err - } else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.NetworkPeer { + } else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.External { return fmt.Errorf("cannot pause a virtual cluster that was created via helm, please run 'vcluster use driver helm' or use the '--driver helm' flag") } diff --git a/pkg/cli/resume_platform.go b/pkg/cli/resume_platform.go index 373f6f1e8..0dc1c493a 100644 --- a/pkg/cli/resume_platform.go +++ b/pkg/cli/resume_platform.go @@ -18,7 +18,7 @@ func ResumePlatform(ctx context.Context, options *ResumeOptions, config *config. vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log) if err != nil { return err - } else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.NetworkPeer { + } else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.External { return fmt.Errorf("cannot resume a virtual cluster that was created via helm, please run 'vcluster use driver helm' or use the '--driver helm' flag") }