Skip to content

Commit

Permalink
Merge pull request #1744 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: handle helm created vclusters correctly
  • Loading branch information
FabianKramm authored May 6, 2024
2 parents a0a6ff0 + e77b550 commit 5dbb3aa
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/loft-sh/agentapi/v3 v3.4.6-beta.0
github.com/loft-sh/analytics-client v0.0.0-20240219162240-2f4c64b2494e
github.com/loft-sh/api/v3 v3.5.0-alpha.1.0.20240426152201-dfdce426ab92
github.com/loft-sh/loftctl/v3 v3.5.0-alpha.1.0.20240430082516-88fe061dbac1
github.com/loft-sh/loftctl/v3 v3.5.0-alpha.2.0.20240506133909-6e7c7415ee54
github.com/loft-sh/utils v0.0.29
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/mitchellh/go-homedir v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ github.com/loft-sh/apiserver v0.0.0-20240129130254-7b9a55ab1744 h1:1Yhs86ugpnEse
github.com/loft-sh/apiserver v0.0.0-20240129130254-7b9a55ab1744/go.mod h1:/QBF5drEoeQ0pggzT6q29+cyirRg5/MOJCq39ghku+8=
github.com/loft-sh/jspolicy v0.2.2 h1:+7QqVumYm225mSJsGOjnbCGYzh9XyKYQab6FgLiHYJU=
github.com/loft-sh/jspolicy v0.2.2/go.mod h1:kbXD1CS17Ie9dqcq5iXrOhpSLESkmQpy4+F80YXOfUM=
github.com/loft-sh/loftctl/v3 v3.5.0-alpha.1.0.20240430082516-88fe061dbac1 h1:ecEb6OmBBs1eF6zxSIH1k+rEaWkqCjuApgbUCkAs220=
github.com/loft-sh/loftctl/v3 v3.5.0-alpha.1.0.20240430082516-88fe061dbac1/go.mod h1:IUXEhtAFeJj2GED0yyePY3ybpjOs8ZJ4pvkPIJ2/g7U=
github.com/loft-sh/loftctl/v3 v3.5.0-alpha.2.0.20240506133909-6e7c7415ee54 h1:9aezsY+IjdtcWJVlFbFl8MOBcbqOHKyyxJQuEEhkB8A=
github.com/loft-sh/loftctl/v3 v3.5.0-alpha.2.0.20240506133909-6e7c7415ee54/go.mod h1:IUXEhtAFeJj2GED0yyePY3ybpjOs8ZJ4pvkPIJ2/g7U=
github.com/loft-sh/log v0.0.0-20240219160058-26d83ffb46ac h1:Gz/7Lb7WgdgIv+KJz87ORA1zvQW52tUqKPGyunlp4dQ=
github.com/loft-sh/log v0.0.0-20240219160058-26d83ffb46ac/go.mod h1:YImeRjXH34Yf5E79T7UHBQpDZl9fIaaFRgyZ/bkY+UQ=
github.com/loft-sh/utils v0.0.29 h1:P/MObccXToAZy2QoJSQDJ+OJx1qHitpFHEVj3QBSNJs=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/connect_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ConnectPlatform(ctx context.Context, options *ConnectOptions, globalFlags *
// retrieve the vcluster
vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log)
if err != nil {
return err
return fmt.Errorf("get platform vcluster %s: %w", vClusterName, err)
}

