From 0cbfa36b4eab2007f80401084de6a8ed92d39c89 Mon Sep 17 00:00:00 2001 From: Jack Stockley Date: Tue, 11 Jul 2023 18:15:32 +0100 Subject: [PATCH] docs(source): update steps to new method of using the cli to delete namespace resources --- ...lly-delete-namespace-resources.html.md.erb | 82 +++++++++++-------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/runbooks/source/manually-delete-namespace-resources.html.md.erb b/runbooks/source/manually-delete-namespace-resources.html.md.erb index ba85be3d..3b53ba15 100644 --- a/runbooks/source/manually-delete-namespace-resources.html.md.erb +++ b/runbooks/source/manually-delete-namespace-resources.html.md.erb @@ -7,39 +7,53 @@ review_in: 6 months # Manually Delete Namespace Resources -We have a [script][deleter script] which will delete all of the AWS resources belonging to a given namespace, by running `terraform apply` with an empty `main.tf` file, and then running `kubectl delete namespace`. - -> The script will not do anything if: -> -> a) the namespace folder exists in your local working copy of the [environments repository], or -> -> b) the namespace has `is-production: "true"` - -NB: You need `ruby` installed, in order to use this tool. - -To run the script: - -1. populate the environment variables listed in the comment at the top of the script - -1. cd to the root of a working copy of the [environments repository] - -1. Run `bundle install` - -1. Run the script, supplying the namespace name as the only argument, e.g. - -``` -./bin/delete-namespace.rb mynamespace +This topic describes how to manually delete namespace resources, deleting namespace resources is now done via the `cloud-plaform` CLI. + +## Prerequisites + +- You have the `cloud-platform` CLI installed +- You have the `kubectl` CLI installed +- You have the `terraform` CLI installed + +## environment variables + +Perform a kubectl destroy and a terraform delete for a given namespace using either -namespace flag or the + the namespace in the given PR Id/Number + + Along with the mandatory input flag, the below environments variables needs to be set + - TF_VAR_cluster_name - e.g. "cp-1902-02" to get the vpc details for some modules like rds, es + - TF_VAR_cluster_state_bucket - State where the cluster state is stored + - TF_VAR_cluster_state_key - folder name/state key inside the state bucket where cluster state is stored + - TF_VAR_github_owner - Github owner: ministryofjustice + - TF_VAR_github_token - Personal access token with repo scope to push github action secrets + - TF_VAR_kubernetes_cluster - Full name of the Cluster e.g. XXXXXX.gr7.eu-west2.eks.amazonaws.com + - PINGDOM_API_TOKEN - API Token to access pingdom + - PIPELINE_TERRAFORM_STATE_LOCK_TABLE - DynamoDB table where the state lock is stored + - PIPELINE_STATE_BUCKET - State bucket where the environments state is stored e.g cloud-platform-terraform-state + - PIPELINE_STATE_KEY_PREFIX - State key/ folder where the environments terraform state is stored e.g cloud-platform-environments + - PIPELINE_STATE_REGION - State region of the bucket e.g. eu-west-1 + - PIPELINE_CLUSTER - Cluster name/folder inside namespaces/ in cloud-platform-environments + - PIPELINE_CLUSTER_STATE - Cluster name/folder inside the state bucket where the environments terraform state is stored + +## Usage + +```bash +cloud-platform environment destroy [flags] + +Examples: +$ cloud-platform environment destroy -n + + +Flags: + --cluster string folder name under namespaces/ inside cloud-platform-environments repo refering to full cluster name + --github-token string Personal access Token from Github + -h, --help help for destroy + --kubecfg string path to kubeconfig file (default "/.kube/config") + -n, --namespace string Namespace which you want to perform the destroy + --prNumber int Pull request ID or number to which you want to perform the destroy + --redact Redact the terraform output before printing (default true) + +Global Flags: + --skip-version-check don't check for updates ``` -If you need to delete a production namespace, you will have to comment out the code which prevents that from happening. - -That's the code block [here](https://github.com/ministryofjustice/cloud-platform-environments/blob/dd2e0049b5eb17d2925a55b22f4102896909a96b/lib/cp_env/namespace_deleter.rb#L71) - -> If the script fails partway through, it may leave a new folder in your local working copy: -> -> `namespaces/live.cloud-platform.service.justice.gov.uk/[namespace name]` -> -> If this happens, just delete the whole `namespaces/live.cloud-platform.service.justice.gov.uk/[namespace name]` folder and re-run the script. - -[deleter script]: https://github.com/ministryofjustice/cloud-platform-environments/blob/main/bin/delete-namespace.rb -[environments repository]: https://github.com/ministryofjustice/cloud-platform-environments