-
Notifications
You must be signed in to change notification settings - Fork 710
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
Added labels following helm best practises #1783
Conversation
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.
Thanks for adding the new labels @fjagugar! I have some suggestions to make this easier.
Apart from that, I believe adding labels is backward compatible but can you confirm if adding the labels doesn't break the upgrade? (If you can run helm upgrade ./chart/kubeapps ...
without errors, that should be enough). We are in the process of adding a test for this in the CI but is not ready yet.
@@ -39,6 +39,8 @@ app: {{ include "kubeapps.name" . }} | |||
chart: {{ include "kubeapps.chart" . }} | |||
release: {{ .Release.Name }} | |||
heritage: {{ .Release.Service }} | |||
helm.sh/chart: {{ template "kubeapps.chart" . }} | |||
app.kubernetes.io/instance: {{ .Release.Name }} |
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.
Can you also add the other two annotations that are recommended: app.kubernetes.io/name
and app.kubernetes.io/managed-by
?
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.
Also, I see that these labels are defined in the _helpers.tpl
file too:
{{/*
Common labels
*/}}
{{- define "kubeapps.labels" -}}
app: {{ include "kubeapps.name" . }}
chart: {{ include "kubeapps.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- end -}}
We can add the new labels there and simply use the helper everywhere (to avoid having to add the labels one by one).
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.
I see that not all the labels added in all the cases use the same parameters. It seem the app/app.kubernetes.io/name
usually changes.
I've created a new template that adds all the labels that are common except those two ones and used it wherever those labels were the same.
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.
🤦 this is a bit of a mess (our fault). I guess app
should have been always the same but we changed it in several places and now we cannot fix it without making it a breaking change.
From the definition in the docs: app.kubernetes.io/name: This should be the app name, reflecting the entire app. Usually {{ template "name" . }} is used for this. This is used by many Kubernetes manifests, and is not Helm-specific.
. Can we at least have a common app.kubernetes.io/name
? We can move that new label to the common group.
@@ -47,6 +49,7 @@ Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector | |||
{{- define "kubeapps.matchLabels" -}} | |||
app: {{ include "kubeapps.name" . }} | |||
release: {{ .Release.Name }} | |||
app.kubernetes.io/instance: {{ .Release.Name }} |
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.
here you are just adding one of the labels, is that intentional?
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.
Yes, as this did not had the chart
tag before. I'm only adding the app.kubernetes.io/instance
which is the equivalent to the release
one.
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.
Apart from that, I believe adding labels is backward compatible but can you confirm if adding the labels doesn't break the upgrade? (If you can run helm upgrade ./chart/kubeapps ... without errors, that should be enough). We are in the process of adding a test for this in the CI but is not ready yet.
I tested and the upgrade seems to work without issues.
@@ -47,6 +49,7 @@ Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector | |||
{{- define "kubeapps.matchLabels" -}} | |||
app: {{ include "kubeapps.name" . }} | |||
release: {{ .Release.Name }} | |||
app.kubernetes.io/instance: {{ .Release.Name }} |
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.
Yes, as this did not had the chart
tag before. I'm only adding the app.kubernetes.io/instance
which is the equivalent to the release
one.
@@ -39,6 +39,8 @@ app: {{ include "kubeapps.name" . }} | |||
chart: {{ include "kubeapps.chart" . }} | |||
release: {{ .Release.Name }} | |||
heritage: {{ .Release.Service }} | |||
helm.sh/chart: {{ template "kubeapps.chart" . }} | |||
app.kubernetes.io/instance: {{ .Release.Name }} |
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.
I see that not all the labels added in all the cases use the same parameters. It seem the app/app.kubernetes.io/name
usually changes.
I've created a new template that adds all the labels that are common except those two ones and used it wherever those labels were the same.
I've created a diff on the template generated using |
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.
Thanks for the careful update @fjagugar ! I think we can clean it up a little bit more.
@@ -39,6 +39,8 @@ app: {{ include "kubeapps.name" . }} | |||
chart: {{ include "kubeapps.chart" . }} | |||
release: {{ .Release.Name }} | |||
heritage: {{ .Release.Service }} | |||
helm.sh/chart: {{ template "kubeapps.chart" . }} | |||
app.kubernetes.io/instance: {{ .Release.Name }} |
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.
🤦 this is a bit of a mess (our fault). I guess app
should have been always the same but we changed it in several places and now we cannot fix it without making it a breaking change.
From the definition in the docs: app.kubernetes.io/name: This should be the app name, reflecting the entire app. Usually {{ template "name" . }} is used for this. This is used by many Kubernetes manifests, and is not Helm-specific.
. Can we at least have a common app.kubernetes.io/name
? We can move that new label to the common group.
@@ -47,6 +59,9 @@ Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector | |||
{{- define "kubeapps.matchLabels" -}} |
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.
I see this matchLabels
is not used anywhere. Can we delete it?
New template diff generated: |
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.
Thanks for the changes
Description of the change
Adds labels to chart templates using the Helm best practises: https://helm.sh/docs/chart_best_practices/labels/#standard-labels
Benefits
Tools already using the label syntax encouraged by Helm will now be able to use that syntax with kubapps.
Possible drawbacks
Only added new tags. Old tags have not been removed for backward compatibility.