From 2e5c0af5b54d0f392e6dfe634017b52f7216e36b Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Mon, 13 Nov 2023 16:59:36 +0100 Subject: [PATCH 1/3] cd install check cluster --- cmd/plural/cd.go | 17 ++++++++++++++--- pkg/console/clusters.go | 4 ++++ pkg/console/console.go | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/plural/cd.go b/cmd/plural/cd.go index 5021d5c5..ce632abf 100644 --- a/cmd/plural/cd.go +++ b/cmd/plural/cd.go @@ -62,9 +62,9 @@ func (p *Plural) cdCommands() []cli.Command { }, }, { - Name: "eject", - Action: p.handleEject, - Usage: "ejects cluster scaffolds", + Name: "eject", + Action: p.handleEject, + Usage: "ejects cluster scaffolds", ArgsUsage: "", // TODO: enable once logic is finished Hidden: true, @@ -93,6 +93,17 @@ func (p *Plural) doInstallOperator(url, token string) error { if err != nil && !apierrors.IsAlreadyExists(err) { return err } + consoleClient, err := console.NewConsoleClient(token, url) + if err != nil { + return err + } + myCluster, err := consoleClient.MyCluster() + if err != nil { + return err + } + if !confirm(fmt.Sprintf("Are you sure you want to install deploy operator for %s cluster?", myCluster.MyCluster.Name), "PLURAL_INSTALL_AGENT_CONFIRM") { + return nil + } err = console.InstallAgent(url, token, operatorNamespace) if err == nil { utils.Success("deployment operator installed successfully\n") diff --git a/pkg/console/clusters.go b/pkg/console/clusters.go index 8532d3c4..d143f95b 100644 --- a/pkg/console/clusters.go +++ b/pkg/console/clusters.go @@ -58,3 +58,7 @@ func (c *consoleClient) CreateCluster(attributes consoleclient.ClusterAttributes } return newCluster, nil } + +func (c *consoleClient) MyCluster() (*consoleclient.MyCluster, error) { + return c.client.MyCluster(c.ctx) +} diff --git a/pkg/console/console.go b/pkg/console/console.go index 5227f826..c9c6c321 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -37,6 +37,7 @@ type ConsoleClient interface { SavePipeline(name string, attrs consoleclient.PipelineAttributes) (*consoleclient.PipelineFragment, error) CreateCluster(attributes consoleclient.ClusterAttributes) (*consoleclient.CreateCluster, error) CreateProvider(attr consoleclient.ClusterProviderAttributes) (*consoleclient.CreateClusterProvider, error) + MyCluster() (*consoleclient.MyCluster, error) } func NewConsoleClient(token, url string) (ConsoleClient, error) { From abfe137e64be12eb7421597799f2acd0bb238535 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Mon, 13 Nov 2023 17:12:07 +0100 Subject: [PATCH 2/3] add mocks --- pkg/test/mocks/ConsoleClient.go | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/pkg/test/mocks/ConsoleClient.go b/pkg/test/mocks/ConsoleClient.go index 77ee71f1..812998b6 100644 --- a/pkg/test/mocks/ConsoleClient.go +++ b/pkg/test/mocks/ConsoleClient.go @@ -12,6 +12,32 @@ type ConsoleClient struct { mock.Mock } +// CloneService provides a mock function with given fields: clusterId, serviceId, serviceName, clusterName, attributes +func (_m *ConsoleClient) CloneService(clusterId string, serviceId *string, serviceName *string, clusterName *string, attributes gqlclient.ServiceCloneAttributes) (*gqlclient.ServiceDeploymentFragment, error) { + ret := _m.Called(clusterId, serviceId, serviceName, clusterName, attributes) + + var r0 *gqlclient.ServiceDeploymentFragment + var r1 error + if rf, ok := ret.Get(0).(func(string, *string, *string, *string, gqlclient.ServiceCloneAttributes) (*gqlclient.ServiceDeploymentFragment, error)); ok { + return rf(clusterId, serviceId, serviceName, clusterName, attributes) + } + if rf, ok := ret.Get(0).(func(string, *string, *string, *string, gqlclient.ServiceCloneAttributes) *gqlclient.ServiceDeploymentFragment); ok { + r0 = rf(clusterId, serviceId, serviceName, clusterName, attributes) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.ServiceDeploymentFragment) + } + } + + if rf, ok := ret.Get(1).(func(string, *string, *string, *string, gqlclient.ServiceCloneAttributes) error); ok { + r1 = rf(clusterId, serviceId, serviceName, clusterName, attributes) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // CreateCluster provides a mock function with given fields: attributes func (_m *ConsoleClient) CreateCluster(attributes gqlclient.ClusterAttributes) (*gqlclient.CreateCluster, error) { ret := _m.Called(attributes) @@ -364,6 +390,32 @@ func (_m *ConsoleClient) ListRepositories() (*gqlclient.ListGitRepositories, err return r0, r1 } +// MyCluster provides a mock function with given fields: +func (_m *ConsoleClient) MyCluster() (*gqlclient.MyCluster, error) { + ret := _m.Called() + + var r0 *gqlclient.MyCluster + var r1 error + if rf, ok := ret.Get(0).(func() (*gqlclient.MyCluster, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *gqlclient.MyCluster); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.MyCluster) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // SavePipeline provides a mock function with given fields: name, attrs func (_m *ConsoleClient) SavePipeline(name string, attrs gqlclient.PipelineAttributes) (*gqlclient.PipelineFragment, error) { ret := _m.Called(name, attrs) @@ -390,6 +442,20 @@ func (_m *ConsoleClient) SavePipeline(name string, attrs gqlclient.PipelineAttri return r0, r1 } +// Token provides a mock function with given fields: +func (_m *ConsoleClient) Token() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + // UpdateCluster provides a mock function with given fields: id, attr func (_m *ConsoleClient) UpdateCluster(id string, attr gqlclient.ClusterUpdateAttributes) (*gqlclient.UpdateCluster, error) { ret := _m.Called(id, attr) From 83ac947b479449bc438d16bd5b08762144d75219 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Tue, 14 Nov 2023 08:50:03 +0100 Subject: [PATCH 3/3] display cluster details --- cmd/plural/cd.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/plural/cd.go b/cmd/plural/cd.go index ce632abf..14d2bea2 100644 --- a/cmd/plural/cd.go +++ b/cmd/plural/cd.go @@ -101,7 +101,20 @@ func (p *Plural) doInstallOperator(url, token string) error { if err != nil { return err } - if !confirm(fmt.Sprintf("Are you sure you want to install deploy operator for %s cluster?", myCluster.MyCluster.Name), "PLURAL_INSTALL_AGENT_CONFIRM") { + clusterFragment, err := consoleClient.GetCluster(&myCluster.MyCluster.ID, nil) + if err != nil { + return err + } + + handle := "-" + provider := "-" + if clusterFragment.Handle != nil { + handle = *clusterFragment.Handle + } + if clusterFragment.Provider != nil { + provider = clusterFragment.Provider.Name + } + if !confirm(fmt.Sprintf("Are you sure you want to install deploy operator for the cluster:\nName: %s\nHandle: %s\nProvider: %s\n", myCluster.MyCluster.Name, handle, provider), "PLURAL_INSTALL_AGENT_CONFIRM") { return nil } err = console.InstallAgent(url, token, operatorNamespace)