Concourse Multi Namespace Applier
Introduction to Applying Changes To Multiple Namespaces At Once
Users are prevented from submitting PRs which will affect multiple namespaces at once. Occasionally we will need to do it e.g. during incidents, or at user request if they have a very large amount of namespaces to update.
Pre-requisites
- A PR with all the updates in it (typically created by the user). This PR will fail on the
reject-multi-namespace-prs.ymlcheck. - Access to concourse
- Access to cloud-platform-terraform-concourse
- If running locally: fly installed
Process
When a change needs to be applied to multiple namespaces in a single operation, use the following process.
Consider whether the user has appropriate permissions for what they are requesting. This is needed as the
rbac-permissions-checkwill only check one namespace.Obtain a list of all namespaces that need to be updated. The
github-actionsbot should have commented a list on the PR.Dismiss the failing
reject-multi-namespace-prs.ymlcheck on the PR.Create a Concourse pipeline to run the apply. Note this can also be done locally with
fly, see the section further down, but that is not the preferred approach. If you do usefly, skip steps 6 & 7.Update the multi-namespace applier pipeline configuration:
- Add the affected namespaces to the following file (you may need to create it):
- https://github.com/ministryofjustice/cloud-platform-terraform-concourse/blob/main/pipelines/manager/main/multi-ns-applier.yaml
- Raise and merge a pull request into
main. - Note that you don’t need to cut a release, the job just needs to be in
main. The bootstrap pipeline will look at all the files in../pipelines/manager/maindirectory and the tile for job will appear.
- Add the affected namespaces to the following file (you may need to create it):
Unpause the bootstrap pipeline in the Concourse CI.
Ensure no other changes are being applied to the affected namespaces at the same time.
- Running multiple Terraform applies against the same namespace concurrently may result in state lock contention or failed applies.
- If this cannot be assured, consider temporarily pausing the environments-live pipeline until the multi-namespace apply has completed.
Merge the pull request.
Trigger the multi-namespace apply job:
- Navigate to:
- https://concourse.cloud-platform.service.justice.gov.uk/teams/main/pipelines/multi-ns-applier/jobs/apply-namespaces/builds/
- Unpause this pipeline
- Start a new build and monitor it until completion.
- Navigate to:
Cleanup:
- If you modified the shared
multi-ns-applier.yamlfile, remove the temporary namespace entries once the change has been successfully applied and merge the cleanup change intomain. This reduces the risk of future executions unintentionally targeting the same namespaces. - Pause the bootstrap pipeline if you unpaused it.
- If you modified the shared
Running the Pipeline Locally With fly
Instead of updating the shared pipeline configuration, you can create a temporary copy of the pipeline and execute it using fly. Be aware this introduces drift and means we lose visibility of who updated the pipeline so is not the preferred option.
Clone a local copy of cloud-platform-terraform-concourse
Update
pipelines/disabled/multi-ns-applier.yamlCreate the pipeline:
fly -t manager set-pipeline -p multi-ns-applier-[some-name] -c pipelines/disabled/multi-ns-applier.yaml- If you are not already authenticated,
flywill display an error similar to:
could not find a valid token. logging in to team 'main' navigate to the following URL in your browser: https://concourse.cloud-platform.service.justice.gov.uk/login?fly_port=XXXX
- Open the URL in your browser and complete the authentication process.
- Re-run the
fly set-pipelinecommand.
- Now continue the Process section at Step 8.