Skip to content

Commit 85dd5c3

Browse files
authored
feat: add cd services kick command (#493)
* add cd services kick command * gen mocks
1 parent efc34ee commit 85dd5c3

9 files changed

Lines changed: 96 additions & 6 deletions

File tree

cmd/plural/cd_services.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ func (p *Plural) cdServiceCommands() []cli.Command {
100100
Action: latestVersion(requireArgs(p.handleDeleteClusterService, []string{"SERVICE_ID"})),
101101
Usage: "delete cluster service",
102102
},
103+
{
104+
Name: "kick",
105+
ArgsUsage: "SERVICE_ID",
106+
Action: latestVersion(requireArgs(p.handleKickClusterService, []string{"SERVICE_ID"})),
107+
Usage: "force sync cluster service",
108+
},
103109
}
104110
}
105111

@@ -432,6 +438,29 @@ func (p *Plural) handleDeleteClusterService(c *cli.Context) error {
432438
return nil
433439
}
434440

441+
func (p *Plural) handleKickClusterService(c *cli.Context) error {
442+
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
443+
return err
444+
}
445+
serviceId, clusterName, serviceName, err := getServiceIdClusterNameServiceName(c.Args().Get(0))
446+
if err != nil {
447+
return err
448+
}
449+
svc, err := p.ConsoleClient.GetClusterService(serviceId, serviceName, clusterName)
450+
if err != nil {
451+
return err
452+
}
453+
if svc == nil {
454+
return fmt.Errorf("Could not find service for %s", c.Args().Get(0))
455+
}
456+
kick, err := p.ConsoleClient.KickClusterService(serviceId, serviceName, clusterName)
457+
if err != nil {
458+
return err
459+
}
460+
utils.Success("Service %s has been sync successfully\n", kick.Name)
461+
return nil
462+
}
463+
435464
type ServiceDeploymentAttributesConfiguration struct {
436465
Configuration []*gqlclient.ConfigAttributes
437466
}

go.mod

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

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
14241424
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
14251425
github.com/pluralsh/cluster-api-migration v0.2.15 h1:TIfusD+wnhZTGmwNfIlKlKJOT2dE3rUaZawDJw98GjY=
14261426
github.com/pluralsh/cluster-api-migration v0.2.15/go.mod h1:J6lEvC/70KouikX16mE331cxc3y3sBwtmfHGwZqu06w=
1427-
github.com/pluralsh/console-client-go v0.0.92 h1:PMSF05Zp5gLejeEWXbwe17CfXNLJ55dGlFPAAVucfCM=
1428-
github.com/pluralsh/console-client-go v0.0.92/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
1427+
github.com/pluralsh/console-client-go v0.0.97 h1:X00oY8E19ji2ynkOaEHtopHQ8IIe8kHK65SDFukQb8Y=
1428+
github.com/pluralsh/console-client-go v0.0.97/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
14291429
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
14301430
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
14311431
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=

pkg/console/console.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type ConsoleClient interface {
4242
MyCluster() (*consoleclient.MyCluster, error)
4343
SaveServiceContext(name string, attributes consoleclient.ServiceContextAttributes) (*consoleclient.ServiceContextFragment, error)
4444
GetServiceContext(name string) (*consoleclient.ServiceContextFragment, error)
45+
KickClusterService(serviceId, serviceName, clusterName *string) (*consoleclient.ServiceDeploymentExtended, error)
4546
}
4647

4748
type authedTransport struct {

pkg/console/describe.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ func DescribeService(service *consoleclient.ServiceDeploymentExtended) (string,
103103
if service.DryRun != nil {
104104
dryRun = *service.DryRun
105105
}
106+
templated := true
107+
if service.Templated != nil {
108+
templated = *service.Templated
109+
}
106110
w.Write(LEVEL_0, "Dry run:\t%v\n", dryRun)
111+
w.Write(LEVEL_0, "Templated:\t%v\n", templated)
107112
w.Write(LEVEL_0, "Git:\t\n")
108113
w.Write(LEVEL_1, "Ref:\t%s\n", service.Git.Ref)
109114
w.Write(LEVEL_1, "Folder:\t%s\n", service.Git.Folder)

pkg/console/services.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,28 @@ func (c *consoleClient) DeleteClusterService(serviceId string) (*gqlclient.Delet
136136

137137
return result, nil
138138
}
139+
140+
func (c *consoleClient) KickClusterService(serviceId, serviceName, clusterName *string) (*gqlclient.ServiceDeploymentExtended, error) {
141+
if serviceId == nil && serviceName == nil && clusterName == nil {
142+
return nil, fmt.Errorf("serviceId, serviceName and clusterName can not be null")
143+
}
144+
if serviceId != nil {
145+
result, err := c.client.KickService(c.ctx, *serviceId)
146+
if err != nil {
147+
return nil, api.GetErrorResponse(err, "KickService")
148+
}
149+
if result == nil {
150+
return nil, fmt.Errorf("the result from KickService is null")
151+
}
152+
return result.KickService, nil
153+
}
154+
result, err := c.client.KickServiceByHandle(c.ctx, *clusterName, *serviceName)
155+
if err != nil {
156+
return nil, api.GetErrorResponse(err, "KickServiceByHandle")
157+
}
158+
if result == nil {
159+
return nil, fmt.Errorf("the result from KickServiceByHandle is null")
160+
}
161+
162+
return result.KickService, nil
163+
}

pkg/test/mocks/Client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/test/mocks/ConsoleClient.go

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/test/mocks/Kube.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)