From d1445d64936ae4601025c81d5f5efcaec660506d Mon Sep 17 00:00:00 2001 From: Grace Do Date: Fri, 21 Jul 2023 17:52:48 -0700 Subject: [PATCH] feat: Add pre-upgrade job to delete jaeger HR (#1417) * feat: Add pre-upgrade job to delete jaeger HR * refactor: Delete jaeger HR older than v2.46.2 --- services/jaeger/2.46.2/helmrelease.yaml | 2 + services/jaeger/2.46.2/kustomization.yaml | 1 + services/jaeger/2.46.2/pre-upgrade.yaml | 22 ++++++ .../2.46.2/pre-upgrade/delete-jaeger-hr.yaml | 73 +++++++++++++++++++ .../2.46.2/pre-upgrade/kustomization.yaml | 4 + 5 files changed, 102 insertions(+) create mode 100644 services/jaeger/2.46.2/pre-upgrade.yaml create mode 100644 services/jaeger/2.46.2/pre-upgrade/delete-jaeger-hr.yaml create mode 100644 services/jaeger/2.46.2/pre-upgrade/kustomization.yaml diff --git a/services/jaeger/2.46.2/helmrelease.yaml b/services/jaeger/2.46.2/helmrelease.yaml index d3cba8e83..52a75d646 100644 --- a/services/jaeger/2.46.2/helmrelease.yaml +++ b/services/jaeger/2.46.2/helmrelease.yaml @@ -4,6 +4,8 @@ metadata: name: jaeger-helmrelease namespace: ${releaseNamespace} spec: + dependsOn: + - name: jaeger-pre-upgrade force: false prune: true wait: true diff --git a/services/jaeger/2.46.2/kustomization.yaml b/services/jaeger/2.46.2/kustomization.yaml index 4fd939d44..7739e3c62 100644 --- a/services/jaeger/2.46.2/kustomization.yaml +++ b/services/jaeger/2.46.2/kustomization.yaml @@ -2,3 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - helmrelease.yaml + - pre-upgrade.yaml diff --git a/services/jaeger/2.46.2/pre-upgrade.yaml b/services/jaeger/2.46.2/pre-upgrade.yaml new file mode 100644 index 000000000..35351fb3e --- /dev/null +++ b/services/jaeger/2.46.2/pre-upgrade.yaml @@ -0,0 +1,22 @@ +apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 +kind: Kustomization +metadata: + name: jaeger-pre-upgrade + namespace: ${releaseNamespace} +spec: + force: false + prune: true + wait: true + interval: 6h + retryInterval: 1m + path: ./services/jaeger/2.46.2/pre-upgrade + sourceRef: + kind: GitRepository + name: management + namespace: kommander-flux + timeout: 1m + # passing releaseNamespace to 2nd level configuration files for ability to configure namespace correctly in attached clusters + # Using `substituteFrom` with `substitution-vars` creates 2nd level resources in `kommander` namespace instead of workspace ns + postBuild: + substitute: + releaseNamespace: ${releaseNamespace} diff --git a/services/jaeger/2.46.2/pre-upgrade/delete-jaeger-hr.yaml b/services/jaeger/2.46.2/pre-upgrade/delete-jaeger-hr.yaml new file mode 100644 index 000000000..77fbb20c8 --- /dev/null +++ b/services/jaeger/2.46.2/pre-upgrade/delete-jaeger-hr.yaml @@ -0,0 +1,73 @@ +# For upgrades from DKP <2.6 to 2.6.x. +# **REMOVE THIS AFTER 2.6 IS RELEASED** +# Delete the jaeger helmrelease prior to upgrading. +# This must be done because upgrading does not apply the newly added priorityClassName field on the +# Jaeger spec, perhaps because the CRD has not been upgraded yet. Recreating the HelmRelease applies the +# Jaeger spec properly. This job will only delete helmreleases from 2.5, so rerunning this job +# during upgrades within 2.6 will not result in the recreation of the helmrelease. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jaeger-pre-upgrade + namespace: ${releaseNamespace} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: jaeger-pre-upgrade + namespace: ${releaseNamespace} +rules: + - apiGroups: ["helm.toolkit.fluxcd.io"] + resources: ["helmreleases"] + verbs: ["get", "watch", "list", "delete"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: jaeger-pre-upgrade + namespace: ${releaseNamespace} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: jaeger-pre-upgrade +subjects: + - kind: ServiceAccount + name: jaeger-pre-upgrade + namespace: ${releaseNamespace} +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: delete-jaeger-helmrelease + namespace: ${releaseNamespace} +spec: + ttlSecondsAfterFinished: 100 + template: + metadata: + name: delete-jaeger-helmrelease + spec: + serviceAccountName: jaeger-pre-upgrade + restartPolicy: OnFailure + priorityClassName: dkp-high-priority + containers: + - name: kubectl + image: bitnami/kubectl:1.26.4 + command: + - sh + - "-c" + - |- + /bin/bash <<'EOF' + set -o nounset + set -o errexit + set -o pipefail + + echo "checking jaeger helmrelease and deleting it pre-upgrade if older than v2.46.2" + + VERSION=$(set -o errexit; kubectl get helmrelease -n ${releaseNamespace} jaeger --ignore-not-found -o=jsonpath='{.spec.chart.spec.version}') + echo "pre-upgrade jaeger version $VERSION" + if [[ $VERSION < "2.46.2" ]]; then + echo "deleting jaeger helmrelease" + kubectl delete helmrelease jaeger -n ${releaseNamespace} --ignore-not-found + exit 0 + fi + EOF diff --git a/services/jaeger/2.46.2/pre-upgrade/kustomization.yaml b/services/jaeger/2.46.2/pre-upgrade/kustomization.yaml new file mode 100644 index 000000000..053d2c1f9 --- /dev/null +++ b/services/jaeger/2.46.2/pre-upgrade/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - delete-jaeger-hr.yaml