Skip to content

Commit

Permalink
migration: Delete namespaces obsolete since v0.20
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Zash committed Oct 9, 2023
1 parent 1d75831 commit 195d770
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions migration/v0.34/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions migration/v0.34/apply/30-delete-obsolete-ns.sh
Original file line number Diff line number Diff line change
@@ -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}\" <execute|rollback>"
;;
esac
}

run "${@}"
18 changes: 18 additions & 0 deletions migration/v0.34/prepare/30-delete-obsolete-ns.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 195d770

Please sign in to comment.