diff --git a/doc/cloud-platform_pipeline_delete-cluster.md b/doc/cloud-platform_pipeline_delete-cluster.md index 062bbfb0..ab0119cb 100644 --- a/doc/cloud-platform_pipeline_delete-cluster.md +++ b/doc/cloud-platform_pipeline_delete-cluster.md @@ -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 @@ -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 ``` diff --git a/pkg/commands/pipeline.go b/pkg/commands/pipeline.go index 9d00c1f1..70a36c9c 100644 --- a/pkg/commands/pipeline.go +++ b/pkg/commands/pipeline.go @@ -13,6 +13,7 @@ type pipelineOptions struct { Name string NodeGroupName string MaxNameLength int8 + BranchName string } var cliOpt pipelineOptions @@ -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) { @@ -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 @@ -104,7 +108,7 @@ func addPipelineDeleteClusterCmd(toplevel *cobra.Command) { contextLogger.Fatal(err) } - pipeline.DeletePipelineShellCmds(cliOpt.Name) + pipeline.DeletePipelineShellCmds(cliOpt.Name, cliOpt.BranchName) }, } diff --git a/pkg/pipeline/pipeline.go b/pkg/pipeline/pipeline.go index 8218f96e..9ec6cfee 100644 --- a/pkg/pipeline/pipeline.go +++ b/pkg/pipeline/pipeline.go @@ -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") }