Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Helm pre-delete hook to remove configurations before Akri chart c… #717

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
kate-goldenring marked this conversation as resolved.
Show resolved Hide resolved
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
Loading