From 3698b3fb2d5f927e2d22c8a01b3dc1e6a5e7264c Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Wed, 15 Nov 2023 08:58:43 -0500 Subject: [PATCH 1/3] Add ability to soft delete clusters Use the detach api to implement this, useful for deleting clusters that were never properly created or deleting w/o draining services if you want to leave them in-place. --- cmd/plural/cd_clusters.go | 4 ++++ pkg/console/clusters.go | 5 +++++ pkg/console/console.go | 1 + 3 files changed, 10 insertions(+) diff --git a/cmd/plural/cd_clusters.go b/cmd/plural/cd_clusters.go index 4126c395..9e2f838b 100644 --- a/cmd/plural/cd_clusters.go +++ b/cmd/plural/cd_clusters.go @@ -220,6 +220,10 @@ func (p *Plural) handleDeleteCluster(c *cli.Context) error { return fmt.Errorf("this cluster does not exist") } + if c.Bool("soft") { + return p.ConsoleClient.DetachCluster(existing.ID) + } + return p.ConsoleClient.DeleteCluster(existing.ID) } func (p *Plural) handleGetClusterCredentials(c *cli.Context) error { diff --git a/pkg/console/clusters.go b/pkg/console/clusters.go index 413dc154..6a54349f 100644 --- a/pkg/console/clusters.go +++ b/pkg/console/clusters.go @@ -51,6 +51,11 @@ func (c *consoleClient) DeleteCluster(id string) error { return api.GetErrorResponse(err, "DeleteCluster") } +func (c *consoleClient) DetachCluster(id string) error { + _, err := c.client.DetachCluster(c.ctx, id) + return api.GetErrorResponse(err, "DetachCluster") +} + func (c *consoleClient) CreateCluster(attributes consoleclient.ClusterAttributes) (*consoleclient.CreateCluster, error) { newCluster, err := c.client.CreateCluster(c.ctx, attributes) if err != nil { diff --git a/pkg/console/console.go b/pkg/console/console.go index c9c6c321..5b7ffef1 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -22,6 +22,7 @@ type ConsoleClient interface { GetCluster(clusterId, clusterName *string) (*consoleclient.ClusterFragment, error) UpdateCluster(id string, attr consoleclient.ClusterUpdateAttributes) (*consoleclient.UpdateCluster, error) DeleteCluster(id string) error + DetachCluster(id string) error ListClusterServices(clusterId, handle *string) ([]*consoleclient.ServiceDeploymentEdgeFragment, error) CreateRepository(url string, privateKey, passphrase, username, password *string) (*consoleclient.CreateGitRepository, error) ListRepositories() (*consoleclient.ListGitRepositories, error) From a4f7ba671cbd78b6de07901448f04729a118e4c7 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Wed, 15 Nov 2023 10:06:48 -0500 Subject: [PATCH 2/3] small tweaks --- cmd/plural/cd_clusters.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/plural/cd_clusters.go b/cmd/plural/cd_clusters.go index 9e2f838b..c5a5860f 100644 --- a/cmd/plural/cd_clusters.go +++ b/cmd/plural/cd_clusters.go @@ -67,7 +67,10 @@ func (p *Plural) cdClusterCommands() []cli.Command { Usage: "deregisters a cluster in plural cd, and drains all services (unless --soft is specified)", ArgsUsage: "CLUSTER_ID", Flags: []cli.Flag{ - cli.BoolFlag{Name: "soft", Usage: "deletes a cluster in our system but doesn't drain resources, leaving them untouched"}, + cli.BoolFlag{ + Name: "soft", + Usage: "deletes a cluster in our system but doesn't drain resources, leaving them untouched", + }, }, }, { @@ -221,6 +224,7 @@ func (p *Plural) handleDeleteCluster(c *cli.Context) error { } if c.Bool("soft") { + fmt.Println("soft deleting this cluster") return p.ConsoleClient.DetachCluster(existing.ID) } From 414c1cc87075fa93cb4d0dd452e2d482c420a77f Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Wed, 15 Nov 2023 10:52:27 -0500 Subject: [PATCH 3/3] small make tweak, add notice for detach --- Makefile | 3 ++- cmd/plural/cd_clusters.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ebf401ad..5f4ad221 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ WAILS_BINDINGS_TAGS ?= bindings,generate WAILS_BINDINGS_BINARY_NAME ?= wailsbindings TAGS ?= $(WAILS_TAGS) OUTFILE ?= plural.o +GOBIN ?= go env GOBIN # Targets to run before other targets # install-tools - Install binaries required to run targets @@ -38,7 +39,7 @@ git-push: .PHONY: install install: - go install -ldflags '$(LDFLAGS)' . + go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/plural . .PHONY: build-cli build-cli: ## Build a CLI binary for the host architecture without embedded UI diff --git a/cmd/plural/cd_clusters.go b/cmd/plural/cd_clusters.go index c5a5860f..298f834a 100644 --- a/cmd/plural/cd_clusters.go +++ b/cmd/plural/cd_clusters.go @@ -224,7 +224,7 @@ func (p *Plural) handleDeleteCluster(c *cli.Context) error { } if c.Bool("soft") { - fmt.Println("soft deleting this cluster") + fmt.Println("detaching cluster from Plural CD, this will leave all workloads running.") return p.ConsoleClient.DetachCluster(existing.ID) }