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

feat: add cd services kick command #493

Merged
merged 2 commits into from
Feb 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cmd/plural/cd_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func (p *Plural) cdServiceCommands() []cli.Command {
Action: latestVersion(requireArgs(p.handleDeleteClusterService, []string{"SERVICE_ID"})),
Usage: "delete cluster service",
},
{
Name: "kick",
ArgsUsage: "SERVICE_ID",
Action: latestVersion(requireArgs(p.handleKickClusterService, []string{"SERVICE_ID"})),
Usage: "force sync cluster service",
},
}
}

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

func (p *Plural) handleKickClusterService(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}
serviceId, clusterName, serviceName, err := getServiceIdClusterNameServiceName(c.Args().Get(0))
if err != nil {
return err
}
svc, err := p.ConsoleClient.GetClusterService(serviceId, serviceName, clusterName)
if err != nil {
return err
}
if svc == nil {
return fmt.Errorf("Could not find service for %s", c.Args().Get(0))
}
kick, err := p.ConsoleClient.KickClusterService(serviceId, serviceName, clusterName)
if err != nil {
return err
}
utils.Success("Service %s has been sync successfully\n", kick.Name)
return nil
}

type ServiceDeploymentAttributesConfiguration struct {
Configuration []*gqlclient.ConfigAttributes
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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.92
github.com/pluralsh/console-client-go v0.0.97
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 @@ -1424,8 +1424,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.92 h1:PMSF05Zp5gLejeEWXbwe17CfXNLJ55dGlFPAAVucfCM=
github.com/pluralsh/console-client-go v0.0.92/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.0.97 h1:X00oY8E19ji2ynkOaEHtopHQ8IIe8kHK65SDFukQb8Y=
github.com/pluralsh/console-client-go v0.0.97/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
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
1 change: 1 addition & 0 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ConsoleClient interface {
MyCluster() (*consoleclient.MyCluster, error)
SaveServiceContext(name string, attributes consoleclient.ServiceContextAttributes) (*consoleclient.ServiceContextFragment, error)
GetServiceContext(name string) (*consoleclient.ServiceContextFragment, error)
KickClusterService(serviceId, serviceName, clusterName *string) (*consoleclient.ServiceDeploymentExtended, error)
}

type authedTransport struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/console/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ func DescribeService(service *consoleclient.ServiceDeploymentExtended) (string,
if service.DryRun != nil {
dryRun = *service.DryRun
}
templated := true
if service.Templated != nil {
templated = *service.Templated
}
w.Write(LEVEL_0, "Dry run:\t%v\n", dryRun)
w.Write(LEVEL_0, "Templated:\t%v\n", templated)
w.Write(LEVEL_0, "Git:\t\n")
w.Write(LEVEL_1, "Ref:\t%s\n", service.Git.Ref)
w.Write(LEVEL_1, "Folder:\t%s\n", service.Git.Folder)
Expand Down
25 changes: 25 additions & 0 deletions pkg/console/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,28 @@ func (c *consoleClient) DeleteClusterService(serviceId string) (*gqlclient.Delet

return result, nil
}

func (c *consoleClient) KickClusterService(serviceId, serviceName, clusterName *string) (*gqlclient.ServiceDeploymentExtended, error) {
if serviceId == nil && serviceName == nil && clusterName == nil {
return nil, fmt.Errorf("serviceId, serviceName and clusterName can not be null")
}
if serviceId != nil {
result, err := c.client.KickService(c.ctx, *serviceId)
if err != nil {
return nil, api.GetErrorResponse(err, "KickService")
}
if result == nil {
return nil, fmt.Errorf("the result from KickService is null")
}
return result.KickService, nil
}
result, err := c.client.KickServiceByHandle(c.ctx, *clusterName, *serviceName)
if err != nil {
return nil, api.GetErrorResponse(err, "KickServiceByHandle")
}
if result == nil {
return nil, fmt.Errorf("the result from KickServiceByHandle is null")
}

return result.KickService, nil
}
2 changes: 1 addition & 1 deletion pkg/test/mocks/Client.go

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

32 changes: 31 additions & 1 deletion pkg/test/mocks/ConsoleClient.go

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

2 changes: 1 addition & 1 deletion pkg/test/mocks/Kube.go

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

Loading