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 optional branch flag to pipeline delete command #549

Merged
merged 2 commits into from
Mar 12, 2024
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: 3 additions & 0 deletions doc/cloud-platform_pipeline_delete-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ It will delete the components, then the cluster, the VPC, terraform workspace an
You must have the following environment variables set, or passed via arguments:
- a cluster name

Optionally you can pass a branch name to use for the pipeline run, default is "main"

** You _must_ have the fly cli installed **
--> https://concourse-ci.org/fly.html

Expand All @@ -27,6 +29,7 @@ cloud-platform pipeline delete-cluster [flags]
### Options

```
-b, --branch-name string branch name to use for pipeline run (default: main) (default "main")
--cluster-name string cluster to delete
-h, --help help for delete-cluster
```
Expand Down
6 changes: 5 additions & 1 deletion pkg/commands/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type pipelineOptions struct {
Name string
NodeGroupName string
MaxNameLength int8
BranchName string
}

var cliOpt pipelineOptions
Expand Down Expand Up @@ -69,6 +70,7 @@ func addPipelineCordonAndDrainClusterCmd(toplevel *cobra.Command) {

func (opt *pipelineOptions) addPipelineDeleteClusterFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&cliOpt.Name, "cluster-name", "", "cluster to delete")
cmd.Flags().StringVarP(&cliOpt.BranchName, "branch-name", "b", "main", "branch name to use for pipeline run (default: main)")
}

func addPipelineDeleteClusterCmd(toplevel *cobra.Command) {
Expand All @@ -85,6 +87,8 @@ func addPipelineDeleteClusterCmd(toplevel *cobra.Command) {
You must have the following environment variables set, or passed via arguments:
- a cluster name

Optionally you can pass a branch name to use for the pipeline run, default is "main"

** You _must_ have the fly cli installed **
--> https://concourse-ci.org/fly.html

Expand All @@ -104,7 +108,7 @@ func addPipelineDeleteClusterCmd(toplevel *cobra.Command) {
contextLogger.Fatal(err)
}

pipeline.DeletePipelineShellCmds(cliOpt.Name)
pipeline.DeletePipelineShellCmds(cliOpt.Name, cliOpt.BranchName)
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func runCmd(cliCmd string, args []string) {
}
}

func DeletePipelineShellCmds(clusterName string) {
func DeletePipelineShellCmds(clusterName string, branchName string) {
runCmd("fly", []string{"--target", "manager", "login", "--team-name", "main", "--concourse-url", "https://concourse.cloud-platform.service.justice.gov.uk/"})
runCmd("bash", []string{"-c", "wget -qO- https://raw.githubusercontent.com/ministryofjustice/cloud-platform-terraform-concourse/main/pipelines/manager/main/delete-cluster.yaml | fly --target manager set-pipeline -p delete-cluster -c - -v cluster_name=" + clusterName})
runCmd("bash", []string{"-c", "wget -qO- https://raw.githubusercontent.com/ministryofjustice/cloud-platform-terraform-concourse/main/pipelines/manager/main/delete-cluster.yaml | fly --target manager set-pipeline -p delete-cluster -c - -v cluster_name=" + clusterName + " -v branch_name=" + branchName})
runCmd("fly", []string{"--target", "manager", "trigger-job", "-j", "delete-cluster/delete"})
fmt.Println("Deleting... https://concourse.cloud-platform.service.justice.gov.uk/teams/main/pipelines/delete-cluster/jobs/delete/builds/latest")
}
Expand Down