From cb3833bfcd01043a411f514fdbaa6b538ee988c2 Mon Sep 17 00:00:00 2001 From: Alexander Olofsson Date: Fri, 28 Apr 2023 11:09:46 +0200 Subject: [PATCH] netbox: Update to 3.5.0 This also adds in proper plugin configuration as well as making the build-in Redis optional - but still requiring _a_ Redis install for regular operation --- charts/netbox/Chart.yaml | 5 +-- charts/netbox/templates/configuration.yaml | 23 +++++++++++-- .../templates/deployment-housekeeping.yaml | 26 ++++++++++++--- .../netbox/templates/deployment-worker.yaml | 26 ++++++++++++--- charts/netbox/templates/deployment.yaml | 16 ++++++++-- charts/netbox/templates/secrets.yaml | 3 ++ charts/netbox/values.yaml | 32 +++++++++++++------ 7 files changed, 105 insertions(+), 26 deletions(-) diff --git a/charts/netbox/Chart.yaml b/charts/netbox/Chart.yaml index c7806a3..b430fd2 100644 --- a/charts/netbox/Chart.yaml +++ b/charts/netbox/Chart.yaml @@ -7,10 +7,10 @@ description: | Important; With chart version 4.0.0 there are major upgrades to the packaged Redis and Postgres, as well as a major version bump of Netbox that introduces housekeeping. Take care when upgrading. icon: https://raw.githubusercontent.com/digitalocean/netbox/develop/netbox/project-static/img/netbox.ico -appVersion: 3.4.10 +appVersion: 3.5.0 type: application -version: 5.1.1 +version: 5.2.0 maintainers: - name: Alexander Olofsson email: ace@haxalot.com @@ -23,3 +23,4 @@ dependencies: - name: redis version: ^17.3.17 repository: https://charts.bitnami.com/bitnami + condition: redis.enabled diff --git a/charts/netbox/templates/configuration.yaml b/charts/netbox/templates/configuration.yaml index e2a865d..9be11ec 100644 --- a/charts/netbox/templates/configuration.yaml +++ b/charts/netbox/templates/configuration.yaml @@ -1,3 +1,6 @@ +{{- if and (not .Values.redis.enabled) (not .Values.redis.host) }} +{{ fail "Redis host must be provided if built-in redis is disabled" }} +{{- end }} {{- if .Values.extraConfiguration }} --- apiVersion: v1 @@ -10,7 +13,23 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} helm.sh/chart: {{ include "netbox.chart" . }} data: - extra.py: {{ .Values.extraConfiguration | toYaml | indent 2 }} + extra.py: | + {{- .Values.extraConfiguration | nindent 4 }} +{{- end }} +{{- if .Values.extraPlugins }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Chart.Name }}-plugins + labels: + app.kubernetes.io/name: {{ include "netbox.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: {{ include "netbox.chart" . }} +data: + plugins.py: | + {{- .Values.extraPlugins | nindent 4 }} {{- end }} --- apiVersion: v1 @@ -28,7 +47,7 @@ data: DB_HOST: {{ .Values.postgresql.postgresqlHost | default (include "netbox.postgresql.fullname" .) }} DB_PORT: {{ .Values.postgresql.postgresqlPort | default 5432 | quote }} - REDIS_HOST: {{ include "netbox.redisHost" . }} + REDIS_HOST: {{ .Values.redis.host | default (include "netbox.redisHost" .) }} REDIS_PORT: {{ .Values.redis.master.service.port | default 6379 | quote }} REDIS_SSL: "false" diff --git a/charts/netbox/templates/deployment-housekeeping.yaml b/charts/netbox/templates/deployment-housekeeping.yaml index 89d5b39..4a121c5 100644 --- a/charts/netbox/templates/deployment-housekeeping.yaml +++ b/charts/netbox/templates/deployment-housekeeping.yaml @@ -33,11 +33,13 @@ spec: image: "{{ .Values.image.repository }}:{{ include "netbox.imageTag" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: + {{- if and (or .Values.redis.auth.existingSecret .Values.redis.enabled) (not .Values.redis.auth.password) }} - name: REDIS_PASSWORD valueFrom: secretKeyRef: - name: {{ include "netbox.redis.fullname" . }} - key: redis-password + name: {{ .Values.redis.auth.existingSecret | default (include "netbox.redis.fullname" .) }} + key: {{ .Values.redis.auth.existingSecretPasswordKey | default "redis-password" }} + {{- end }} {{- if .Values.postgresql.enabled }} - name: DB_PASSWORD valueFrom: @@ -57,21 +59,35 @@ spec: name: {{ include "netbox.fullname" . }} resources: {{- toYaml .Values.housekeeping.resources | nindent 12 }} - {{- if .Values.extraConfiguration }} + {{- if or .Values.extraConfiguration .Values.extraPlugins }} volumeMounts: + {{- if .Values.extraConfiguration }} - name: netbox-extra-config mountPath: /etc/netbox/config/extra.py subPath: extra.py - {{- end }} + {{- end }} + {{- if .Values.extraPlugins }} + - name: netbox-extra-plugins + mountPath: /etc/netbox/config/plugins.py + subPath: plugins.py + {{- end }} + {{- end }} {{- with .Values.housekeeping.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- if .Values.extraConfiguration }} volumes: + {{- if or .Values.extraConfiguration .Values.extraPlugins }} + {{- if .Values.extraConfiguration }} - name: netbox-extra-config configMap: name: {{ .Chart.Name }}-extra + {{- end }} + {{- if .Values.extraPlugins }} + - name: netbox-extra-plugins + configMap: + name: {{ .Chart.Name }}-plugins + {{- end }} {{- end }} {{- with .Values.housekeeping.affinity }} affinity: diff --git a/charts/netbox/templates/deployment-worker.yaml b/charts/netbox/templates/deployment-worker.yaml index 6e21aea..bde1e58 100644 --- a/charts/netbox/templates/deployment-worker.yaml +++ b/charts/netbox/templates/deployment-worker.yaml @@ -35,11 +35,13 @@ spec: image: "{{ .Values.image.repository }}:{{ include "netbox.imageTag" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: + {{- if and (or .Values.redis.auth.existingSecret .Values.redis.enabled) (not .Values.redis.auth.password) }} - name: REDIS_PASSWORD valueFrom: secretKeyRef: - name: {{ include "netbox.redis.fullname" . }} - key: redis-password + name: {{ .Values.redis.auth.existingSecret | default (include "netbox.redis.fullname" .) }} + key: {{ .Values.redis.auth.existingSecretPasswordKey | default "redis-password" }} + {{- end }} {{- if .Values.postgresql.enabled }} - name: DB_PASSWORD valueFrom: @@ -59,21 +61,35 @@ spec: name: {{ include "netbox.fullname" . }} resources: {{- toYaml .Values.worker.resources | nindent 12 }} - {{- if .Values.extraConfiguration }} + {{- if or .Values.extraConfiguration .Values.extraPlugins }} volumeMounts: + {{- if .Values.extraConfiguration }} - name: netbox-extra-config mountPath: /etc/netbox/config/extra.py subPath: extra.py - {{- end }} + {{- end }} + {{- if .Values.extraPlugins }} + - name: netbox-extra-plugins + mountPath: /etc/netbox/config/plugins.py + subPath: plugins.py + {{- end }} + {{- end }} {{- with .Values.worker.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- if .Values.extraConfiguration }} + {{- if or .Values.extraConfiguration .Values.extraPlugins }} volumes: + {{- if .Values.extraConfiguration }} - name: netbox-extra-config configMap: name: {{ .Chart.Name }}-extra + {{- end }} + {{- if .Values.extraPlugins }} + - name: netbox-extra-plugins + configMap: + name: {{ .Chart.Name }}-plugins + {{- end }} {{- end }} {{- with .Values.worker.affinity }} affinity: diff --git a/charts/netbox/templates/deployment.yaml b/charts/netbox/templates/deployment.yaml index 36dde3d..1885cff 100644 --- a/charts/netbox/templates/deployment.yaml +++ b/charts/netbox/templates/deployment.yaml @@ -39,11 +39,13 @@ spec: image: "{{ .Values.image.repository }}:{{ include "netbox.imageTag" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: + {{- if and (or .Values.redis.auth.existingSecret .Values.redis.enabled) (not .Values.redis.auth.password) }} - name: REDIS_PASSWORD valueFrom: secretKeyRef: - name: {{ include "netbox.redis.fullname" . }} - key: redis-password + name: {{ .Values.redis.auth.existingSecret | default (include "netbox.redis.fullname" .) }} + key: {{ .Values.redis.auth.existingSecretPasswordKey | default "redis-password" }} + {{- end }} {{- if .Values.existingDjangoSecret }} - name: SECRET_KEY valueFrom: @@ -94,6 +96,11 @@ spec: mountPath: /etc/netbox/config/extra.py subPath: extra.py {{- end }} + {{- if .Values.extraPlugins }} + - name: netbox-extra-plugins + mountPath: /etc/netbox/config/plugins.py + subPath: plugins.py + {{- end }} {{- with .Values.extraVolumeMounts }} {{ toYaml . | nindent 12 }} {{- end }} @@ -114,6 +121,11 @@ spec: configMap: name: {{ .Chart.Name }}-extra {{- end }} + {{- if .Values.extraPlugins }} + - name: netbox-extra-plugins + configMap: + name: {{ .Chart.Name }}-plugins + {{- end }} {{- if .Values.extraVolumes }} {{ toYaml .Values.extraVolumes | nindent 8 }} {{- end }} diff --git a/charts/netbox/templates/secrets.yaml b/charts/netbox/templates/secrets.yaml index 5571c80..687bc90 100644 --- a/charts/netbox/templates/secrets.yaml +++ b/charts/netbox/templates/secrets.yaml @@ -12,6 +12,9 @@ data: {{- if and (.Values.postgresql.auth.password) (not .Values.postgresql.enabled) }} DB_PASSWORD: {{ .Values.postgresql.auth.password | b64enc }} {{- end }} +{{- if .Values.redis.auth.password }} + REDIS_PASSWORD: {{ .Values.redis.auth.password | b64enc }} +{{- end }} {{- if .Values.djangoSecret }} SECRET_KEY: {{ .Values.djangoSecret | b64enc }} {{- else if not .Values.existingDjangoSecret }} diff --git a/charts/netbox/values.yaml b/charts/netbox/values.yaml index 02bc5ff..f5709dc 100644 --- a/charts/netbox/values.yaml +++ b/charts/netbox/values.yaml @@ -56,11 +56,17 @@ postgresql: # postgresqlHost: postgres # postgresqlPort: 5432 +# For standalone redis, set enabled=false and host to your redis server redis: + enabled: true + # host: example.com + architecture: standalone auth: enabled: true # password: netbox + # existingSecret: + # existingSecretPasswordKey: master: kind: Deployment @@ -81,18 +87,29 @@ extraEnv: {} # EMAIL_USERNAME: netbox # EMAIL_TIMEOUT: 5 # EMAIL_FROM: netbox@example.com - # NAPALM_USERNAME: '' - # NAPALM_TIMEOUT: 10 # MAX_PAGE_SIZE: 1000 # WEBHOOKS_ENABLED: true extraSecrets: {} # EMAIL_PASSWORD: netbox - # NAPALM_PASSWORD: '' -# Ends up stored as extra.py in the netbox configuration +# Ends up stored as extra.py in the netbox configuration, must be valid Python extraConfiguration: '' +# Will be stored in plugins.py in the netbox configuration, requires +# using/building a netbox image containing the required plugins, must be valid +# Python +# +# https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins +extraPlugins: '' + # PLUGINS = ["netbox_bgp"] + # + # PLUGINS_CONFIG = { + # "netbox_bgp": { + # ADD YOUR SETTINGS HERE + # } + # } + superuser: name: '' email: '' @@ -116,10 +133,6 @@ affinity: {} extraVolumes: [] extraVolumeMounts: [] - # - name: extra-music-data - # mountPath: /srv/funkwhale/data/music - # readOnly: true - # existingClaim: volume-claim persistence: enabled: false @@ -147,9 +160,8 @@ worker: affinity: {} +# Handles the Netbox 3.0+ housekeeping pod housekeeping: - ## Netbox 3.0.0 and upwards need a housekeeping pod, if you're not using - ## 3.0 then you may need to set this parameter enabled: true resources: {}