Skip to content

Commit 889fffd

Browse files
committed
helm: add post-delete hook that cleans up the node
This patch adds a post-delete hook to the Helm chart that runs "nfd-master --prune" in the cluster. This cleans up the node of labels, annotations, taints and extended resources that were created by NFD.
1 parent 456a77b commit 889fffd

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ include "node-feature-discovery.master.serviceAccountName" . }}-prune
5+
namespace: {{ include "node-feature-discovery.namespace" . }}
6+
labels:
7+
{{- include "node-feature-discovery.labels" . | nindent 4 }}
8+
annotations:
9+
"helm.sh/hook": post-delete
10+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
11+
---
12+
apiVersion: rbac.authorization.k8s.io/v1
13+
kind: ClusterRole
14+
metadata:
15+
name: {{ include "node-feature-discovery.fullname" . }}-prune
16+
labels:
17+
{{- include "node-feature-discovery.labels" . | nindent 4 }}
18+
annotations:
19+
"helm.sh/hook": post-delete
20+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
21+
rules:
22+
- apiGroups:
23+
- ""
24+
resources:
25+
- nodes
26+
- nodes/status
27+
verbs:
28+
- get
29+
- patch
30+
- update
31+
- list
32+
---
33+
apiVersion: rbac.authorization.k8s.io/v1
34+
kind: ClusterRoleBinding
35+
metadata:
36+
name: {{ include "node-feature-discovery.fullname" . }}-prune
37+
labels:
38+
{{- include "node-feature-discovery.labels" . | nindent 4 }}
39+
annotations:
40+
"helm.sh/hook": post-delete
41+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
42+
roleRef:
43+
apiGroup: rbac.authorization.k8s.io
44+
kind: ClusterRole
45+
name: {{ include "node-feature-discovery.fullname" . }}-prune
46+
subjects:
47+
- kind: ServiceAccount
48+
name: {{ include "node-feature-discovery.fullname" . }}-prune
49+
namespace: {{ include "node-feature-discovery.namespace" . }}
50+
---
51+
apiVersion: batch/v1
52+
kind: Job
53+
metadata:
54+
name: {{ include "node-feature-discovery.fullname" . }}-prune
55+
namespace: {{ include "node-feature-discovery.namespace" . }}
56+
labels:
57+
{{- include "node-feature-discovery.labels" . | nindent 4 }}
58+
annotations:
59+
"helm.sh/hook": post-delete
60+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
61+
spec:
62+
template:
63+
metadata:
64+
labels:
65+
{{- include "node-feature-discovery.labels" . | nindent 8 }}
66+
role: prune
67+
spec:
68+
serviceAccountName: {{ include "node-feature-discovery.fullname" . }}-prune
69+
containers:
70+
- name: nfd-master
71+
securityContext:
72+
{{- toYaml .Values.master.securityContext | nindent 12 }}
73+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
74+
imagePullPolicy: {{ .Values.image.pullPolicy }}
75+
command:
76+
- "nfd-master"
77+
args:
78+
- "-prune"
79+
{{- if .Values.master.instance | empty | not }}
80+
- "-instance={{ .Values.master.instance }}"
81+
{{- end }}
82+
restartPolicy: Never
83+
{{- with .Values.master.nodeSelector }}
84+
nodeSelector:
85+
{{- toYaml . | nindent 8 }}
86+
{{- end }}
87+
{{- with .Values.master.affinity }}
88+
affinity:
89+
{{- toYaml . | nindent 8 }}
90+
{{- end }}
91+
{{- with .Values.master.tolerations }}
92+
tolerations:
93+
{{- toYaml . | nindent 8 }}
94+
{{- end }}

docs/deployment/helm.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ helm uninstall node-feature-discovery --namespace $NFD_NS
7575
```
7676

7777
The command removes all the Kubernetes components associated with the chart and
78-
deletes the release.
78+
deletes the release. It also runs a post-delete hook that cleans up the nodes
79+
of all labels, annotations, taints and extended resources that were created by
80+
NFD.
7981

8082
## Chart parameters
8183

docs/deployment/uninstallation.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Follow the uninstallation instructions of the deployment method used
1616

1717
## Removing feature labels
1818

19+
> **NOTE:** This is unnecessary when using the Helm chart for deployment as it
20+
> will clean up the nodes when NFD is uninstalled.
21+
1922
NFD-Master has a special `-prune` command line flag for removing all
2023
nfd-related node labels, annotations, extended resources and taints from the
2124
cluster.

0 commit comments

Comments
 (0)