1+ { {/* vim: set filetype= mustache: */} }
12{ {/*
23Expand the name of the chart.
34*/} }
@@ -11,41 +12,260 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
1112If release name contains chart name it will be used as a full name.
1213*/} }
1314{ {- define " nvidia-device-plugin.fullname" -} }
14- {{- if .Values.fullnameOverride }}
15- {{- .Values.fullnameOverride | trunc 63 | trimSuffix " -" }}
16- {{- else }}
17- {{- $name := default .Chart.Name .Values.nameOverride }}
18- {{- if contains $name .Release.Name }}
19- {{- .Release.Name | trunc 63 | trimSuffix " -" }}
20- {{- else }}
21- {{- printf " %s -%s " .Release.Name $name | trunc 63 | trimSuffix " -" }}
22- {{- end }}
23- {{- end }}
24- {{- end }}
15+ { {- if .Values.fullnameOverride -} }
16+ { {- .Values.fullnameOverride | trunc 63 | trimSuffix " -" -} }
17+ { {- else -} }
18+ { {- $name := default .Chart.Name .Values.nameOverride -} }
19+ { {- if contains $name .Release.Name -} }
20+ { {- .Release.Name | trunc 63 | trimSuffix " -" -} }
21+ { {- else -} }
22+ { {- printf " %s-%s" .Release.Name $name | trunc 63 | trimSuffix " -" -} }
23+ { {- end -} }
24+ { {- end -} }
25+ { {- end -} }
26+
27+ { {/*
28+ Allow the release namespace to be overridden for multi-namespace deployments in combined charts
29+ */} }
30+ { {- define " nvidia-device-plugin.namespace" -} }
31+ { {- if .Values.namespaceOverride -} }
32+ { {- .Values.namespaceOverride -} }
33+ { {- else -} }
34+ { {- .Release.Namespace -} }
35+ { {- end -} }
36+ { {- end -} }
2537
2638{ {/*
2739Create chart name and version as used by the chart label.
2840*/} }
2941{ {- define " nvidia-device-plugin.chart" -} }
30- {{- printf " %s -%s " .Chart.Name .Chart.Version | replace " +" " _" | trunc 63 | trimSuffix " -" }}
42+ { {- $name := default .Chart.Name .Values.nameOverride -} }
43+ { {- printf " %s-%s" $name .Chart.Version | replace " +" " _" | trunc 63 | trimSuffix " -" } }
3144{ {- end } }
3245
3346{ {/*
3447Common labels
3548*/} }
3649{ {- define " nvidia-device-plugin.labels" -} }
3750helm.sh/chart: { { include " nvidia-device-plugin.chart" . } }
38- {{ include " nvidia-device-plugin.selectorLabels " . }}
51+ { { include " nvidia-device-plugin.templateLabels " . } }
3952{ {- if .Chart.AppVersion } }
4053app.kubernetes.io/version: { { .Chart.AppVersion | quote } }
4154{ {- end } }
4255app.kubernetes.io/managed-by: { { .Release.Service } }
4356{ {- end } }
4457
4558{ {/*
46- Selector labels
59+ Template labels
4760*/} }
48- {{- define " nvidia-device-plugin.selectorLabels " -}}
61+ { {- define " nvidia-device-plugin.templateLabels " -} }
4962app.kubernetes.io/name: { { include " nvidia-device-plugin.name" . } }
5063app.kubernetes.io/instance: { { .Release.Name } }
51- {{- end }}
64+ { {- if .Values.selectorLabelsOverride } }
65+ { { toYaml .Values.selectorLabelsOverride } }
66+ { {- end } }
67+ { {- end } }
68+
69+ { {/*
70+ Selector labels
71+ */} }
72+ { {- define " nvidia-device-plugin.selectorLabels" -} }
73+ { {- if .Values.selectorLabelsOverride -} }
74+ { { toYaml .Values.selectorLabelsOverride } }
75+ { {- else -} }
76+ { { include " nvidia-device-plugin.templateLabels" . } }
77+ { {- end } }
78+ { {- end } }
79+
80+ { {/*
81+ Full image name with tag
82+ */} }
83+ { {- define " nvidia-device-plugin.fullimage" -} }
84+ { {- $tag := printf " v%s" .Chart.AppVersion } }
85+ { {- .Values.image.repository -} }:{ {- .Values.image.tag | default $tag -} }
86+ { {- end } }
87+
88+ { {/*
89+ Security context for the plugin
90+ */} }
91+ { {- define " nvidia-device-plugin.securityContext" -} }
92+ { {- if ne (len .Values.securityContext) 0 -} }
93+ { { toYaml .Values.securityContext } }
94+ { {- else if .Values.compatWithCPUManager -} }
95+ privileged: true
96+ { {- else if eq (include " nvidia-device-plugin.requiresCapSysAdmin" .) " true" -} }
97+ capabilities:
98+ add:
99+ - SYS_ADMIN
100+ { {- else -} }
101+ allowPrivilegeEscalation: false
102+ capabilities:
103+ drop: ["ALL"]
104+ { {- end -} }
105+ { {- end -} }
106+
107+ { {/*
108+ Security context for GFD
109+ */} }
110+ { {- define " gpu-feature-discovery.securityContext" -} }
111+ { {- if ne (len .Values.gfd.securityContext) 0 -} }
112+ { { toYaml .Values.gfd.securityContext } }
113+ { {- else if eq (include " nvidia-device-plugin.requiresCapSysAdmin" .) " true" -} }
114+ capabilities:
115+ add:
116+ - SYS_ADMIN
117+ { {- else -} }
118+ allowPrivilegeEscalation: false
119+ capabilities:
120+ drop: ["ALL"]
121+ { {- end -} }
122+ { {- end -} }
123+
124+ { {/*
125+ Check whether the SYS_ADMIN capability should be included.
126+ */} }
127+ { {- define " nvidia-device-plugin.requiresCapSysAdmin" -} }
128+ { {- $result := false -} }
129+ { {- if ne (include " nvidia-device-plugin.allPossibleMigStrategiesAreNone" .) " true" -} }
130+ { {- $result = true -} }
131+ { {- else if eq (include " nvidia-device-plugin.deviceListStrategyIncludesVolumeMount" .) " true" -} }
132+ { {- $result = true -} }
133+ { {- end -} }
134+ { {- $result -} }
135+ { {- end -} }
136+
137+ { {/*
138+ Check if migStrategy (from all possible configurations) is " none"
139+ */} }
140+ { {- define " nvidia-device-plugin.allPossibleMigStrategiesAreNone" -} }
141+ { {- $result := true -} }
142+ { {- if .Values.migStrategy -} }
143+ { {- if ne .Values.migStrategy " none" -} }
144+ { {- $result = false -} }
145+ { {- end -} }
146+ { {- else if eq (include " nvidia-device-plugin.hasConfigMap" .) " true" -} }
147+ { {- $result = false -} }
148+ { {- else -} }
149+ { {- range $name , $contents := $.Values.config.map -} }
150+ { {- $config := $contents | fromYaml -} }
151+ { {- if $config .flags -} }
152+ { {- if ne $config .flags.migStrategy " none" -} }
153+ { {- $result = false -} }
154+ { {- end -} }
155+ { {- end -} }
156+ { {- end -} }
157+ { {- end -} }
158+ { {- $result -} }
159+ { {- end } }
160+
161+ { {/*
162+ Check if volume-mounts is included in the set of device-list-strategies
163+ */} }
164+ { {- define " nvidia-device-plugin.deviceListStrategyIncludesVolumeMount" -} }
165+ { {- $result := false -} }
166+ { {- if .Values.deviceListStrategy -} }
167+ { {- $result = ( contains " volume-mounts" .Values.deviceListStrategy ) -} }
168+ { {- else if eq (include " nvidia-device-plugin.hasConfigMap" .) " true" -} }
169+ { {- $result = true -} }
170+ { {- else -} }
171+ { {- range $name , $contents := $.Values.config.map -} }
172+ { {- $config := $contents | fromYaml -} }
173+ { {- if $config .flags -} }
174+ { {- if $config .flags.plugin -} }
175+ { {- if typeIs " string" $config .flags.plugin.deviceListStrategy } }
176+ { {- $result = ( contains " volume-mounts" $config .flags.plugin.deviceListStrategy ) -} }
177+ { {- else if typeIs " list" $config .flags.plugin.deviceListStrategy } }
178+ { {- $result = ( has " volume-mounts" $config .flags.plugin.deviceListStrategy ) -} }
179+ { {- end -} }
180+ { {- end -} }
181+ { {- end -} }
182+ { {- end -} }
183+ { {- end -} }
184+ { {- $result -} }
185+ { {- end } }
186+
187+ { {/*
188+ Check if an explicit set of configs has been provided or not
189+ */} }
190+ { {- define " nvidia-device-plugin.hasEmbeddedConfigMap" -} }
191+ { {- $result := true -} }
192+ { {- if empty .Values.config.map -} }
193+ { {- $result = false -} }
194+ { {- end -} }
195+ { {- $result -} }
196+ { {- end } }
197+
198+ { {/*
199+ Check if there is a ConfigMap in use or not
200+ */} }
201+ { {- define " nvidia-device-plugin.hasConfigMap" -} }
202+ { {- $result := false -} }
203+ { {- if ne (include " nvidia-device-plugin.configMapName" .) " " -} }
204+ { {- $result = true -} }
205+ { {- end -} }
206+ { {- $result -} }
207+ { {- end } }
208+
209+ { {/*
210+ Get the name of the default configuration
211+ */} }
212+ { {- define " nvidia-device-plugin.hasDefaultConfig" -} }
213+ { {- $result := " false" -} }
214+ { {- if .Values.config.default -} }
215+ { {- $result = " true" -} }
216+ { {- else if not (empty .Values.config.map) -} }
217+ { {- if has " named" .Values.config.fallbackStrategies -} }
218+ { {- if hasKey .Values.config.map " default" -} }
219+ { {- $result = " true" -} }
220+ { {- end -} }
221+ { {- end -} }
222+ { {- if has " single" .Values.config.fallbackStrategies -} }
223+ { {- if eq (.Values.config.map | keys | len) 1 -} }
224+ { {- $result = " true" -} }
225+ { {- end -} }
226+ { {- end -} }
227+ { {- if has " empty" .Values.config.fallbackStrategies -} }
228+ { {- $result = " true" -} }
229+ { {- end -} }
230+ { {- end -} }
231+ { {- $result -} }
232+ { {- end } }
233+
234+ { {/*
235+ Get the name of the configmap to use
236+ */} }
237+ { {- define " nvidia-device-plugin.configMapName" -} }
238+ { {- $result := " " -} }
239+ { {- if .Values.config.name -} }
240+ { {- $result = .Values.config.name -} }
241+ { {- else if not (empty .Values.config.map) -} }
242+ { {- $result = printf " %s-%s" (include " nvidia-device-plugin.fullname" .) " configs" -} }
243+ { {- end -} }
244+ { {- $result -} }
245+ { {- end -} }
246+
247+ { {/*
248+ Pod annotations for the plugin and GFD
249+ */} }
250+ { {- define " nvidia-device-plugin.podAnnotations" -} }
251+ { {- $annotations := deepCopy .local.Values.podAnnotations -} }
252+ { {- if not (hasKey $annotations " checksum/config" ) -} }
253+ { {- if eq (include " nvidia-device-plugin.hasEmbeddedConfigMap" .root) " true" -} }
254+ { {- $_ := set $annotations " checksum/config" (include (print $.root.Template.BasePath " /configmap.yml" ) .root | sha256sum) -} }
255+ { {- end -} }
256+ { {- end -} }
257+ { {- toYaml $annotations } }
258+ { {- end -} }
259+
260+
261+ { {/*
262+ Collection of typed options for the device plugin.
263+
264+ We convert this to JSON so that it can be included and converted to an object using fromJson.
265+ */} }
266+ { {- define " nvidia-device-plugin.options" -} }
267+ { {- $options := dict " " " " -} }
268+ { {- $_ := set $options " hasConfigMap" ( eq ( (include " nvidia-device-plugin.hasConfigMap" . ) | trim ) " true" ) -} }
269+ { {- $_ := set $options " addMigMonitorDevices" ( ne ( (include " nvidia-device-plugin.allPossibleMigStrategiesAreNone" . ) | trim ) " true" ) -} }
270+ { {- mustToJson $options -} }
271+ { {- end -} }
0 commit comments