Skip to content

Instantly share code, notes, and snippets.

@erdii
Created August 4, 2023 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdii/65f86efdbea815bdd242c30e00d6ed04 to your computer and use it in GitHub Desktop.
Save erdii/65f86efdbea815bdd242c30e00d6ed04 to your computer and use it in GitHub Desktop.
package-operator CRD v1.6.6 to v1.7.0 upgrade fix
#!/bin/bash
set -euxo pipefail
PKO_NAMESPACE="package-operator-system"
PKO_POD_SELECTOR="app.kubernetes.io/name=package-operator"
PKO_COS_SELECTOR="package-operator.run/package=package-operator"
# get rid of currently running PKO
kubectl delete deploy -n "$PKO_NAMESPACE" package-operator-manager
# wait until all PKO pods are shut down
kubectl wait pod \
-n "$PKO_NAMESPACE" \
--selector="$PKO_POD_SELECTOR" \
--for=delete --timeout=300s
# delete old non-pluralized CRDs
kubectl delete crd \
objectslice.package-operator.run \
clusterobjectslice.package-operator.run
# delete PKO's ClusterObjectSets (both old and new) but
# cascade='orphan' is very IMPORTANT (!)
# this will keep the other PKO CRDs in the cluster (otherwise packages will vanish and the newly upgraded PKO will uninstall all previously installed packages from the cluster
# I repeat: THIS IS IMPORTANT!
# TODO: idempotency: check if they are already deleted
kubectl delete clusterobjectset \
-l="$PKO_COS_SELECTOR" \
--cascade='orphan' \
--wait=false
# Remove finalizers from existing PKO ClusterObjectSets to unblock their deletion
kubectl get clusterobjectset \
-l="$PKO_COS_SELECTOR" \
-o='jsonpath={.items.*.metadata.name}' \
| xargs -I '{}' -d ' ' -n 1 \
kubectl patch clusterobjectset '{}' \
-p '{"metadata":{"finalizers": null}}' \
--type=merge
# Wait until all PKO ClusterObjectsets are fully deleted
kubectl wait clusterobjectset \
--selector="$PKO_COS_SELECTOR" \
--for=delete --timeout=60s
# re run install-job for new version
kubectl apply -f https://github.com/package-operator/package-operator/releases/download/v1.7.0/self-bootstrap-job.yaml
# function retail() { tail -f -n +0 "$2" > "$1"; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment