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 duplicate clustersrolebindings issue #10479

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
@@ -1,6 +1,10 @@
{{- if .Values.rbac.create -}}
{{- $root := . -}}
{{- range append .Values.watchNamespaces .Release.Namespace }}
{{- $watchNamespaces := .Values.watchNamespaces -}}
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 defined a new variable - "watchNamespaces", the default value is .Values.watchNamespaces.

{{- if $root.Values.watchAnyNamespace }}
{{- $watchNamespaces = list -}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If "watchAnyNamespace" is set to true, we will set variable watchNamespaces to empty List, and ignore the values of ".Values.watchNamespaces"

Loop over new variable($watchNamespaces) instead of ".Values.watchNamespaces"

{{- end }}
{{- range append $watchNamespaces .Release.Namespace }}
Comment on lines +3 to +7
Copy link
Member

Choose a reason for hiding this comment

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

As we are not really Helm experts, would you mind explaining (perhaps int he PR description) what exactly does this code do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure @scholzj

---
apiVersion: rbac.authorization.k8s.io/v1
{{- if $root.Values.watchAnyNamespace }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{- if .Values.rbac.create }}
{{- if .Values.rbac.create -}}
{{- $root := . -}}
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, what does the - at the end do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that we received a few empty lines in our YAML. Why? When the template engine runs, it removes the contents inside of {{ and }}, but it leaves the remaining whitespace exactly as is.

YAML ascribes meaning to whitespace, so managing the whitespace becomes pretty important. Fortunately, Helm templates have a few tools to help.
First, the curly brace syntax of template declarations can be modified with special characters to tell the template engine to chomp whitespace. {{- (with the dash and space added) indicates that whitespace should be chomped left, while -}} means whitespace to the right should be consumed. Be careful! Newlines are whitespace!

If it is the first line in a yaml file, I think it will not impact anything.
If you concern about it, I can remove - at the end.

{{- range append .Values.watchNamespaces .Release.Namespace }}
{{- $watchNamespaces := .Values.watchNamespaces -}}
{{- if $root.Values.watchAnyNamespace }}
{{- $watchNamespaces = list -}}
{{- end }}
{{- range append $watchNamespaces .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if $root.Values.watchAnyNamespace }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{- if .Values.rbac.create }}
{{- if .Values.rbac.create -}}
{{- $root := . -}}
{{- range append .Values.watchNamespaces .Release.Namespace }}
{{- $watchNamespaces := .Values.watchNamespaces -}}
{{- if $root.Values.watchAnyNamespace }}
{{- $watchNamespaces = list -}}
{{- end }}
{{- range append $watchNamespaces .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if $root.Values.watchAnyNamespace }}
Expand Down
Loading