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

fix: vcluster sleep & resume #1254

Merged
merged 2 commits into from
Sep 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/vclusterctl/cmd/app/create/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func validateTemplateOptions(options *Options) error {
if options.KubernetesVersion != "" {
return fmt.Errorf("cannot use --kubernetes-version because the vcluster is using a template")
}
if options.Distro != "" {
if options.Distro != "" && options.Distro != "k3s" {
return fmt.Errorf("cannot use --distro because the vcluster is using a template")
}
if options.ChartName != "vcluster" {
Expand Down
7 changes: 3 additions & 4 deletions cmd/vclusterctl/cmd/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
storagev1 "github.com/loft-sh/api/v3/pkg/apis/storage/v1"
"github.com/loft-sh/api/v3/pkg/product"
proclient "github.com/loft-sh/loftctl/v3/pkg/client"
"github.com/loft-sh/loftctl/v3/pkg/client/naming"
"github.com/loft-sh/loftctl/v3/pkg/config"
loftctlUtil "github.com/loft-sh/loftctl/v3/pkg/util"
"github.com/loft-sh/log"
Expand Down Expand Up @@ -125,7 +124,7 @@ func (cmd *PauseCmd) pauseProVCluster(ctx context.Context, proClient proclient.C

cmd.Log.Infof("Putting virtual cluster %s in project %s to sleep", vCluster.VirtualCluster.Name, vCluster.Project.Name)

virtualClusterInstance, err := managementClient.Loft().ManagementV1().VirtualClusterInstances(naming.ProjectNamespace(vCluster.VirtualCluster.Namespace)).Get(ctx, vCluster.VirtualCluster.Name, metav1.GetOptions{})
virtualClusterInstance, err := managementClient.Loft().ManagementV1().VirtualClusterInstances(vCluster.VirtualCluster.Namespace).Get(ctx, vCluster.VirtualCluster.Name, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -138,15 +137,15 @@ func (cmd *PauseCmd) pauseProVCluster(ctx context.Context, proClient proclient.C
virtualClusterInstance.Annotations[clusterv1.SleepModeForceDurationAnnotation] = strconv.FormatInt(cmd.ForceDuration, 10)
}

_, err = managementClient.Loft().ManagementV1().VirtualClusterInstances(naming.ProjectNamespace(vCluster.VirtualCluster.Namespace)).Update(ctx, virtualClusterInstance, metav1.UpdateOptions{})
_, err = managementClient.Loft().ManagementV1().VirtualClusterInstances(vCluster.VirtualCluster.Namespace).Update(ctx, virtualClusterInstance, metav1.UpdateOptions{})
if err != nil {
return err
}

// wait for sleeping
cmd.Log.Info("Wait until virtual cluster is sleeping...")
err = wait.PollUntilContextTimeout(ctx, time.Second, config.Timeout(), false, func(ctx context.Context) (done bool, err error) {
virtualClusterInstance, err := managementClient.Loft().ManagementV1().VirtualClusterInstances(naming.ProjectNamespace(vCluster.VirtualCluster.Namespace)).Get(ctx, vCluster.VirtualCluster.Name, metav1.GetOptions{})
virtualClusterInstance, err := managementClient.Loft().ManagementV1().VirtualClusterInstances(vCluster.VirtualCluster.Namespace).Get(ctx, vCluster.VirtualCluster.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/vclusterctl/cmd/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"k8s.io/client-go/kubernetes"

proclient "github.com/loft-sh/loftctl/v3/pkg/client"
"github.com/loft-sh/loftctl/v3/pkg/client/naming"
loftctlUtil "github.com/loft-sh/loftctl/v3/pkg/util"
"github.com/loft-sh/loftctl/v3/pkg/vcluster"
"github.com/loft-sh/log"
Expand Down Expand Up @@ -101,7 +100,7 @@ func (cmd *ResumeCmd) resumeProVCluster(ctx context.Context, proClient proclient

cmd.Log.Infof("Waking up virtual cluster %s in project %s", vCluster.VirtualCluster.Name, vCluster.Project.Name)

_, err = vcluster.WaitForVirtualClusterInstance(ctx, managementClient, naming.ProjectNamespace(vCluster.VirtualCluster.Namespace), vCluster.VirtualCluster.Name, true, cmd.Log)
_, err = vcluster.WaitForVirtualClusterInstance(ctx, managementClient, vCluster.VirtualCluster.Namespace, vCluster.VirtualCluster.Name, true, cmd.Log)
if err != nil {
return err
}
Expand Down