Skip to content

Commit

Permalink
Add reinstall command (#481)
Browse files Browse the repository at this point in the history
Found this to be useful when testing a lot with k3s where you spin clusters up/down all the time.
  • Loading branch information
michaeljguarino authored Dec 21, 2023
1 parent 98d50a1 commit 3233f98
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
19 changes: 19 additions & 0 deletions cmd/plural/cd_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (p *Plural) cdClusterCommands() []cli.Command {
},
},
},
{
Name: "reinstall",
Action: latestVersion(p.handleClusterReinstall),
Usage: "reinstalls the deployment operator into a cluster",
},
}
}

Expand Down Expand Up @@ -376,6 +381,20 @@ func (p *Plural) handleCreateProvider(existingProviders []string) (*gqlclient.Cr
return clusterProv, nil
}

func (p *Plural) handleClusterReinstall(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}

deployToken, err := p.ConsoleClient.GetDeployToken(getIdAndName(c.Args().Get(0)))
if err != nil {
return err
}

url := fmt.Sprintf("%s/ext/gql", p.ConsoleClient.Url())
return p.doInstallOperator(url, deployToken)
}

func (p *Plural) handleClusterBootstrap(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/plural/cd_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ func (p *Plural) handleCreatePipeline(c *cli.Context) error {
return err
}

utils.Success("Pipeline %s created successfully", pipe.Name)
utils.Success("Pipeline %s created successfully\n", pipe.Name)
return nil
}
2 changes: 1 addition & 1 deletion cmd/plural/cd_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error {
Name: name,
Namespace: namespace,
Version: &v,
RepositoryID: repoId,
RepositoryID: lo.ToPtr(repoId),
Git: &gqlclient.GitRefAttributes{
Ref: gitRef,
Folder: gitFolder,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/packethost/packngo v0.29.0
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pluralsh/cluster-api-migration v0.2.15
github.com/pluralsh/console-client-go v0.0.51
github.com/pluralsh/console-client-go v0.0.60
github.com/pluralsh/gqlclient v1.11.0
github.com/pluralsh/plural-operator v0.5.5
github.com/pluralsh/polly v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pluralsh/cluster-api-migration v0.2.15 h1:TIfusD+wnhZTGmwNfIlKlKJOT2dE3rUaZawDJw98GjY=
github.com/pluralsh/cluster-api-migration v0.2.15/go.mod h1:J6lEvC/70KouikX16mE331cxc3y3sBwtmfHGwZqu06w=
github.com/pluralsh/console-client-go v0.0.51 h1:QjPoPWVlqjW2KebgAEV8Cx48yS9cgrDWXmyqnTeoqmA=
github.com/pluralsh/console-client-go v0.0.51/go.mod h1:u/RjzXE3wtl3L6wiWxwhQHSpxFX46+EYvpkss2mALN4=
github.com/pluralsh/console-client-go v0.0.60 h1:hvZV5WsXEN/bd9leid56FxVXXqCOhOdczQd7CC5qri0=
github.com/pluralsh/console-client-go v0.0.60/go.mod h1:u/RjzXE3wtl3L6wiWxwhQHSpxFX46+EYvpkss2mALN4=
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=
Expand Down
14 changes: 14 additions & 0 deletions pkg/console/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

consoleclient "github.com/pluralsh/console-client-go"
"github.com/pluralsh/plural-cli/pkg/api"
"github.com/samber/lo"
)

func (c *consoleClient) ListClusters() (*consoleclient.ListClusters, error) {
Expand Down Expand Up @@ -36,6 +37,19 @@ func (c *consoleClient) GetCluster(clusterId, clusterName *string) (*consoleclie
return result.Cluster, nil
}

func (c *consoleClient) GetDeployToken(clusterId, clusterName *string) (string, error) {
res, err := c.client.GetClusterWithToken(c.ctx, clusterId, clusterName)
if err != nil {
return "", err
}

if res == nil {
return "", fmt.Errorf("cluster not found")
}

return lo.FromPtr(res.Cluster.DeployToken), nil
}

func (c *consoleClient) UpdateCluster(id string, attr consoleclient.ClusterUpdateAttributes) (*consoleclient.UpdateCluster, error) {

result, err := c.client.UpdateCluster(c.ctx, id, attr)
Expand Down
1 change: 1 addition & 0 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ConsoleClient interface {
Token() string
ListClusters() (*consoleclient.ListClusters, error)
GetCluster(clusterId, clusterName *string) (*consoleclient.ClusterFragment, error)
GetDeployToken(clusterId, clusterName *string) (string, error)
UpdateCluster(id string, attr consoleclient.ClusterUpdateAttributes) (*consoleclient.UpdateCluster, error)
DeleteCluster(id string) error
DetachCluster(id string) error
Expand Down

0 comments on commit 3233f98

Please sign in to comment.