Skip to content

Commit

Permalink
feat: Add pre-upgrade job to delete jaeger HR (#1417)
Browse files Browse the repository at this point in the history
* feat: Add pre-upgrade job to delete jaeger HR

* refactor: Delete jaeger HR older than v2.46.2
  • Loading branch information
gracedo authored Jul 22, 2023
1 parent 9b67dd9 commit d1445d6
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions services/jaeger/2.46.2/helmrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
name: jaeger-helmrelease
namespace: ${releaseNamespace}
spec:
dependsOn:
- name: jaeger-pre-upgrade
force: false
prune: true
wait: true
Expand Down
1 change: 1 addition & 0 deletions services/jaeger/2.46.2/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- helmrelease.yaml
- pre-upgrade.yaml
22 changes: 22 additions & 0 deletions services/jaeger/2.46.2/pre-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -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}
73 changes: 73 additions & 0 deletions services/jaeger/2.46.2/pre-upgrade/delete-jaeger-hr.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions services/jaeger/2.46.2/pre-upgrade/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- delete-jaeger-hr.yaml

0 comments on commit d1445d6

Please sign in to comment.