From 9dea0cee6dc51dae3fe3d9890ff206d8fce641ec Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Fri, 24 Nov 2023 19:21:05 +0100 Subject: [PATCH] fix(unifi): allow for smooth migration (#15327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [x] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Signed-off-by: Kjeld Schouten --- charts/stable/unifi/Chart.yaml | 2 +- charts/stable/unifi/values.yaml | 48 +++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/charts/stable/unifi/Chart.yaml b/charts/stable/unifi/Chart.yaml index 09952d72a31..47e2cefb79d 100644 --- a/charts/stable/unifi/Chart.yaml +++ b/charts/stable/unifi/Chart.yaml @@ -22,7 +22,7 @@ sources: - https://github.com/jacobalberty/unifi-docker - https://unifi-network.ui.com type: application -version: 16.0.4 +version: 16.0.5 annotations: truecharts.org/category: Networking truecharts.org/SCALE-support: "true" diff --git a/charts/stable/unifi/values.yaml b/charts/stable/unifi/values.yaml index e0997fe6f7e..23f899d8e5d 100644 --- a/charts/stable/unifi/values.yaml +++ b/charts/stable/unifi/values.yaml @@ -47,10 +47,20 @@ service: persistence: config: enabled: true - mountPath: "/usr/lib/unifi/olddata" + targetSelector: + main: + main: + mountPath: /usr/lib/unifi/olddata + migrate: + mountPath: /usr/lib/unifi/olddata data: enabled: true - mountPath: "/usr/lib/unifi/data" + targetSelector: + main: + main: + mountPath: /usr/lib/unifi/data + migrate: + mountPath: /usr/lib/unifi/data logs: enabled: true mountPath: "/usr/lib/unifi/logs" @@ -64,11 +74,39 @@ portal: securityContext: container: readOnlyRootFilesystem: false - runAsGroup: 999 - runAsUser: 999 + runAsGroup: 0 + runAsUser: 0 workload: main: podSpec: containers: main: - env: {} + env: + RUN_CHOWN: true + DB_MONGO_LOCAL: true + initContainers: + migrate: + enabled: true + type: init + imageSelector: alpineImage + command: + - /bin/sh + args: + - -c + - | + newdatadir="/usr/lib/unifi/data" + olddatadir="/usr/lib/unifi/olddata/data" + # Check the dir exists + [ ! -d "$newdatadir" ] && echo "$newdatadir missing" && exit 1 + # Check if there is a data/data dir to migrate + [ ! -d "$olddatadir" ] && echo "No $olddatadir dir found. Migration skipped" && exit 0 + + # Check if the new data dir is empty, ignoring the old data dir + dirs=$(ls -A "$newdatadir" | grep -v "data") + if [ -n "$dirs" ]; then + echo "New data dir is empty. Migrating data one level up" + mv $olddatadir/* $newdatadir || echo "Failed to move data" && exit 1 + # Remove the data/data dir + rm -rf $olddatadir + echo "Data migration complete" + fi