Skip to content

Commit 3233f98

Browse files
Add reinstall command (#481)
Found this to be useful when testing a lot with k3s where you spin clusters up/down all the time.
1 parent 98d50a1 commit 3233f98

File tree

7 files changed

+39
-5
lines changed

7 files changed

+39
-5
lines changed

cmd/plural/cd_clusters.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func (p *Plural) cdClusterCommands() []cli.Command {
103103
},
104104
},
105105
},
106+
{
107+
Name: "reinstall",
108+
Action: latestVersion(p.handleClusterReinstall),
109+
Usage: "reinstalls the deployment operator into a cluster",
110+
},
106111
}
107112
}
108113

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

384+
func (p *Plural) handleClusterReinstall(c *cli.Context) error {
385+
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
386+
return err
387+
}
388+
389+
deployToken, err := p.ConsoleClient.GetDeployToken(getIdAndName(c.Args().Get(0)))
390+
if err != nil {
391+
return err
392+
}
393+
394+
url := fmt.Sprintf("%s/ext/gql", p.ConsoleClient.Url())
395+
return p.doInstallOperator(url, deployToken)
396+
}
397+
379398
func (p *Plural) handleClusterBootstrap(c *cli.Context) error {
380399
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
381400
return err

cmd/plural/cd_pipelines.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ func (p *Plural) handleCreatePipeline(c *cli.Context) error {
6060
return err
6161
}
6262

63-
utils.Success("Pipeline %s created successfully", pipe.Name)
63+
utils.Success("Pipeline %s created successfully\n", pipe.Name)
6464
return nil
6565
}

cmd/plural/cd_services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error {
133133
Name: name,
134134
Namespace: namespace,
135135
Version: &v,
136-
RepositoryID: repoId,
136+
RepositoryID: lo.ToPtr(repoId),
137137
Git: &gqlclient.GitRefAttributes{
138138
Ref: gitRef,
139139
Folder: gitFolder,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ require (
5454
github.com/packethost/packngo v0.29.0
5555
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
5656
github.com/pluralsh/cluster-api-migration v0.2.15
57-
github.com/pluralsh/console-client-go v0.0.51
57+
github.com/pluralsh/console-client-go v0.0.60
5858
github.com/pluralsh/gqlclient v1.11.0
5959
github.com/pluralsh/plural-operator v0.5.5
6060
github.com/pluralsh/polly v0.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,8 +1423,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
14231423
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
14241424
github.com/pluralsh/cluster-api-migration v0.2.15 h1:TIfusD+wnhZTGmwNfIlKlKJOT2dE3rUaZawDJw98GjY=
14251425
github.com/pluralsh/cluster-api-migration v0.2.15/go.mod h1:J6lEvC/70KouikX16mE331cxc3y3sBwtmfHGwZqu06w=
1426-
github.com/pluralsh/console-client-go v0.0.51 h1:QjPoPWVlqjW2KebgAEV8Cx48yS9cgrDWXmyqnTeoqmA=
1427-
github.com/pluralsh/console-client-go v0.0.51/go.mod h1:u/RjzXE3wtl3L6wiWxwhQHSpxFX46+EYvpkss2mALN4=
1426+
github.com/pluralsh/console-client-go v0.0.60 h1:hvZV5WsXEN/bd9leid56FxVXXqCOhOdczQd7CC5qri0=
1427+
github.com/pluralsh/console-client-go v0.0.60/go.mod h1:u/RjzXE3wtl3L6wiWxwhQHSpxFX46+EYvpkss2mALN4=
14281428
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
14291429
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
14301430
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=

pkg/console/clusters.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
consoleclient "github.com/pluralsh/console-client-go"
77
"github.com/pluralsh/plural-cli/pkg/api"
8+
"github.com/samber/lo"
89
)
910

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

40+
func (c *consoleClient) GetDeployToken(clusterId, clusterName *string) (string, error) {
41+
res, err := c.client.GetClusterWithToken(c.ctx, clusterId, clusterName)
42+
if err != nil {
43+
return "", err
44+
}
45+
46+
if res == nil {
47+
return "", fmt.Errorf("cluster not found")
48+
}
49+
50+
return lo.FromPtr(res.Cluster.DeployToken), nil
51+
}
52+
3953
func (c *consoleClient) UpdateCluster(id string, attr consoleclient.ClusterUpdateAttributes) (*consoleclient.UpdateCluster, error) {
4054

4155
result, err := c.client.UpdateCluster(c.ctx, id, attr)

pkg/console/console.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ConsoleClient interface {
2020
Token() string
2121
ListClusters() (*consoleclient.ListClusters, error)
2222
GetCluster(clusterId, clusterName *string) (*consoleclient.ClusterFragment, error)
23+
GetDeployToken(clusterId, clusterName *string) (string, error)
2324
UpdateCluster(id string, attr consoleclient.ClusterUpdateAttributes) (*consoleclient.UpdateCluster, error)
2425
DeleteCluster(id string) error
2526
DetachCluster(id string) error

0 commit comments

Comments
 (0)