Skip to content

Commit

Permalink
Merge pull request #1902 from lizardruss/ENG-3890
Browse files Browse the repository at this point in the history
No agent found with Sleep Mode configured: vCluster logs, CLI output
  • Loading branch information
FabianKramm authored Jul 4, 2024
2 parents 25621b8 + 87b8c1b commit ceb7dec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
26 changes: 26 additions & 0 deletions pkg/cli/create_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/delete_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/pause_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/resume_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit ceb7dec

Please sign in to comment.