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

[helm nats 1.x] add tlsCA option #763

Merged
merged 1 commit into from
Jul 14, 2023
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
4 changes: 4 additions & 0 deletions helm/charts/nats/files/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ gateway:
########################################
{{- with .monitor }}
{{- if .enabled }}
{{- if .tls.enabled }}
https_port: {{ .port }}
{{- else }}
http_port: {{ .port }}
{{- end }}
{{- end }}
{{- end }}

########################################
# profiling
Expand Down
13 changes: 11 additions & 2 deletions helm/charts/nats/files/config/tls.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# tls
{{- with .tls }}
{{- if .secretName }}
{{- $dir := trimSuffix "/" .dir }}
cert_file: {{ printf "%s/%s" $dir .cert }}
key_file: {{ printf "%s/%s" $dir .key }}
cert_file: {{ printf "%s/%s" $dir (.cert | default "tls.crt") | quote }}
key_file: {{ printf "%s/%s" $dir (.key | default "tls.key") | quote }}
{{- end }}
{{- end }}

# tlsCA
{{- with $.Values.tlsCA }}
{{- if and .enabled (or .configMapName .secretName) }}
{{- $dir := trimSuffix "/" .dir }}
ca_file: {{ printf "%s/%s" $dir (.key | default "ca.crt") | quote }}
{{- end }}
{{- end }}
2 changes: 0 additions & 2 deletions helm/charts/nats/files/headless-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ spec:
{{- $tlsEnabled := false }}
{{- if hasKey $configProtocol "tls" }}
{{- $tlsEnabled = $configProtocol.tls.enabled }}
{{- else if eq $protocol "monitor" }}
{{- $tlsEnabled = $.Values.config.nats.tls.enabled }}
{{- end }}
{{- $appProtocol := or (eq $protocol "websocket") (eq $protocol "monitor") | ternary ($tlsEnabled | ternary "https" "http") ($tlsEnabled | ternary "tls" "tcp") }}
- {{ dict "name" $protocol "port" $configProtocol.port "targetPort" $protocol "appProtocol" $appProtocol | toYaml | nindent 4 }}
Expand Down
16 changes: 12 additions & 4 deletions helm/charts/nats/files/nats-box/contexts-secret/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ url: nats://{{ .Values.headlessService.name }}
creds: /etc/nats-contents/{{ $contextName }}.creds
{{- else if .secretName }}
{{- $dir := trimSuffix "/" .dir }}
creds: {{ $dir }}/{{ .key }}
creds: {{ printf "%s/%s" $dir (.key | default "nats.creds") | quote }}
{{- end }}
{{- end }}

Expand All @@ -25,16 +25,24 @@ creds: {{ $dir }}/{{ .key }}
nkey: /etc/nats-contents/{{ $contextName }}.nk
{{- else if .secretName }}
{{- $dir := trimSuffix "/" .dir }}
nkey: {{ $dir }}/{{ .key }}
nkey: {{ printf "%s/%s" $dir (.key | default "nats.nk") | quote }}
{{- end }}
{{- end }}

# tls
{{- with .tls }}
{{- if .secretName }}
{{- $dir := trimSuffix "/" .dir }}
cert: {{ $dir }}/{{ .cert | default "tls.crt" }}
key: {{ $dir }}/{{ .key | default "tls.key" }}
cert: {{ printf "%s/%s" $dir (.cert | default "tls.crt") | quote }}
key: {{ printf "%s/%s" $dir (.key | default "tls.key") | quote }}
{{- end }}
{{- end }}

# tlsCA
{{- with $.Values.tlsCA }}
{{- if and .enabled (or .configMapName .secretName) }}
{{- $dir := trimSuffix "/" .dir }}
ca: {{ printf "%s/%s" $dir (.key | default "ca.crt") | quote }}
{{- end }}
{{- end }}

Expand Down
5 changes: 5 additions & 0 deletions helm/charts/nats/files/nats-box/deployment/container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ command:
args:
- trap true INT TERM; sleep infinity & wait
volumeMounts:
# contexts secret
- name: contexts
mountPath: /etc/nats-contexts
# contents secret
Copy link
Member

Choose a reason for hiding this comment

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

