Skip to content

Commit

Permalink
Merge pull request #717 from kate-goldenring/helm-delete-configs-hook
Browse files Browse the repository at this point in the history
Add Helm pre-delete hook to remove configurations before Akri chart c…
  • Loading branch information
kate-goldenring authored Nov 11, 2024
2 parents d456ca3 + 396b398 commit edc2803
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 90 deletions.
434 changes: 349 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.13.7"
version = "0.13.8"
edition = "2021"
license = "Apache-2.0"
homepage = "https://docs.akri.sh/"
Expand Down
4 changes: 2 additions & 2 deletions deployment/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.13.7
version: 0.13.8

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.13.7
appVersion: 0.13.8
36 changes: 36 additions & 0 deletions deployment/helm/templates/pre-delete-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.cleanupHook.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-cleanup"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app.kubernetes.io/component: helm-hook
spec:
restartPolicy: Never
serviceAccountName: akri-helm-cleanup-hook-sa
containers:
- name: delete-configurations
image: bitnami/kubectl:latest
command: ["/bin/sh", "-c"]
args: [
"kubectl delete configurations.akri.sh --all --all-namespaces --wait"
]
{{- end }}
35 changes: 35 additions & 0 deletions deployment/helm/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,39 @@ subjects:
- kind: 'ServiceAccount'
name: 'akri-agent-sa'
namespace: {{ .Release.Namespace }}
{{- if .Values.cleanupHook.enabled }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: akri-helm-cleanup-hook-sa
labels:
app.kubernetes.io/component: helm-hook
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: "akri-helm-cleanup-hook-role"
labels:
app.kubernetes.io/component: helm-hook
rules:
- apiGroups: [{{ .Values.crds.group | quote }}]
resources: ["configurations"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"]
---
apiVersion: 'rbac.authorization.k8s.io/v1'
kind: 'ClusterRoleBinding'
metadata:
name: "akri-helm-cleanup-hook-binding"
labels:
app.kubernetes.io/component: helm-hook
roleRef:
apiGroup: ''
kind: 'ClusterRole'
name: 'akri-helm-cleanup-hook-role'
subjects:
- kind: 'ServiceAccount'
name: 'akri-helm-cleanup-hook-sa'
namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions deployment/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ useDevelopmentContainers: true
# This can be set from the helm command line using `--set imagePullSecrets[0].name="mysecret"`
imagePullSecrets: []

cleanupHook:
# enabled defines whether to enable the Helm pre-delete hook to cleanup
# Configurations during chart deletion. Also applies associated RBAC for the
# hook. More information on Helm hooks:
# https://helm.sh/docs/topics/charts_hooks/
enabled: true

# generalize references to `apiGroups` and `apiVersion` values for Akri CRDs
crds:
group: akri.sh
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/onvif/src/discovery_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub mod util {
/// Get SOAP probe message with a specific message id
fn get_expected_probe_message(message_id: &str) -> String {
format!(
"<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"><w:MessageID>{}</w:MessageID><w:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action>http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></s:Header><s:Body xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\"><d:Probe><d:Types>netwsdl:NetworkVideoTransmitter</d:Types></d:Probe></s:Body></s:Envelope>",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"><w:MessageID>{}</w:MessageID><w:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action>http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></s:Header><s:Body xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\"><d:Probe><d:Types>netwsdl:NetworkVideoTransmitter</d:Types></d:Probe></s:Body></s:Envelope>",
&message_id)
}

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.7
0.13.8

0 comments on commit edc2803

Please sign in to comment.