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

Add ability to soft delete clusters #474

Merged
merged 3 commits into from
Nov 16, 2023
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
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)
}
func (p *Plural) handleGetClusterCredentials(c *cli.Context) error {
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
Loading