Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No agent found with Sleep Mode configured: vCluster logs, CLI output #1902

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +377 to +384
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we narrow this down by namespace?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since people can deploy loft in any namespace, I'm not sure if this would be a good idea

}

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
Loading