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

Fix Helm chart service labels #615

Merged
merged 1 commit into from
Apr 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Common labels
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/component: {{ .Release.Name }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify that my understanding of this change: the bug previously was that component was set to aws-node-termination-handler, which is not correct. The value should have been daemonset or deployment (depending on the way NTH runs in the cluster). Your solution is to remove this from the generic labels and instead assign it in the supersets of labels called labelsDeployment and labelsDaemonset, and then to use the unrelated selectorLabelsDeployment for the service monitor template, which separately sets component to deployment.

Do I understand correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct. When I refactored the chart I accidentally left the component in the main labels function and forgot to add the component labels functions. Without these functions the component was incorrectly set in the resource labels but the only bug would be the ServiceMonitor as that's the only selector working on these labels.

app.kubernetes.io/part-of: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "aws-node-termination-handler.chart" . }}
Expand All @@ -57,6 +56,22 @@ helm.sh/chart: {{ include "aws-node-termination-handler.chart" . }}
{{- end }}
{{- end -}}

{{/*
Deployment labels
*/}}
{{- define "aws-node-termination-handler.labelsDeployment" -}}
{{ include "aws-node-termination-handler.labels" . }}
app.kubernetes.io/component: deployment
{{- end -}}

{{/*
Daemonset labels
*/}}
{{- define "aws-node-termination-handler.labelsDaemonset" -}}
{{ include "aws-node-termination-handler.labels" . }}
app.kubernetes.io/component: daemonset
{{- end -}}

{{/*
Selector labels
*/}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: {{ include "aws-node-termination-handler.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "aws-node-termination-handler.labels" . | nindent 4 }}
{{- include "aws-node-termination-handler.labelsDaemonset" . | nindent 4 }}
spec:
{{- with .Values.updateStrategy }}
updateStrategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: {{ include "aws-node-termination-handler.fullnameWindows" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "aws-node-termination-handler.labels" . | nindent 4 }}
{{- include "aws-node-termination-handler.labelsDaemonset" . | nindent 4 }}
spec:
{{- with .Values.updateStrategy }}
updateStrategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: {{ include "aws-node-termination-handler.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "aws-node-termination-handler.labels" . | nindent 4 }}
{{- include "aws-node-termination-handler.labelsDeployment" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas }}
{{- with .Values.strategy }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: {{ include "aws-node-termination-handler.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "aws-node-termination-handler.labels" . | nindent 4 }}
{{- include "aws-node-termination-handler.labelsDeployment" . | nindent 4 }}
spec:
type: ClusterIP
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ spec:
{{- end }}
selector:
matchLabels:
{{- include "aws-node-termination-handler.labels" . | nindent 6 }}
{{- include "aws-node-termination-handler.selectorLabelsDeployment" . | nindent 6 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is defined here, for reference:

{{- define "aws-node-termination-handler.selectorLabelsDeployment" -}}
{{ include "aws-node-termination-handler.selectorLabels" . }}
app.kubernetes.io/component: deployment
{{- end -}}

The important point is that it defines component to be deployment.

{{- end -}}