diff --git a/charts/unifi-controller/.gitignore b/charts/unifi-controller/.gitignore index c419c22..4afcd1a 100644 --- a/charts/unifi-controller/.gitignore +++ b/charts/unifi-controller/.gitignore @@ -1 +1,2 @@ -values.test.yaml \ No newline at end of file +values.test.yaml +charts/*.tgz \ No newline at end of file diff --git a/charts/unifi-controller/Chart.lock b/charts/unifi-controller/Chart.lock new file mode 100644 index 0000000..fdd5f2e --- /dev/null +++ b/charts/unifi-controller/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: mongodb + repository: https://charts.bitnami.com/bitnami + version: 15.3.0 +digest: sha256:f6cc8e47d7f68e327889b4807f488a346c70c7da8c80ea623aa7a1a8c6d95877 +generated: "2024-05-10T21:31:20.762106802+01:00" diff --git a/charts/unifi-controller/Chart.yaml b/charts/unifi-controller/Chart.yaml index dbb98b7..09f8539 100644 --- a/charts/unifi-controller/Chart.yaml +++ b/charts/unifi-controller/Chart.yaml @@ -15,10 +15,16 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 2.0.0 +version: 3.0.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "8.0.7" +appVersion: "8.1.127" + +dependencies: + - name: mongodb + version: ^15.3.0 + repository: https://charts.bitnami.com/bitnami + condition: mongodb.enabled diff --git a/charts/unifi-controller/templates/_helpers.tpl b/charts/unifi-controller/templates/_helpers.tpl index 9640a04..2b2666f 100644 --- a/charts/unifi-controller/templates/_helpers.tpl +++ b/charts/unifi-controller/templates/_helpers.tpl @@ -60,3 +60,81 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "unifi-controller.mongodb.fullname" -}} +{{- printf "%s-%s" .Release.Name "mongodb" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Set mongodb host +*/}} +{{- define "unifi-controller.mongodb.host" -}} +{{- if .Values.mongodb.enabled -}} +{{- template "unifi-controller.mongodb.fullname" . -}} +{{- else -}} +{{ required "A valid externalMongodb.host is required" .Values.externalMongodb.host }} +{{- end -}} +{{- end -}} + +{{/* +Set mongodb secret +*/}} +{{- define "unifi-controller.mongodb.secret" -}} +{{- if .Values.mongodb.enabled -}} +{{- template "unifi-controller.mongodb.fullname" . -}} +{{- else -}} +{{- template "unifi-controller.fullname" . -}} +{{- end -}} +{{- end -}} + +{{/* +Set mongodb port +*/}} +{{- define "unifi-controller.mongodb.port" -}} +{{- if .Values.mongodb.enabled -}} +{{- if .Values.mongodb.service -}} +{{- .Values.mongodb.service.port | default 27017 }} +{{- else -}} +5432 +{{- end -}} +{{- else -}} +{{- required "A valid externalMongodb.port is required" .Values.externalMongodb.port -}} +{{- end -}} +{{- end -}} + +{{/* +Set mongodb username +*/}} +{{- define "unifi-controller.mongodb.username" -}} +{{- if .Values.mongodb.enabled -}} +{{ required "A valid mongodb.auth.usernames is required" (first .Values.mongodb.auth.usernames) }} +{{- else -}} +{{ required "A valid externalMongodb.username is required" .Values.externalMongodb.username }} +{{- end -}} +{{- end -}} + +{{/* +Set mongodb password +*/}} +{{- define "unifi-controller.mongodb.password" -}} +{{- if .Values.mongodb.enabled -}} +{{ required "A valid mongodb.auth.passwords is required" (first .Values.mongodb.auth.passwords) }} +{{- else if not (and .Values.externalMongodb.existingSecret .Values.externalMongodb.existingSecretPasswordKey) -}} +{{ required "A valid externalMongodb.password is required" .Values.externalMongodb.password }} +{{- end -}} +{{- end -}} + +{{/* +Set mongodb database +*/}} +{{- define "unifi-controller.mongodb.database" -}} +{{- if .Values.mongodb.enabled -}} +{{- (first .Values.mongodb.auth.databases) | default "unifi" }} +{{- else -}} +{{ required "A valid externalMongodb.database is required" .Values.externalMongodb.database }} +{{- end -}} +{{- end -}} diff --git a/charts/unifi-controller/templates/configmap.yaml b/charts/unifi-controller/templates/configmap.yaml new file mode 100644 index 0000000..8932cc4 --- /dev/null +++ b/charts/unifi-controller/templates/configmap.yaml @@ -0,0 +1,10 @@ +{{- if .Values.mongodb.enabled -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: initdb-scripts +data: + init-mongo.js: | + db = db.getSiblingDB("{{ include "unifi-controller.mongodb.database" . }}"); + db.grantRolesToUser("{{ include "unifi-controller.mongodb.username" . }}", [{role: "dbOwner", db: "{{ include "unifi-controller.mongodb.database" . }}_stat"}]) +{{- end }} \ No newline at end of file diff --git a/charts/unifi-controller/templates/deployment.yaml b/charts/unifi-controller/templates/deployment.yaml index 3be04bf..70105e0 100644 --- a/charts/unifi-controller/templates/deployment.yaml +++ b/charts/unifi-controller/templates/deployment.yaml @@ -67,6 +67,26 @@ spec: value: {{ .Values.config.jvmMemory.startup }} - name: MEM_LIMIT value: {{ .Values.config.jvmMemory.limit }} + - name: MONGO_HOST + value: {{ include "unifi-controller.mongodb.host" . }} + - name: MONGO_PORT + value: {{ include "unifi-controller.mongodb.port" . | quote }} + - name: MONGO_USER + value: {{ include "unifi-controller.mongodb.username" . }} + {{- if or .Values.mongodb.enabled .Values.externalMongodb.existingSecret }} + - name: MONGO_PASS + valueFrom: + secretKeyRef: + {{- if .Values.mongodb.enabled }} + name: {{ .Values.mongodb.existingSecret | default (include "unifi-controller.mongodb.fullname" .) }} + key: mongodb-passwords + {{- else }} + name: {{ .Values.externalMongodb.existingSecret }} + key: {{ .Values.externalMongodb.existingSecretPasswordKey }} + {{- end }} + {{- end }} + - name: MONGO_DBNAME + value: {{ include "unifi-controller.mongodb.database" . }} resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/charts/unifi-controller/values.yaml b/charts/unifi-controller/values.yaml index 13cf110..76de11e 100644 --- a/charts/unifi-controller/values.yaml +++ b/charts/unifi-controller/values.yaml @@ -3,7 +3,7 @@ # Declare variables to be passed into your templates. image: - repository: quay.io/linuxserver.io/unifi-controller + repository: lscr.io/linuxserver/unifi-network-application pullPolicy: IfNotPresent # -- Overrides the image tag whose default is the chart appVersion. tag: "" @@ -56,6 +56,31 @@ service: combinedProtocols: true annotations: {} +mongodb: + # -- Deploy Bitnami MongoDB sub-chart + enabled: true + auth: + rootUser: root + rootPassword: unifi + databases: + - unifi + usernames: + - unifi + passwords: + - unifi + initdbScriptsConfigMap: initdb-scripts + +externalMongodb: + # -- Use an external MongoDB database + enabled: false + # host: mongodb + port: 5432 + database: mongo + username: mongo + # password: mongo + # existingSecret: mongo + # existingSecretPasswordKey: password + ingress: enabled: false className: ""