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

[CN-993] Common label and annotation parameters for all deployed objects #388

Merged
merged 7 commits into from
Oct 18, 2023

Conversation

semihbkgr
Copy link
Contributor

@semihbkgr semihbkgr commented Sep 19, 2023

provides a way to add common labels and annotations to all objects deployed by the chart

# Labels to add to all deployed objects
commonLabels: {}

# Annotations to add to all deployed objects
commonAnnotations: {}

Implementation Notes

To merge two maps, we are using merge function. eg:

merge nil .Values.mancenter.ingress.annotations .Values.commonAnnotations

The reason why we are passing nil to the first parameter of merge function is to keep the maps immutable.

$newdict := merge $dest $source1 $source2

The first parameter of the merge function is destination. The new merging entries are put into the destination map.

https://helm.sh/docs/chart_template_guide/function_list/#merge-mustmerge

We are passing nil as a destination map in order to not modify any of our existing map. In this way, the maps generated from the values.yaml and user args are not modified during the render process of templates.

@hasancelik hasancelik requested review from a team and dzeromski-hazelcast and removed request for a team September 19, 2023 11:55
@@ -8,6 +8,15 @@ metadata:
helm.sh/chart: {{ template "hazelcast.chart" . }}
app.kubernetes.io/instance: "{{ .Release.Name }}"
app.kubernetes.io/managed-by: "{{ .Release.Service }}"
{{- range $key, $value := .Values.commonLabels }}
Copy link
Contributor

@dzeromski-hazelcast dzeromski-hazelcast Sep 19, 2023

Choose a reason for hiding this comment

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

Could we use template to avoid repeating loop in every template?

We do something similar in our operator helm chart:

  labels:
    {{- include "hazelcast-platform-operator.labels" . | nindent 4 }}

and define it in https://github.com/hazelcast/charts/blob/master/stable/hazelcast-platform-operator/templates/_helpers.tpl#L33

Copy link
Contributor Author

@semihbkgr semihbkgr Sep 20, 2023

Choose a reason for hiding this comment

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

I was planning to refactor it in a separate PR. We are duplicating default labels in all templates as well.

@semihbkgr semihbkgr merged commit 037da7e into master Oct 18, 2023
2 checks passed
@semihbkgr semihbkgr deleted the common-label-annotation branch October 18, 2023 10:25
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.

3 participants