From bda886babd8eb7661a80333d180e5a7af4eb4f9e Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:56:34 +0200 Subject: [PATCH] feat(common): add cleanup flags for volsync (#29830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** Flags introduced in this release. (We should also update the CRDs on the volsync chart) ⚒️ Fixes #29824 **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 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:** - [x] ⚖️ My code follows the style guidelines of this project - [x] 👀 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 - [x] ⚠️ My changes generate no new warnings - [x] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [x] ⬆️ I increased versions for any altered app according to semantic versioning - [x] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ 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: Stavros Kois <47820033+stavros-k@users.noreply.github.com> --- .../volsync/replication_dest_spec_test.yaml | 55 ++++++++++++++++ .../volsync/replication_src_spec_test.yaml | 65 +++++++++++++++++++ charts/library/common/Chart.yaml | 2 +- .../class/volsync/_replicationDestination.tpl | 11 ++++ .../class/volsync/_replicationSource.tpl | 13 +++- cspell.config.yaml | 3 + 6 files changed, 147 insertions(+), 2 deletions(-) diff --git a/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml b/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml index 3a653db94af..28592db08fd 100644 --- a/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml @@ -64,6 +64,8 @@ tests: restic: repository: test-release-name-common-test-destbackup-volsync-mybackup1 copyMethod: Snapshot + cleanupTempPVC: false + cleanupCachePVC: false cacheCapacity: 10Gi capacity: 100Gi accessModes: @@ -107,6 +109,8 @@ tests: restic: repository: test-release-name-common-test-destbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false cacheCapacity: 10Gi capacity: 200Gi accessModes: @@ -150,6 +154,8 @@ tests: restic: repository: test-release-name-common-test-destbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false cacheCapacity: 10Gi capacity: 100Gi accessModes: @@ -194,6 +200,8 @@ tests: restic: repository: test-release-name-common-test-destbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false cacheCapacity: 10Gi capacity: 100Gi accessModes: @@ -239,6 +247,8 @@ tests: restic: repository: test-release-name-common-test-destbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false cacheCapacity: 10Gi capacity: 100Gi accessModes: @@ -249,3 +259,48 @@ tests: fsGroup: 568 runAsUser: 568 runAsGroup: 568 + + - it: should generate correct spec with cleanup flags + set: + persistence: + destbackup: + enabled: true + type: pvc + mountPath: /backedup + volsync: + - name: mybackup1 + type: restic + credentials: mys3 + cleanupTempPVC: true + cleanupCachePVC: true + dest: + enabled: true + src: + enabled: false + credentials: *credentials + asserts: + - documentIndex: *replicationDestDoc + isKind: + of: ReplicationDestination + - documentIndex: *replicationDestDoc + isAPIVersion: + of: volsync.backube/v1alpha1 + - documentIndex: *replicationDestDoc + equal: + path: spec + value: + trigger: + manual: restore-once + restic: + repository: test-release-name-common-test-destbackup-volsync-mybackup1 + copyMethod: Snapshot + cleanupTempPVC: true + cleanupCachePVC: true + cacheCapacity: 10Gi + capacity: 100Gi + accessModes: + - ReadWriteOnce + moverSecurityContext: + fsGroup: 568 + runAsUser: 568 + runAsGroup: 568 diff --git a/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml b/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml index 6290bbfb503..7cb6cc59b24 100644 --- a/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml @@ -64,6 +64,8 @@ tests: content: repository: test-release-name-common-test-srcbackup-volsync-mybackup1 copyMethod: Snapshot + cleanupTempPVC: false + cleanupCachePVC: false pruneIntervalDays: 7 retain: hourly: 6 @@ -128,6 +130,8 @@ tests: content: repository: test-release-name-common-test-srcbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false pruneIntervalDays: 5 retain: hourly: 20 @@ -191,6 +195,8 @@ tests: content: repository: test-release-name-common-test-srcbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false pruneIntervalDays: 5 retain: hourly: 20 @@ -255,6 +261,8 @@ tests: content: repository: test-release-name-common-test-srcbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false pruneIntervalDays: 5 retain: hourly: 20 @@ -320,6 +328,8 @@ tests: content: repository: test-release-name-common-test-srcbackup-volsync-mybackup1 copyMethod: Clone + cleanupTempPVC: false + cleanupCachePVC: false pruneIntervalDays: 5 retain: hourly: 20 @@ -339,3 +349,58 @@ tests: matchRegex: path: spec.restic.unlock pattern: "^[0-9]{14}$" + + - it: should generate correct spec with cleanup flags + set: + persistence: + srcbackup: + enabled: true + type: pvc + mountPath: /backedup + volsync: + - name: mybackup1 + type: restic + credentials: mys3 + copyMethod: Clone + cleanupTempPVC: true + cleanupCachePVC: true + dest: + enabled: false + src: + enabled: true + trigger: + schedule: "1 0 * * *" + retain: + hourly: 20 + daily: 5 + weekly: 3 + pruneIntervalDays: 5 + credentials: *credentials + asserts: + - documentIndex: *replicationDestDoc + isKind: + of: ReplicationSource + - documentIndex: *replicationDestDoc + isAPIVersion: + of: volsync.backube/v1alpha1 + - documentIndex: *replicationDestDoc + isSubset: + path: spec.restic + content: + repository: test-release-name-common-test-srcbackup-volsync-mybackup1 + copyMethod: Clone + cleanupTempPVC: true + cleanupCachePVC: true + pruneIntervalDays: 5 + retain: + hourly: 20 + daily: 5 + weekly: 3 + monthly: 3 + yearly: 1 + accessModes: + - ReadWriteOnce + moverSecurityContext: + fsGroup: 568 + runAsUser: 568 + runAsGroup: 568 diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 7e05db6695e..8102c384c3c 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,4 +48,4 @@ sources: - https://hub.docker.com/_/ - https://hub.docker.com/r/mikefarah/yq type: library -version: 25.2.4 +version: 25.2.5 diff --git a/charts/library/common/templates/class/volsync/_replicationDestination.tpl b/charts/library/common/templates/class/volsync/_replicationDestination.tpl index ee239b40bd8..ed0cc38ff81 100644 --- a/charts/library/common/templates/class/volsync/_replicationDestination.tpl +++ b/charts/library/common/templates/class/volsync/_replicationDestination.tpl @@ -17,6 +17,15 @@ objectData: {{- $objectData := .objectData -}} {{- $volsyncData := .volsyncData -}} + {{- $cleanupTempPVC := false -}} + {{- $cleanupCachePVC := false -}} + {{- if and (hasKey $volsyncData "cleanupTempPVC") (kindIs "bool" $volsyncData.cleanupTempPVC) -}} + {{- $cleanupTempPVC = $volsyncData.cleanupTempPVC -}} + {{- end -}} + {{- if and (hasKey $volsyncData "cleanupCachePVC") (kindIs "bool" $volsyncData.cleanupCachePVC) -}} + {{- $cleanupCachePVC = $volsyncData.cleanupCachePVC -}} + {{- end -}} + {{- $capacity := $rootCtx.Values.global.fallbackDefaults.pvcSize -}} {{- if $objectData.size -}} {{- $capacity = $objectData.size -}} @@ -47,6 +56,8 @@ spec: repository: {{ $volsyncData.repository }} copyMethod: {{ $volsyncData.copyMethod | default "Snapshot"}} capacity: {{ $capacity }} + cleanupTempPVC: {{ $cleanupTempPVC }} + cleanupCachePVC: {{ $cleanupCachePVC }} {{- include "tc.v1.common.lib.volsync.storage" (dict "rootCtx" $rootCtx "objectData" $objectData "volsyncData" $volsyncData "target" "dest") | trim | nindent 4 }} {{- include "tc.v1.common.lib.volsync.cache" (dict "rootCtx" $rootCtx "objectData" $objectData "volsyncData" $volsyncData "target" "dest") | trim | nindent 4 }} {{- include "tc.v1.common.lib.volsync.moversecuritycontext" (dict "rootCtx" $rootCtx "objectData" $objectData "volsyncData" $volsyncData "target" "dest") | trim | nindent 4 }} diff --git a/charts/library/common/templates/class/volsync/_replicationSource.tpl b/charts/library/common/templates/class/volsync/_replicationSource.tpl index 133bb52f9d0..13dbc668860 100644 --- a/charts/library/common/templates/class/volsync/_replicationSource.tpl +++ b/charts/library/common/templates/class/volsync/_replicationSource.tpl @@ -20,7 +20,16 @@ objectData: {{- $schedule := "0 0 * * *" -}} {{- if and $volsyncData.src.trigger $volsyncData.src.trigger.schedule -}} {{- $schedule = $volsyncData.src.trigger.schedule -}} - {{- end }} + {{- end -}} + + {{- $cleanupTempPVC := false -}} + {{- $cleanupCachePVC := false -}} + {{- if and (hasKey $volsyncData "cleanupTempPVC") (kindIs "bool" $volsyncData.cleanupTempPVC) -}} + {{- $cleanupTempPVC = $volsyncData.cleanupTempPVC -}} + {{- end -}} + {{- if and (hasKey $volsyncData "cleanupCachePVC") (kindIs "bool" $volsyncData.cleanupCachePVC) -}} + {{- $cleanupCachePVC = $volsyncData.cleanupCachePVC -}} + {{- end -}} {{- $retain := dict "hourly" 6 "daily" 5 "weekly" 4 "monthly" 3 "yearly" 1 -}} {{- if $volsyncData.src.retain -}} @@ -54,6 +63,8 @@ spec: {{ $volsyncData.type }}: repository: {{ $volsyncData.repository }} copyMethod: {{ $volsyncData.copyMethod | default "Snapshot" }} + cleanupTempPVC: {{ $cleanupTempPVC }} + cleanupCachePVC: {{ $cleanupCachePVC }} pruneIntervalDays: {{ $volsyncData.src.pruneIntervalDays | default 7 }} unlock: {{ now | date "20060102150405" | quote }} retain: diff --git a/cspell.config.yaml b/cspell.config.yaml index afa7b222503..9cd0209b1d4 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -20,6 +20,7 @@ words: - autoplay - autoscan - autosync + - backube - backupname - basicauthexample - batnoter @@ -188,6 +189,7 @@ words: - netdata - networkv - nextcloud + - nindent - nitter - nobind - nocaptcha @@ -328,6 +330,7 @@ words: - vdev - vikunja - vm's + - volsync - wakeup - watchyourlan - webbasecontrol