Skip to content

Commit

Permalink
Merge pull request #549 from ministryofjustice/pipeline-delete-branch…
Browse files Browse the repository at this point in the history
…-flag

add optional branch flag to pipeline delete command
  • Loading branch information
sj-williams authored Mar 12, 2024
2 parents 140e5a0 + 0d5d3b4 commit f8944ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit f8944ef

Please sign in to comment.