Skip to content

Commit

Permalink
bin: fix snippets, update manual migration steps
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-elastisys committed Oct 19, 2023
1 parent 4e1eb05 commit 1b4b4b0
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 32 deletions.
12 changes: 12 additions & 0 deletions migration/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ As with all scripts in this repository `CK8S_CONFIG_PATH` is expected to be set.
git switch -d ${new_version}.x
```

1. Set whether or not upgrade should be prepared for `both` clusters or for one of `sc` or `wc`:

```bash
export CK8S_CLUSTER=<wc|sc|both>
```

1. Update apps configuration:

This will take a backup into `backups/` before modifying any files.
Expand All @@ -120,6 +126,12 @@ As with all scripts in this repository `CK8S_CONFIG_PATH` is expected to be set.

> *Done during maintenance window.*

1. Set whether or not upgrade should be applied for `both` clusters or for one of `sc` or `wc`:

```bash
export CK8S_CLUSTER=<wc|sc|both>
```

1. Rerun bootstrap:

```bash
Expand Down
8 changes: 4 additions & 4 deletions migration/template/apply/00-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ run() {
# Note: 00-template.sh will be skipped by the upgrade command
log_info "no operation: this is a template"

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
log_info "operation on service cluster"
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
log_info "operation on workload cluster"
fi
;;
rollback)
log_warn "rollback not implemented"

