_unifi.tpl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {{- define "unifi.workload" -}}
  2. workload:
  3. unifi:
  4. enabled: true
  5. primary: true
  6. type: Deployment
  7. podSpec:
  8. hostNetwork: {{ .Values.unifiNetwork.hostNetwork }}
  9. containers:
  10. unifi:
  11. enabled: true
  12. primary: true
  13. imageSelector: image
  14. securityContext:
  15. runAsUser: 999
  16. runAsGroup: 999
  17. readOnlyRootFilesystem: false
  18. env:
  19. DB_MONGO_LOCAL: true
  20. RUN_CHOWN: false
  21. RUNAS_UID0: false
  22. UNIFI_HTTP_PORT: {{ .Values.unifiNetwork.webHttpPort }}
  23. UNIFI_HTTPS_PORT: {{ .Values.unifiNetwork.webHttpsPort }}
  24. PORTAL_HTTP_PORT: {{ .Values.unifiNetwork.portalHttpPort }}
  25. PORTAL_HTTPS_PORT: {{ .Values.unifiNetwork.portalHttpsPort }}
  26. {{ with .Values.unifiConfig.additionalEnvs }}
  27. envList:
  28. {{ range $env := . }}
  29. - name: {{ $env.name }}
  30. value: {{ $env.value }}
  31. {{ end }}
  32. {{ end }}
  33. probes:
  34. liveness:
  35. enabled: true
  36. type: exec
  37. command: /usr/local/bin/docker-healthcheck.sh
  38. readiness:
  39. enabled: true
  40. type: exec
  41. command: /usr/local/bin/docker-healthcheck.sh
  42. startup:
  43. enabled: true
  44. type: exec
  45. command: /usr/local/bin/docker-healthcheck.sh
  46. initContainers:
  47. {{- include "ix.v1.common.app.permissions" (dict "containerName" "01-permissions"
  48. "UID" 999
  49. "GID" 999
  50. "mode" "check"
  51. "type" "install") | nindent 8 }}
  52. {{- $migrate := false -}}
  53. {{- if (hasKey .Values.global "ixChartContext") -}}
  54. {{- if (hasKey .Values.global.ixChartContext "upgradeMetadata") -}}
  55. {{- with .Values.global.ixChartContext.upgradeMetadata -}}
  56. {{- $ver := semver (.oldChartVersion | default "0.0.0") -}}
  57. {{/* Enable migrate script if old version is below 1.2.x */}}
  58. {{- if and (eq $ver.Major 1) (lt $ver.Minor 2) -}}
  59. {{- $migrate = true -}}
  60. {{- end -}}
  61. {{- end -}}
  62. {{- end -}}
  63. {{- end }}
  64. 02-migrate:
  65. enabled: {{ $migrate }}
  66. type: init
  67. imageSelector: image
  68. securityContext:
  69. runAsUser: 999
  70. runAsGroup: 999
  71. readOnlyRootFilesystem: false
  72. command:
  73. - /bin/bash
  74. args:
  75. - -c
  76. - |
  77. newdatadir="/usr/lib/unifi/data"
  78. olddatadir="/usr/lib/unifi/data/data"
  79. # Check the dir exists
  80. [ ! -d "$newdatadir" ] && echo "$newdatadir missing" && exit 1
  81. # Check if there is a data/data dir to migrate
  82. [ ! -d "$olddatadir" ] && echo "No $olddatadir dir found. Migration skipped" && exit 0
  83. # Check if the new data dir is empty, ignoring the old data dir
  84. dirs=$(ls -A "$newdatadir" | grep -v "data")
  85. if [ -n "$dirs" ]; then
  86. echo "New data dir is empty. Migrating data one level up"
  87. mv $olddatadir/* $newdatadir || echo "Failed to move data" && exit 1
  88. # Remove the data/data dir
  89. rm -rf $olddatadir
  90. echo "Data migration complete"
  91. fi
  92. {{- end -}}