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

Added labels following helm best practises #1783

Merged
merged 4 commits into from
Jun 17, 2020
Merged

Added labels following helm best practises #1783

merged 4 commits into from
Jun 17, 2020

Conversation

fjagugar
Copy link
Contributor

@fjagugar fjagugar commented Jun 8, 2020

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.

Copy link
Contributor

@andresmgot andresmgot left a 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 }}
Copy link
Contributor

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?

Copy link
Contributor

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).

Copy link
Contributor Author

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.

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 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 }}
Copy link
Contributor

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?

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, 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.

Copy link
Contributor Author

@fjagugar fjagugar left a 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 }}
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, 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 }}
Copy link
Contributor Author

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.

@fjagugar
Copy link
Contributor Author

fjagugar commented Jun 9, 2020

I've created a diff on the template generated using helm template before and after the changes:

template_differential.txt

Copy link
Contributor

@andresmgot andresmgot left a 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 }}
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 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" -}}
Copy link
Contributor

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?

@fjagugar
Copy link
Contributor Author

New template diff generated:
template_differential.txt

Copy link
Contributor

@andresmgot andresmgot left a 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

@andresmgot andresmgot merged commit 7bca52b into vmware-tanzu:master Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants