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

Tweak YAML rendering using common render helpers #405

Merged
merged 3 commits into from
Dec 2, 2024
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
2 changes: 1 addition & 1 deletion charts/netbox/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: netbox
version: 5.0.0-beta.151
version: 5.0.0-beta.152
appVersion: "v4.1.7"
type: application
kubeVersion: ^1.25.0-0
Expand Down
8 changes: 4 additions & 4 deletions charts/netbox/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Volumes that need to be mounted for .Values.extraConfig entries
*/}}
{{- define "netbox.extraConfig.volumes" -}}
{{- range $index, $config := .Values.extraConfig }}
- name: extra-config-{{ $index }}
- name: {{ printf "extra-config-%s" $index | quote }}
{{- if $config.values }}
configMap:
name: {{ include "common.names.fullname" $ }}
Expand All @@ -111,10 +111,10 @@ Volumes that need to be mounted for .Values.extraConfig entries
path: extra-{{ $index }}.yaml
{{- else if $config.configMap }}
configMap:
{{- toYaml $config.configMap | nindent 4 }}
{{- include "common.tplvalues.render" (dict "value" $config.configMap "context" $) | nindent 4 }}
{{- else if $config.secret }}
secret:
{{- toYaml $config.secret | nindent 4 }}
{{- include "common.tplvalues.render" (dict "value" $config.secret "context" $) | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -124,7 +124,7 @@ Volume mounts for .Values.extraConfig entries
*/}}
{{- define "netbox.extraConfig.volumeMounts" -}}
{{- range $index, $config := .Values.extraConfig }}
- name: extra-config-{{ $index }}
- name: {{ printf "extra-config-%s" $index | quote }}
mountPath: /run/config/extra/{{ $index }}
readOnly: true
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions charts/netbox/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data:
MEDIA_ROOT: /opt/netbox/netbox/media
{{- if .Values.storageBackend }}
STORAGE_BACKEND: {{ .Values.storageBackend | quote }}
STORAGE_CONFIG: {{ toJson .Values.storageConfig }}
STORAGE_CONFIG: {{ toJson .Values.storageConfig }}
{{- end }}
METRICS_ENABLED: {{ toJson .Values.metrics.enabled }}
PAGINATE_COUNT: {{ int .Values.paginateCount }}
Expand Down Expand Up @@ -208,7 +208,7 @@ data:

{{- range $index, $config := .Values.extraConfig }}
{{- if $config.values }}
extra-{{ $index }}.yaml: |-
{{- toYaml $config.values | nindent 4 }}
{{ printf "extra-%s.yaml" $index }}: |-
{{- include "common.tplvalues.render" (dict "value" $config.values "context" $) | nindent 4 }}
{{- end }}
{{- end }}
53 changes: 28 additions & 25 deletions charts/netbox/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,26 @@ spec:
spec:
template:
metadata:
{{- with .Values.housekeeping.podAnnotations }}
{{- if .Values.housekeeping.podAnnotations }}
annotations:
{{- toYaml . | nindent 12 }}
{{- include "common.tplvalues.render" ( dict "value" .Values.housekeeping.podAnnotations "context" $ ) | nindent 12 }}
{{- end }}
labels:
{{- include "common.labels.matchLabels" . | nindent 12 }}
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.housekeeping.podLabels "context" $ ) | nindent 12 }}
app.kubernetes.io/component: housekeeping
{{- with .Values.housekeeping.podLabels }}
{{- toYaml . | nindent 12 }}
{{- end }}
spec:
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image) "context" $) | nindent 10 }}
serviceAccountName: {{ include "netbox.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.housekeeping.automountServiceAccountToken }}
{{- if .Values.housekeeping.podSecurityContext.enabled }}
securityContext: {{- omit .Values.housekeeping.podSecurityContext "enabled" | toYaml | nindent 12 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.housekeeping.podSecurityContext "context" $) | nindent 12 }}
{{- end }}
{{- if .Values.housekeeping.initContainers }}
initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.housekeeping.initContainers "context" $) | trim | nindent 12 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}-housekeeping
{{- if .Values.housekeeping.securityContext.enabled }}
securityContext: {{- omit .Values.housekeeping.securityContext "enabled" | toYaml | nindent 14 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.housekeeping.securityContext "context" $) | nindent 14 }}
{{- end }}
image: {{ include "netbox.image" . | quote }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand All @@ -55,9 +51,19 @@ spec:
{{- if .Values.housekeeping.args }}
args: {{- include "common.tplvalues.render" (dict "value" .Values.housekeeping.args "context" $) | nindent 14 }}
{{- end }}
{{- with .Values.housekeeping.extraEnvs }}
env:
{{- toYaml . | nindent 12 }}
{{- if .Values.housekeeping.extraEnvs }}
env: {{- include "common.tplvalues.render" (dict "value" .Values.housekeeping.extraEnvs "context" $) | nindent 14 }}
{{- end }}
{{- if or .Values.housekeeping.extraEnvVarsCM .Values.housekeeping.extraEnvVarsSecret }}
envFrom:
{{- if .Values.housekeeping.extraEnvVarsCM }}
- configMapRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.housekeeping.extraEnvVarsCM "context" $) }}
{{- end }}
{{- if .Values.housekeeping.extraEnvVarsSecret }}
- secretRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.housekeeping.extraEnvVarsSecret "context" $) }}
{{- end }}
{{- end }}
volumeMounts:
- name: config
Expand Down Expand Up @@ -101,8 +107,8 @@ spec:
subPath: {{ .Values.scriptsPersistence.subPath | default "" | quote }}
readOnly: {{ .Values.housekeeping.readOnlyPersistence | default false }}
{{- end }}
{{- with .Values.housekeeping.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- if .Values.housekeeping.extraVolumeMounts }}
{{- include "common.tplvalues.render" (dict "value" .Values.housekeeping.extraVolumeMounts "context" $) | nindent 12 }}
{{- end }}
{{- if .Values.housekeeping.resources }}
resources: {{ toYaml .Values.housekeeping.resources | nindent 14 }}
Expand Down Expand Up @@ -169,20 +175,17 @@ spec:
claimName: {{ .Values.scriptsPersistence.existingClaim | default (printf "%s-scripts" (include "common.names.fullname" .)) }}
readOnly: {{ .Values.housekeeping.readOnlyPersistence | default false }}
{{- end }}
{{- with .Values.housekeeping.extraVolumes }}
{{- toYaml . | nindent 10 }}
{{- if .Values.housekeeping.extraVolumes }}
{{- include "common.tplvalues.render" (dict "value" .Values.housekeeping.extraVolumes "context" $) | nindent 10 }}
{{- end }}
{{- with .Values.housekeeping.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- if .Values.housekeeping.nodeSelector }}
nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.housekeeping.nodeSelector "context" $) | nindent 12 }}
{{- end }}
{{- with .Values.housekeeping.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- if .Values.housekeeping.affinity }}
affinity: {{- include "common.tplvalues.render" ( dict "value" .Values.housekeeping.affinity "context" $) | nindent 12 }}
{{- end }}
{{- with .Values.housekeeping.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- if .Values.housekeeping.tolerations }}
tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.housekeeping.tolerations "context" .) | nindent 12 }}
{{- end }}
restartPolicy: {{ .Values.housekeeping.restartPolicy }}
{{- end -}}
47 changes: 26 additions & 21 deletions charts/netbox/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,29 @@ spec:
{{- end }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
selector:
matchLabels:
{{- include "common.labels.matchLabels" . | nindent 6 }}
matchLabels: {{- include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $) | nindent 6 }}
app.kubernetes.io/component: netbox
{{- if .Values.updateStrategy }}
strategy:
{{- toYaml .Values.updateStrategy | nindent 4 }}
strategy: {{- include "common.tplvalues.render" (dict "value" .Values.updateStrategy "context" $) | nindent 4 }}
{{- end }}
template:
metadata:
annotations:
{{- if .Values.podAnnotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.podAnnotations "context" $ ) | nindent 8 }}
{{- end }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if (not .Values.existingSecret) }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "common.labels.matchLabels" . | nindent 8 }}
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.podLabels "context" $ ) | nindent 8 }}
app.kubernetes.io/component: netbox
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image) "context" $) | nindent 6 }}
serviceAccountName: {{ include "netbox.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- omit .Values.podSecurityContext "enabled" | toYaml | nindent 8 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.podSecurityContext "context" $) | nindent 8 }}
{{- end }}
initContainers:
- name: init-dirs
Expand All @@ -55,7 +49,7 @@ spec:
resources: {{- include "common.resources.preset" (dict "type" .Values.init.resourcesPreset) | nindent 10 }}
{{- end }}
{{- if .Values.init.securityContext.enabled }}
securityContext: {{- omit .Values.init.securityContext "enabled" | toYaml | nindent 10 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.init.securityContext "context" $) | nindent 10 }}
{{- end }}
volumeMounts:
- name: optunit
Expand All @@ -66,7 +60,7 @@ spec:
containers:
- name: {{ .Chart.Name }}
{{- if .Values.securityContext.enabled }}
securityContext: {{- omit .Values.securityContext "enabled" | toYaml | nindent 10 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.securityContext "context" $) | nindent 10 }}
{{- end }}
image: {{ include "netbox.image" . | quote }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand Down Expand Up @@ -95,16 +89,27 @@ spec:
- name: UNIT_CONFIG
value: /run/config/netbox/nginx-unit.json
{{- end }}
{{- with .Values.extraEnvs }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.allowedHostsIncludesPodIP }}
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
{{- end }}
{{- if .Values.extraEnvs }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraEnvs "context" $) | nindent 10 }}
{{- end }}
{{- if or .Values.extraEnvVarsCM .Values.extraEnvVarsSecret }}
envFrom:
{{- if .Values.extraEnvVarsCM }}
- configMapRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.extraEnvVarsCM "context" $) }}
{{- end }}
{{- if .Values.extraEnvVarsSecret }}
- secretRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.extraEnvVarsSecret "context" $) }}
{{- end }}
{{- end }}
ports:
- name: http
containerPort: 8080
Expand Down Expand Up @@ -202,7 +207,7 @@ spec:
{{- include "common.tplvalues.render" (dict "value" .Values.extraVolumeMounts "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.resources }}
resources: {{ toYaml .Values.resources | nindent 10 }}
resources: {{- toYaml .Values.resources | nindent 10 }}
{{- else if ne .Values.resourcesPreset "none" }}
resources: {{- include "common.resources.preset" (dict "type" .Values.resourcesPreset) | nindent 10 }}
{{- end }}
Expand Down Expand Up @@ -273,8 +278,8 @@ spec:
persistentVolumeClaim:
claimName: {{ .Values.scriptsPersistence.existingClaim | default (printf "%s-scripts" (include "common.names.fullname" .)) }}
{{- end }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- if .Values.extraVolumes }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraVolumes "context" $) | nindent 6 }}
{{- end }}
{{- if .Values.nodeSelector }}
nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/netbox/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data:
email: {{ .Values.superuser.email | b64enc | quote }}
api_token: {{ .Values.superuser.apiToken | default uuidv4 | b64enc | quote }}
{{- end }}
{{- if not (or .Values.postgresql.enabled .Values.externalDatabase.existingSecretName) }}
{{- if not (or .Values.postgresql.enabled .Values.externalDatabase.existingSecretName) }}
---
apiVersion: v1
kind: Secret
Expand Down
2 changes: 1 addition & 1 deletion charts/netbox/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ spec:
resources: {{- include "common.resources.preset" (dict "type" .Values.test.resourcesPreset) | nindent 6 }}
{{- end }}
{{- if .Values.test.securityContext.enabled }}
securityContext: {{- omit .Values.test.securityContext "enabled" | toYaml | nindent 6 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.test.securityContext "context" $) | nindent 6 }}
{{- end }}
restartPolicy: Never
46 changes: 25 additions & 21 deletions charts/netbox/templates/worker/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,37 @@ spec:
{{- end }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
selector:
matchLabels:
{{- include "common.labels.matchLabels" . | nindent 6 }}
matchLabels: {{- include "common.labels.matchLabels" (dict "customLabels" .Values.worker.podLabels "context" $) | nindent 6 }}
app.kubernetes.io/component: worker
{{- if .Values.worker.updateStrategy }}
strategy:
{{- toYaml .Values.worker.updateStrategy | nindent 4 }}
strategy: {{- include "common.tplvalues.render" (dict "value" .Values.worker.updateStrategy "context" $) | nindent 4 }}
{{- end }}
template:
metadata:
annotations:
{{- if .Values.worker.podAnnotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.worker.podAnnotations "context" $ ) | nindent 8 }}
{{- end }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if (not .Values.existingSecret) }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- end }}
{{- with .Values.worker.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "common.labels.matchLabels" . | nindent 8 }}
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.worker.podLabels "context" $ ) | nindent 8 }}
app.kubernetes.io/component: worker
{{- with .Values.worker.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image) "context" $) | nindent 6 }}
serviceAccountName: {{ include "netbox.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.worker.automountServiceAccountToken }}
{{- if .Values.worker.podSecurityContext.enabled }}
securityContext: {{- omit .Values.worker.podSecurityContext "enabled" | toYaml | nindent 8 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.worker.podSecurityContext "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.worker.initContainers }}
initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.worker.initContainers "context" $) | trim | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}-worker
{{- if .Values.worker.securityContext.enabled }}
securityContext: {{- omit .Values.worker.securityContext "enabled" | toYaml | nindent 10 }}
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.worker.securityContext "context" $) | nindent 10 }}
{{- end }}
image: {{ include "netbox.image" . | quote }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand All @@ -61,9 +55,19 @@ spec:
{{- if .Values.worker.args }}
args: {{- include "common.tplvalues.render" (dict "value" .Values.worker.args "context" $) | nindent 10 }}
{{- end }}
{{- with .Values.worker.extraEnvs }}
env:
{{- toYaml . | nindent 8 }}
{{- if .Values.worker.extraEnvs }}
env: {{- include "common.tplvalues.render" (dict "value" .Values.worker.extraEnvs "context" $) | nindent 10 }}
{{- end }}
{{- if or .Values.worker.extraEnvVarsCM .Values.worker.extraEnvVarsSecret }}
envFrom:
{{- if .Values.worker.extraEnvVarsCM }}
- configMapRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.worker.extraEnvVarsCM "context" $) }}
{{- end }}
{{- if .Values.worker.extraEnvVarsSecret }}
- secretRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.worker.extraEnvVarsSecret "context" $) }}
{{- end }}
{{- end }}
volumeMounts:
- name: config
Expand Down Expand Up @@ -107,8 +111,8 @@ spec:
subPath: {{ .Values.scriptsPersistence.subPath | default "" | quote }}
readOnly: {{ .Values.worker.readOnlyPersistence | default false }}
{{- end }}
{{- with .Values.worker.extraVolumeMounts }}
{{- toYaml . | nindent 8 }}
{{- if .Values.worker.extraVolumeMounts }}
{{- include "common.tplvalues.render" (dict "value" .Values.worker.extraVolumeMounts "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.worker.resources }}
resources: {{ toYaml .Values.worker.resources | nindent 10 }}
Expand Down Expand Up @@ -182,8 +186,8 @@ spec:
claimName: {{ .Values.scriptsPersistence.existingClaim | default (printf "%s-scripts" (include "common.names.fullname" .)) }}
readOnly: {{ .Values.worker.readOnlyPersistence | default false }}
{{- end }}
{{- with .Values.worker.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- if .Values.worker.extraVolumes }}
{{- include "common.tplvalues.render" (dict "value" .Values.worker.extraVolumes "context" $) | nindent 6 }}
{{- end }}
{{- if .Values.worker.nodeSelector }}
nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.worker.nodeSelector "context" $) | nindent 8 }}
Expand Down
Loading
Loading