From bca8ecf8e2ea51690a1edf6ff5d2830487d19aac Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Thu, 7 Nov 2024 22:59:49 -0800 Subject: [PATCH] Use kubectl to delete all configurations in helm hook Signed-off-by: Kate Goldenring --- deployment/helm/templates/pre-delete-job.yaml | 13 +++++++++---- deployment/helm/templates/rbac.yaml | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/deployment/helm/templates/pre-delete-job.yaml b/deployment/helm/templates/pre-delete-job.yaml index 813c2611d..4be324d90 100644 --- a/deployment/helm/templates/pre-delete-job.yaml +++ b/deployment/helm/templates/pre-delete-job.yaml @@ -28,9 +28,14 @@ spec: serviceAccountName: akri-helm-cleanup-hook-sa containers: - name: delete-configurations - image: curlimages/curl:latest + image: bitnami/kubectl:latest command: ["/bin/sh", "-c"] - args: [ - "curl -ik -X DELETE -H \"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)\" https://kubernetes.default.svc.cluster.local/apis/akri.sh/v0/namespaces/{{ .Release.Namespace }}/configurations" - ] + args: + - | + kubectl delete configurations.akri.sh --all --all-namespaces; + until [ "$(kubectl get configurations.akri.sh --all-namespaces --no-headers | wc -l)" -eq "0" ]; do + echo "Waiting for all configurations to be deleted..."; + sleep 5; + done; + echo "All configurations have been deleted."; {{- end }} \ No newline at end of file diff --git a/deployment/helm/templates/rbac.yaml b/deployment/helm/templates/rbac.yaml index 99331213d..034bff54c 100644 --- a/deployment/helm/templates/rbac.yaml +++ b/deployment/helm/templates/rbac.yaml @@ -106,9 +106,9 @@ metadata: labels: app.kubernetes.io/component: helm-hook rules: -- apiGroups: ["akri.sh"] +- apiGroups: [{{ .Values.crds.group | quote }}] resources: ["configurations"] - verbs: ["deletecollection"] + verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"] --- apiVersion: 'rbac.authorization.k8s.io/v1' kind: 'ClusterRoleBinding'