Should this be within the template if below? Similarly for pid stuff below?

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've been in the habit of putting comments at the beginning of conditional blocks, because it helps me see balancing of the {{- if and {{- end braces between the comments

{{- if .hasContentsSecret }}
- name: contents
mountPath: /etc/nats-contents
{{- end }}
# tlsCA
{{- include "nats.tlsCAVolumeMount" $ }}
# secrets
{{- range (include "natsBox.secretNames" $ | fromJson).secretNames }}
- name: {{ .name | quote }}
mountPath: {{ .dir | quote }}
Expand Down
2 changes: 2 additions & 0 deletions helm/charts/nats/files/nats-box/deployment/pod-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
secret:
secretName: {{ .Values.natsBox.contentsSecret.name }}
{{- end }}
# tlsCA
{{- include "nats.tlsCAVolume" $ | nindent 2 }}
# secrets
{{- range (include "natsBox.secretNames" $ | fromJson).secretNames }}
- name: {{ .name | quote }}
Expand Down
2 changes: 0 additions & 2 deletions helm/charts/nats/files/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ spec:
{{- $tlsEnabled := false }}
{{- if hasKey $configProtocol "tls" }}
{{- $tlsEnabled = $configProtocol.tls.enabled }}
{{- else if eq $protocol "monitor" }}
{{- $tlsEnabled = $.Values.config.nats.tls.enabled }}
{{- end }}
{{- $appProtocol := or (eq $protocol "websocket") (eq $protocol "monitor") | ternary ($tlsEnabled | ternary "https" "http") ($tlsEnabled | ternary "tls" "tcp") }}
- {{ merge (dict "name" $protocol "targetPort" $protocol "appProtocol" $appProtocol) (omit $servicePort "enabled") (dict "port" $configProtocol.port) | toYaml | nindent 4 }}
Expand Down
7 changes: 7 additions & 0 deletions helm/charts/nats/files/stateful-set/nats-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ livenessProbe:
{{- end }}

volumeMounts:
# nats config
- name: config
mountPath: /etc/nats-config
# PID volume
{{- if .Values.reloader.enabled }}
- name: pid
mountPath: /var/run/nats
{{- end}}
# JetStream PVC
{{- with .Values.config.jetstream }}
{{- if and .enabled .fileStore.enabled .fileStore.pvc.enabled }}
{{- with .fileStore }}
Expand All @@ -79,12 +82,16 @@ volumeMounts:
{{- end }}
{{- end }}
{{- end }}
# resolver PVC
{{- with .Values.config.resolver }}
{{- if and .enabled .pvc.enabled }}
- name: {{ .pvc.name }}
mountPath: {{ .dir | quote }}
{{- end }}
{{- end }}
# tlsCA
{{- include "nats.tlsCAVolumeMount" $ }}
# secrets
{{- range (include "nats.secretNames" $ | fromJson).secretNames }}
- name: {{ .name | quote }}
mountPath: {{ .dir | quote }}
Expand Down
2 changes: 2 additions & 0 deletions helm/charts/nats/files/stateful-set/pod-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
- name: pid
emptyDir: {}
{{- end }}
# tlsCA
{{- include "nats.tlsCAVolume" $ | nindent 2 }}
# secrets
{{- range (include "nats.secretNames" $ | fromJson).secretNames }}
- name: {{ .name | quote }}
Expand Down
24 changes: 24 additions & 0 deletions helm/charts/nats/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@ imagePullPolicy: {{ .pullPolicy | default .global.image.pullPolicy }}
{{- toJson (dict "secretNames" $secrets) }}
{{- end }}

{{- define "nats.tlsCAVolume" -}}
{{- with .Values.tlsCA }}
{{- if and .enabled (or .configMapName .secretName) }}
- name: tls-ca
{{- if .configMapName }}
configMap:
name: {{ .configMapName | quote }}
{{- else if .secretName }}
secret:
secretName: {{ .secretName | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- define "nats.tlsCAVolumeMount" -}}
{{- with .Values.tlsCA }}
{{- if and .enabled (or .configMapName .secretName) }}
- name: tls-ca
mountPath: {{ .dir | quote }}
{{- end }}
{{- end }}
{{- end }}

{{/*
translates env var map to list
*/}}
Expand Down
Loading