From 195d770f706296189984363ab3c5fa4f692872d5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 22 Sep 2023 14:05:30 +0200 Subject: [PATCH] migration: Delete namespaces obsolete since v0.20 Fixes #1585 Rollback not implemented because the namespaces have been obsolete so long, plus this wouldn't restore any resources in the deleted namespaces anyway, so restoring them on their own seems of little value. --- migration/v0.34/README.md | 21 ++++++++++++++ .../v0.34/apply/30-delete-obsolete-ns.sh | 29 +++++++++++++++++++ .../v0.34/prepare/30-delete-obsolete-ns.sh | 18 ++++++++++++ 3 files changed, 68 insertions(+) create mode 100755 migration/v0.34/apply/30-delete-obsolete-ns.sh create mode 100755 migration/v0.34/prepare/30-delete-obsolete-ns.sh diff --git a/migration/v0.34/README.md b/migration/v0.34/README.md index 35b47eb66..d3d01619a 100644 --- a/migration/v0.34/README.md +++ b/migration/v0.34/README.md @@ -94,6 +94,21 @@ As with all scripts in this repository `CK8S_CONFIG_PATH` is expected to be set. git switch -d v0.34.x ``` +1. Verify that no important resources are present in the `elastic-system` and `influxdb-prometheus` namespaces. + + ``` bash + ./migration/v0.34/prepare/30-delete-obsolete-ns.sh + ``` + + Expected output: + + ``` + No resources found in elastic-system namespace. + No resources found in influxdb-prometheus namespace. + ``` + + If resources _are_ present, verify that they are not something important. + 1. Update apps configuration: This will take a backup into `backups/` before modifying any files. @@ -127,6 +142,12 @@ As with all scripts in this repository `CK8S_CONFIG_PATH` is expected to be set. ./migration/v0.30/apply/11-prometheus-operator-crds.sh execute ``` +1. Delete obsolete namespaces: + + ```bash + ./migration/v0.34/apply/30-delete-obsolete-ns.sh execute + ``` + 1. Upgrade applications: ```bash diff --git a/migration/v0.34/apply/30-delete-obsolete-ns.sh b/migration/v0.34/apply/30-delete-obsolete-ns.sh new file mode 100755 index 000000000..b6025b4fc --- /dev/null +++ b/migration/v0.34/apply/30-delete-obsolete-ns.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +ROOT="$(readlink -f "$(dirname "${0}")/../../../")" + +# shellcheck source=scripts/migration/lib.sh +source "${ROOT}/scripts/migration/lib.sh" + +run() { + case "${1:-}" in + execute) + for NS in elastic-system influxdb-prometheus; do + if kubectl_do sc get namespace $NS >/dev/null 2>/dev/null; then + log_info " - deleting unused namespace $NS in sc" + kubectl_do sc delete namespace $NS + else + log_info " - skip deleting not present namespace $NS in sc" + fi + done + ;; + rollback) + log_warn " - restoration of unused namespaces not implemented" + ;; + *) + log_fatal "usage: \"${0}\" " + ;; + esac +} + +run "${@}" diff --git a/migration/v0.34/prepare/30-delete-obsolete-ns.sh b/migration/v0.34/prepare/30-delete-obsolete-ns.sh new file mode 100755 index 000000000..ff97f06b5 --- /dev/null +++ b/migration/v0.34/prepare/30-delete-obsolete-ns.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +HERE="$(dirname "$(readlink -f "${0}")")" +ROOT="$(readlink -f "${HERE}/../../../")" + +# shellcheck source=scripts/migration/lib.sh +source "${ROOT}/scripts/migration/lib.sh" + +for NS in elastic-system influxdb-prometheus; do + log_info "checking for resources in namespace $NS" + NS_RESOURCES="$(kubectl_do sc get all -n $NS 2>&1)" + if [[ "$NS_RESOURCES" == "No resources found in $NS namespace." ]]; then + log_info "$NS_RESOURCES - safe to delete" + else + log_warn "Resources found in namespace $NS, please verify that these are okay to delete before proceeding to apply" + echo "$NS_RESOURCES" + fi +done