Skip to content

Commit

Permalink
Add ability to soft delete clusters (#474)
Browse files Browse the repository at this point in the history
* 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.

* small tweaks

* small make tweak, add notice for detach
  • Loading branch information
michaeljguarino authored Nov 16, 2023
1 parent e350eef commit 818ee6e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion cmd/plural/cd_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
{
Expand Down Expand Up @@ -220,6 +223,11 @@ func (p *Plural) handleDeleteCluster(c *cli.Context) error {
return fmt.Errorf("this cluster does not exist")
}

if c.Bool("soft") {
fmt.Println("detaching cluster from Plural CD, this will leave all workloads running.")
return p.ConsoleClient.DetachCluster(existing.ID)
}

return p.ConsoleClient.DeleteCluster(existing.ID)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/console/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 818ee6e

Please sign in to comment.