-
Notifications
You must be signed in to change notification settings - Fork 98
Use per-component matchLabels selector in pod specs (fix #355) #359
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,36 +43,47 @@ Create chart name and version as used by the chart label. | |
| {{- end }} | ||
|
|
||
| {{/* | ||
| Common labels | ||
| Standard labels: documented at | ||
| https://helm.sh/docs/chart_best_practices/labels/ | ||
| Apply this to all high-level objects (Deployment, DaemonSet, ...). | ||
| Pod template labels are included here to deliver name+instance. | ||
| */}} | ||
| {{- define "nvidia-dra-driver-gpu.labels" -}} | ||
| helm.sh/chart: {{ include "nvidia-dra-driver-gpu.chart" . }} | ||
| {{ include "nvidia-dra-driver-gpu.templateLabels" . }} | ||
| {{- if .Chart.AppVersion }} | ||
| app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
| {{- end }} | ||
| app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
| {{ include "nvidia-dra-driver-gpu.templateLabels" . }} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Template labels | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly allergic to a thing named |
||
| Apply this to all pod templates (a smaller set of labels compared to | ||
| the set of standard labels above, to not clutter individual pods too | ||
| much). Note that these labels cannot be used to distinguish | ||
| components within this Helm chart. | ||
| */}} | ||
| {{- define "nvidia-dra-driver-gpu.templateLabels" -}} | ||
| app.kubernetes.io/name: {{ include "nvidia-dra-driver-gpu.name" . }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| {{- if .Values.selectorLabelsOverride }} | ||
| {{ toYaml .Values.selectorLabelsOverride }} | ||
| {{- end }} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the selector label (single label, I propose) strictly independent. "Template labels" I believe always meant "pod template labels" and I think it really always meant "apply a common set of labels to all pods of this Helm chart". By that nature, this set of labels cannot distinguish individual groups of pods within the Helm chart. Which is what "selector labels" want to do. In that sense, those two concepts (template labels and selector labels) are generally incompatible. Which goes unnoticed for the special case of there being just one component (one relevant group of pods) in the Helm chart. |
||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Selector labels | ||
| Selector label: precisely filter for just the pods of the corresponding | ||
| Deployment, DaemonSet, .... That is, this label key/value pair must be | ||
| different per-component (a component name is a required argument). This | ||
| could be many labels, but we want to use just one (with a sufficiently | ||
| unique key). | ||
|
|
||
| TOOD: remove the override feature, or make the override work per-component. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove the override before GA? @klueska do we know of anyone with SPECIFIC selector labels? |
||
| */}} | ||
| {{- define "nvidia-dra-driver-gpu.selectorLabels" -}} | ||
| {{- if .Values.selectorLabelsOverride -}} | ||
| {{ toYaml .Values.selectorLabelsOverride }} | ||
| {{- if and (hasKey . "componentName") (hasKey . "context") -}} | ||
| {{- if .context.Values.selectorLabelsOverride -}} | ||
| {{ toYaml .context.Values.selectorLabelsOverride }} | ||
| {{- else -}} | ||
| {{ include "nvidia-dra-driver-gpu.templateLabels" . }} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need the template labels in the selector labels. The current logic will write something like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for looking deeply. Very appreciated. I will review this more carefully tomorrow. I want to understand use cases that we want to support, and then remove complexity that is not currently needed. (this nifty setup will have to be documented better so that it can survive if it must survive!) Based on what I understand today, I don't think that template labels and selector labels should be entangled. I think template labels, as far as I understood, are just labels added to any and all component deployed by this Helm chart. That looks good, and keeps things more or less organized. Selector labels, on the other hand, have a deep technical (and internal, for hat matter) meaning. I am not sure if we even want to let people override those. Will think about it more tomorrow.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went into history. NVIDIA/k8s-device-plugin@4820ac1#r157221509.
I think it's better to change that then, here. Will do. It's already a challenge for me to put into English words what a good distinction is between "common labels" and "template labels". I will work on that. For me, it's easier to see a clear distinction between [common labels, template labels] and [selector labels]. I want to reinforce that distinction.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a new commit with commentary declaring intent. Not perfect, but I think it's important for us to express the system that we want to use here. |
||
| {{ .context.Chart.Name }}-component: {{ .componentName }} | ||
| {{- end }} | ||
| {{- else -}} | ||
| fail "selectorLabels: both arguments are required: context, componentName" | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ spec: | |
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| {{- include "nvidia-dra-driver-gpu.selectorLabels" . | nindent 6 }} | ||
| {{- include "nvidia-dra-driver-gpu.selectorLabels" (dict "context" . "componentName" "controller") | nindent 6 }} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, I have now learned that this left-chomping-nindent-technique is the holy grail of Helm templates: helm/helm#3854 (comment) |
||
| template: | ||
| metadata: | ||
| {{- with .Values.controller.podAnnotations }} | ||
|
|
@@ -34,6 +34,7 @@ spec: | |
| {{- end }} | ||
| labels: | ||
| {{- include "nvidia-dra-driver-gpu.templateLabels" . | nindent 8 }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. That's fine. I wanted to be minimally invasive. To me, that first and foremost meant that I did not want to remove any labels.
edit: okay, changed to using the selectorLabels approach again (now it's a dynamic label)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another update:
not anymore, see commentary.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks: I think making selectorLabels more specific (and a reduced set is correct). |
||
| {{- include "nvidia-dra-driver-gpu.selectorLabels" (dict "context" . "componentName" "controller") | nindent 8 }} | ||
| spec: | ||
| {{- if .Values.controller.priorityClassName }} | ||
| priorityClassName: {{ .Values.controller.priorityClassName }} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we always define that (and if we don't, I want to know about it)