# if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
# if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
# log_info "rollback operation on service cluster"
# fi
# if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
# if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
# log_info "rollback operation on workload cluster"
# fi
;;
Expand Down
4 changes: 2 additions & 2 deletions migration/template/apply/20-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ source "${ROOT}/scripts/migration/lib.sh"
run() {
case "${1:-}" in
execute)
if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
"${ROOT}/bin/ck8s" bootstrap sc
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
"${ROOT}/bin/ck8s" bootstrap wc
fi
;;
Expand Down
8 changes: 4 additions & 4 deletions migration/template/apply/80-apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ run() {
local -a filters
local selector

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
filters=("${skipped[@]}" "${skipped_sc[@]}")
selector="${filters[*]:-"app!=null"}"
helmfile_upgrade sc "${selector// /,}"
fi

if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
filters=("${skipped[@]}" "${skipped_wc[@]}")
selector="${filters[*]:-"app!=null"}"
helmfile_upgrade wc "${selector// /,}"
Expand All @@ -39,10 +39,10 @@ run() {
rollback)
log_warn "rollback not implemented"

# if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
# if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
# log_info "rollback operation on service cluster"
# fi
# if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
# if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
# log_info "rollback operation on workload cluster"
# fi
;;
Expand Down
4 changes: 2 additions & 2 deletions migration/template/prepare/00-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ source "${ROOT}/scripts/migration/lib.sh"
# Note: 00-template.sh will be skipped by the upgrade command
log_info "no operation: this is a template"

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
log_info "operation on service cluster"
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
log_info "operation on workload cluster"
fi
12 changes: 12 additions & 0 deletions migration/v0.34/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ As with all scripts in this repository `CK8S_CONFIG_PATH` is expected to be set.
git switch -d v0.34.x
```

1. Set whether or not upgrade should be prepared for `both` clusters or for one of `sc` or `wc`:

```bash
export CK8S_CLUSTER=<wc|sc|both>
```

1. Verify that no important resources are present in the `elastic-system` and `influxdb-prometheus` namespaces.

``` bash
Expand Down Expand Up @@ -135,6 +141,12 @@ As with all scripts in this repository `CK8S_CONFIG_PATH` is expected to be set.

> *Done during maintenance window.*

1. Set whether or not upgrade should be applied for `both` clusters or for one of `sc` or `wc`:

```bash
export CK8S_CLUSTER=<wc|sc|both>
```

1. Rerun bootstrap:

```bash
Expand Down
8 changes: 4 additions & 4 deletions migration/v0.34/apply/00-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ run() {
# Note: 00-template.sh will be skipped by the upgrade command
log_info "no operation: this is a template"

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
log_info "operation on service cluster"
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
log_info "operation on workload cluster"
fi
;;
rollback)
log_warn "rollback not implemented"

# if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
# if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
# log_info "rollback operation on service cluster"
# fi
# if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
# if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
# log_info "rollback operation on workload cluster"
# fi
;;
Expand Down
4 changes: 2 additions & 2 deletions migration/v0.34/apply/20-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ run() {
case "${1:-}" in
execute)

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
"${ROOT}/bin/ck8s" bootstrap sc
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
"${ROOT}/bin/ck8s" bootstrap wc
fi
;;
Expand Down
2 changes: 1 addition & 1 deletion migration/v0.34/apply/30-delete-obsolete-ns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run() {
case "${1:-}" in
execute)

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
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"
Expand Down
4 changes: 2 additions & 2 deletions migration/v0.34/apply/80-apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ run() {
local -a filters
local selector

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
filters=("${skipped[@]}" "${skipped_sc[@]}")
selector="${filters[*]:-"app!=null"}"
helmfile_upgrade sc "${selector// /,}"
fi

if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
filters=("${skipped[@]}" "${skipped_wc[@]}")
selector="${filters[*]:-"app!=null"}"
helmfile_upgrade wc "${selector// /,}"
Expand Down
4 changes: 2 additions & 2 deletions migration/v0.34/prepare/00-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ source "${ROOT}/scripts/migration/lib.sh"
# Note: 00-template.sh will be skipped by the upgrade command
log_info "no operation: this is a template"

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
log_info "operation on service cluster"
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
log_info "operation on workload cluster"
fi
2 changes: 1 addition & 1 deletion migration/v0.34/prepare/30-delete-obsolete-ns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ROOT="$(readlink -f "${HERE}/../../../")"
# shellcheck source=scripts/migration/lib.sh
source "${ROOT}/scripts/migration/lib.sh"

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
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)"
Expand Down
16 changes: 8 additions & 8 deletions scripts/migration/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ THIS="$(basename "$(readlink -f "${0}")")"
declare -A CONFIG
declare -A VERSION

SC_STATE_FILE=".state/kube_config_sc.yaml"
WC_STATE_FILE=".state/kube_config_wc.yaml"
SC_KUBECONFIG_FILE=".state/kube_config_sc.yaml"
WC_KUBECONFIG_FILE=".state/kube_config_wc.yaml"

declare -a SC_CONFIG_FILES
SC_CONFIG_FILES=(
Expand Down Expand Up @@ -179,7 +179,7 @@ check_sops() {
}

check_config() {
if [ -z "${CK8S_CLUSTER}" ]; then
if [ -z "${CK8S_CLUSTER:-}" ]; then
log_fatal "error: \"CK8S_CLUSTER\" is unset"
elif [[ ! "${CK8S_CLUSTER}" =~ ^(sc|wc|both)$ ]]; then
log_fatal "error: invalid value set for \"CK8S_CLUSTER\", valid values are <sc|wc|both>"
Expand All @@ -199,16 +199,16 @@ check_config() {

local pass="true"

if [[ "${CK8S_CLUSTER:-}" =~ ^(sc|both)$ ]]; then
for FILE in "${SC_CONFIG_FILES[@]}" "$SC_STATE_FILE"; do
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
for FILE in "${SC_CONFIG_FILES[@]}" "$SC_KUBECONFIG_FILE"; do
if [ ! -f "${CK8S_CONFIG_PATH}/${FILE}" ]; then
log_error "error: \"${FILE}\" is not a file"
pass="false"
fi
done
fi
if [[ "${CK8S_CLUSTER:-}" =~ ^(wc|both)$ ]]; then
for FILE in "${WC_CONFIG_FILES[@]}" "$WC_STATE_FILE"; do
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
for FILE in "${WC_CONFIG_FILES[@]}" "$WC_KUBECONFIG_FILE"; do
if [ ! -f "${CK8S_CONFIG_PATH}/${FILE}" ]; then
log_error "error: \"${FILE}\" is not a file"
pass="false"
Expand All @@ -226,7 +226,7 @@ check_config() {
fi

for prefix in wc sc; do
if [[ "${CK8S_CLUSTER:-}" =~ ^($prefix|both)$ ]]; then
if [[ "${CK8S_CLUSTER}" =~ ^($prefix|both)$ ]]; then
if check_sops "${CK8S_CONFIG_PATH}/.state/kube_config_${prefix}.yaml"; then
CONFIG["${prefix}-kubeconfig"]="encrypted"
else
Expand Down

0 comments on commit 1b4b4b0

Please sign in to comment.