// create connect platform command
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/create_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func CreatePlatform(ctx context.Context, options *CreateOptions, globalFlags *fl
// if the virtual cluster already exists and flag is not set, we terminate
if !options.Upgrade && virtualClusterInstance != nil {
return fmt.Errorf("virtual cluster %s already exists in project %s", virtualClusterName, options.Project)
} else if virtualClusterInstance != nil && virtualClusterInstance.Spec.NetworkPeer {
return fmt.Errorf("cannot upgrade a virtual cluster that was created via helm, please run 'vcluster use manager helm' or use the '--manager helm' flag")
}

// should create via template
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/delete_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func DeletePlatform(ctx context.Context, options *DeleteOptions, vClusterName st
vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log)
if err != nil {
return err
} else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.NetworkPeer {
return fmt.Errorf("cannot delete a virtual cluster that was created via helm, please run 'vcluster use manager helm' or use the '--manager helm' flag")
}

managementClient, err := platformClient.Management()
Expand Down
16 changes: 14 additions & 2 deletions pkg/cli/list_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,27 @@ func proToVClusters(vClusters []platform.VirtualClusterInstanceProject, currentC
status = "Pending"
}

version := ""
if vCluster.VirtualCluster.Status.VirtualCluster != nil && vCluster.VirtualCluster.Status.VirtualCluster.HelmRelease.Chart.Version != "" {
version = vCluster.VirtualCluster.Status.VirtualCluster.HelmRelease.Chart.Version
} else if vCluster.VirtualCluster.Spec.Template != nil && vCluster.VirtualCluster.Spec.Template.HelmRelease.Chart.Version != "" {
version = vCluster.VirtualCluster.Spec.Template.HelmRelease.Chart.Version
}

name := vCluster.VirtualCluster.Spec.ClusterRef.VirtualCluster
if vCluster.VirtualCluster.Spec.NetworkPeer {
name = vCluster.VirtualCluster.Name
}

connected := strings.HasPrefix(currentContext, "vcluster-platform_"+vCluster.VirtualCluster.Name+"_"+vCluster.Project.Name)
vClusterOutput := ListVCluster{
Name: vCluster.VirtualCluster.Spec.ClusterRef.VirtualCluster,
Name: name,
Namespace: vCluster.VirtualCluster.Spec.ClusterRef.Namespace,
Connected: connected,
Created: vCluster.VirtualCluster.CreationTimestamp.Time,
AgeSeconds: int(time.Since(vCluster.VirtualCluster.CreationTimestamp.Time).Round(time.Second).Seconds()),
Status: status,
Version: vCluster.VirtualCluster.Status.VirtualCluster.HelmRelease.Chart.Version,
Version: version,
}
output = append(output, vClusterOutput)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/pause_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func PausePlatform(ctx context.Context, options *PauseOptions, vClusterName stri
vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log)
if err != nil {
return err
} else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.NetworkPeer {
return fmt.Errorf("cannot pause a virtual cluster that was created via helm, please run 'vcluster use manager helm' or use the '--manager helm' flag")
}

managementClient, err := platformClient.Management()
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/resume_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"fmt"

"github.com/loft-sh/loftctl/v3/pkg/vcluster"
"github.com/loft-sh/log"
Expand All @@ -18,6 +19,8 @@ func ResumePlatform(ctx context.Context, options *ResumeOptions, vClusterName st
vCluster, err := find.GetPlatformVCluster(ctx, platformClient, vClusterName, options.Project, log)
if err != nil {
return err
} else if vCluster.VirtualCluster != nil && vCluster.VirtualCluster.Spec.NetworkPeer {
return fmt.Errorf("cannot resume a virtual cluster that was created via helm, please run 'vcluster use manager helm' or use the '--manager helm' flag")
}

managementClient, err := platformClient.Management()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ github.com/loft-sh/apiserver/pkg/builders
# github.com/loft-sh/jspolicy v0.2.2
## explicit; go 1.16
github.com/loft-sh/jspolicy/pkg/apis/policy/v1beta1
# github.com/loft-sh/loftctl/v3 v3.5.0-alpha.1.0.20240430082516-88fe061dbac1
# github.com/loft-sh/loftctl/v3 v3.5.0-alpha.2.0.20240506133909-6e7c7415ee54
## explicit; go 1.22.2
github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd
github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd/connect
Expand Down

0 comments on commit 5dbb3aa

Please sign in to comment.