diff --git a/cmd/plural/cd_services.go b/cmd/plural/cd_services.go index 59301b91..0c8ffede 100644 --- a/cmd/plural/cd_services.go +++ b/cmd/plural/cd_services.go @@ -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", + }, } } @@ -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 } diff --git a/go.mod b/go.mod index 8b244351..00f523c0 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index abcb6e63..b87fba8d 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/console/console.go b/pkg/console/console.go index c656834c..02dca33e 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -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 { diff --git a/pkg/console/describe.go b/pkg/console/describe.go index b02caa9b..e477bb72 100644 --- a/pkg/console/describe.go +++ b/pkg/console/describe.go @@ -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) diff --git a/pkg/console/services.go b/pkg/console/services.go index fe8401f0..7729f8f7 100644 --- a/pkg/console/services.go +++ b/pkg/console/services.go @@ -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 +} diff --git a/pkg/test/mocks/Client.go b/pkg/test/mocks/Client.go index c8d420a7..afd7d104 100644 --- a/pkg/test/mocks/Client.go +++ b/pkg/test/mocks/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.41.0. DO NOT EDIT. +// Code generated by mockery v2.42.0. DO NOT EDIT. package mocks diff --git a/pkg/test/mocks/ConsoleClient.go b/pkg/test/mocks/ConsoleClient.go index 0bbd35f0..f76fe1f7 100644 --- a/pkg/test/mocks/ConsoleClient.go +++ b/pkg/test/mocks/ConsoleClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.41.0. DO NOT EDIT. +// Code generated by mockery v2.42.0. DO NOT EDIT. package mocks @@ -406,6 +406,36 @@ func (_m *ConsoleClient) GetServiceContext(name string) (*gqlclient.ServiceConte return r0, r1 } +// KickClusterService provides a mock function with given fields: serviceId, serviceName, clusterName +func (_m *ConsoleClient) KickClusterService(serviceId *string, serviceName *string, clusterName *string) (*gqlclient.ServiceDeploymentExtended, error) { + ret := _m.Called(serviceId, serviceName, clusterName) + + if len(ret) == 0 { + panic("no return value specified for KickClusterService") + } + + var r0 *gqlclient.ServiceDeploymentExtended + var r1 error + if rf, ok := ret.Get(0).(func(*string, *string, *string) (*gqlclient.ServiceDeploymentExtended, error)); ok { + return rf(serviceId, serviceName, clusterName) + } + if rf, ok := ret.Get(0).(func(*string, *string, *string) *gqlclient.ServiceDeploymentExtended); ok { + r0 = rf(serviceId, serviceName, clusterName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.ServiceDeploymentExtended) + } + } + + if rf, ok := ret.Get(1).(func(*string, *string, *string) error); ok { + r1 = rf(serviceId, serviceName, clusterName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // ListClusterServices provides a mock function with given fields: clusterId, handle func (_m *ConsoleClient) ListClusterServices(clusterId *string, handle *string) ([]*gqlclient.ServiceDeploymentEdgeFragment, error) { ret := _m.Called(clusterId, handle) diff --git a/pkg/test/mocks/Kube.go b/pkg/test/mocks/Kube.go index 112229b2..6badcb94 100644 --- a/pkg/test/mocks/Kube.go +++ b/pkg/test/mocks/Kube.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.41.0. DO NOT EDIT. +// Code generated by mockery v2.42.0. DO NOT EDIT. package mocks