diff --git a/.github/workflows/common_library_tests.yaml b/.github/workflows/common_library_tests.yaml index 766122af..b933ca89 100644 --- a/.github/workflows/common_library_tests.yaml +++ b/.github/workflows/common_library_tests.yaml @@ -206,7 +206,7 @@ jobs: - name: Add Dependencies run: | - if [[ "${{ matrix.values }}" =~ (ingress|metrics|cnpg).*-values.yaml ]]; then + if [[ "${{ matrix.values }}" =~ (ingress|metrics|cnpg|volsync).*-values.yaml ]]; then helm install prometheus-operator oci://tccr.io/truecharts/prometheus-operator --namespace prometheus-operator --create-namespace --wait fi if [[ "${{ matrix.values }}" =~ cnpg.*-values.yaml ]]; then @@ -217,6 +217,10 @@ jobs: helm install traefik oci://tccr.io/truecharts/traefik --namespace traefik --create-namespace --wait \ --set service.main.type=ClusterIP --set service.tcp.type=ClusterIP fi + if [[ "${{ matrix.values }}" =~ volsync.*-values.yaml ]]; then + helm install volumesnapshots oci://tccr.io/truecharts/volumesnapshot --namespace volumesnapshots --create-namespace --wait + helm install volsync oci://tccr.io/truecharts/volsync --namespace volsync --create-namespace --wait + fi - name: Run chart-testing (install) run: | diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 65210afe..5d9d56d8 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~20.4.0 + version: ~21.0.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common-test/ci/volsync-dest-values.yaml b/library/common-test/ci/volsync-dest-values.yaml new file mode 100644 index 00000000..27b40a4a --- /dev/null +++ b/library/common-test/ci/volsync-dest-values.yaml @@ -0,0 +1,24 @@ +persistence: + destbackup: + enabled: true + type: pvc + mountPath: /backedup + targetSelectAll: true + volsync: + - name: mybackup + type: restic + credentials: mys3 + dest: + enabled: true + src: + enabled: false + +credentials: + mys3: + type: s3 + url: "" + region: "" + bucket: "" + accessKey: "" + secretKey: "" + encrKey: "" diff --git a/library/common-test/ci/volsync-src-values.yaml b/library/common-test/ci/volsync-src-values.yaml new file mode 100644 index 00000000..7ccc2c2f --- /dev/null +++ b/library/common-test/ci/volsync-src-values.yaml @@ -0,0 +1,24 @@ +persistence: + srcbackup: + enabled: true + type: pvc + mountPath: /backedup + targetSelectAll: true + volsync: + - name: mybackup + type: restic + credentials: mys3 + dest: + enabled: false + src: + enabled: true + +credentials: + mys3: + type: s3 + url: "" + region: "" + bucket: "" + accessKey: "" + secretKey: "" + encrKey: "" diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 14414720..014c513b 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 20.4.0 +version: 21.0.0 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/class/volsync/_replicationDestination.tpl b/library/common/templates/class/volsync/_replicationDestination.tpl new file mode 100644 index 00000000..f3370a1a --- /dev/null +++ b/library/common/templates/class/volsync/_replicationDestination.tpl @@ -0,0 +1,49 @@ +{{/* replicationdestination Class */}} +{{/* Call this template: +{{ include "tc.v1.common.class.replicationdestination" (dict "rootCtx" $ "objectData" $objectData "volsyncData" $volsyncData) }} + +rootCtx: The root context of the chart. +objectData: + name: The name of the replicationdestination. + labels: The labels of the replicationdestination. + annotations: The annotations of the replicationdestination. + data: The data of the replicationdestination. + namespace: The namespace of the replicationdestination. (Optional) +*/}} + +{{- define "tc.v1.common.class.replicationdestination" -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + {{- $volsyncData := .volsyncData }} + +--- +apiVersion: volsync.backube/v1alpha1 +kind: replicationdestination +metadata: + name: {{ $objectData.name }}-{{ $volsyncData.name }}-dest + namespace: {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "replicationdestination") }} + {{- $labels := (mustMerge ($volsyncData.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}} + {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} + labels: + {{- . | nindent 4 }} + {{- end -}} + {{- $annotations := (mustMerge ($volsyncData.annotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}} + {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }} + annotations: + {{- . | nindent 4 }} + {{- end }} +spec: + trigger: + manual: restore-once + {{ $volsyncData.type }}: + repository: {{ $volsyncData.repository }} + copyMethod: {{ $volsyncData.copyMethod | default "Snapshot"}} + {{- with $volsyncData.dest.capacity }} + capacity: {{ $volsyncData.dest.capacity }} + {{- end }} + + {{- 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 }} +{{- end -}} diff --git a/library/common/templates/class/volsync/_replicationSource.tpl b/library/common/templates/class/volsync/_replicationSource.tpl new file mode 100644 index 00000000..6668459e --- /dev/null +++ b/library/common/templates/class/volsync/_replicationSource.tpl @@ -0,0 +1,72 @@ +{{/* replicationsource Class */}} +{{/* Call this template: +{{ include "tc.v1.common.class.replicationsource" (dict "rootCtx" $ "objectData" $objectData "volsyncData" $volsyncData) }} + +rootCtx: The root context of the chart. +objectData: + name: The name of the replicationsource. + labels: The labels of the replicationsource. + annotations: The annotations of the replicationsource. + data: The data of the replicationsource. + namespace: The namespace of the replicationsource. (Optional) +*/}} + +{{- define "tc.v1.common.class.replicationsource" -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + {{- $volsyncData := .volsyncData -}} + + {{- $schedule := "0 0 * * *" -}} + {{- if and $volsyncData.src.trigger $volsyncData.src.trigger.schedule -}} + {{- $schedule = $volsyncData.src.trigger.schedule -}} + {{- end }} + + {{- $hourly := 24 -}} + {{- $daily := 7 -}} + {{- $weekly := 5 -}} + {{- if and $volsyncData.src.retain -}} + {{- with $volsyncData.src.retain.hourly -}} + {{- $hourly = . }} + {{- end -}} + {{- with $volsyncData.src.retain.daily -}} + {{- $daily = . }} + {{- end -}} + {{- with $volsyncData.src.retain.weekly -}} + {{- $weekly = . }} + {{- end -}} + {{- end }} +--- +apiVersion: volsync.backube/v1alpha1 +kind: ReplicationSource +metadata: + name: {{ $objectData.name }}-{{ $volsyncData.name }} + namespace: {{ include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $rootCtx "objectData" $objectData "caller" "replicationsource") }} + {{- $labels := (mustMerge ($volsyncData.labels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}} + {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} + labels: + {{- . | nindent 4 }} + {{- end -}} + {{- $annotations := (mustMerge ($volsyncData.annotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}} + {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }} + annotations: + {{- . | nindent 4 }} + {{- end }} +spec: + sourcePVC: {{ $objectData.name }} + trigger: + schedule: {{ $schedule }} + {{ $volsyncData.type }}: + repository: {{ $volsyncData.repository }} + copyMethod: {{ $volsyncData.copyMethod | default "Snapshot" }} + pruneIntervalDays: {{ $volsyncData.src.pruneIntervalDays | default 7 }} + + {{- include "tc.v1.common.lib.volsync.storage" (dict "rootCtx" $rootCtx "objectData" $objectData "volsyncData" $volsyncData "target" "src") | trim | nindent 4 }} + {{- include "tc.v1.common.lib.volsync.cache" (dict "rootCtx" $rootCtx "objectData" $objectData "volsyncData" $volsyncData "target" "src") | trim | nindent 4 }} + {{- include "tc.v1.common.lib.volsync.moversecuritycontext" (dict "rootCtx" $rootCtx "objectData" $objectData "volsyncData" $volsyncData "target" "src") | trim | nindent 4 }} + + retain: + hourly: {{ $hourly }} + daily: {{ $daily }} + weekly: {{ $weekly }} +{{- end }} diff --git a/library/common/templates/lib/storage/pvc/_spec.tpl b/library/common/templates/lib/storage/pvc/_spec.tpl index 0a7ef991..e60efcf4 100644 --- a/library/common/templates/lib/storage/pvc/_spec.tpl +++ b/library/common/templates/lib/storage/pvc/_spec.tpl @@ -35,4 +35,11 @@ dataSource: kind: {{ .kind }} name: {{ $sourceName }} {{- end -}} + +{{- with $objectData.dataSourceRef }} +dataSourceRef: + kind: {{ .kind }} + name: {{ .name }} + apiGroup: {{ .apiGroup }} +{{- end -}} {{- end -}} diff --git a/library/common/templates/lib/volsync/_cache.tpl b/library/common/templates/lib/volsync/_cache.tpl new file mode 100644 index 00000000..f01e5474 --- /dev/null +++ b/library/common/templates/lib/volsync/_cache.tpl @@ -0,0 +1,23 @@ +{{- define "tc.v1.common.lib.volsync.cache" -}} + {{- $creds := .creds -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + {{- $volsyncData := .volsyncData -}} + {{- $target := get $volsyncData .target -}} + + {{- with $target.cacheCapacity }} +cacheCapacity: {{ $target.cacheCapacity }} + {{- end -}} + + {{- with $target.cacheStorageClassName }} +cacheStorageClassName: {{ $target.cacheStorageClassName }} + {{- end -}} + + {{- with $target.cacheAccessModes }} +cacheAccessModes: + {{- range . }} + - {{ . }} + {{- end }} + {{- end -}} +{{- end -}} diff --git a/library/common/templates/lib/volsync/_moverSecurityContext.tpl b/library/common/templates/lib/volsync/_moverSecurityContext.tpl new file mode 100644 index 00000000..f6bcdfd2 --- /dev/null +++ b/library/common/templates/lib/volsync/_moverSecurityContext.tpl @@ -0,0 +1,29 @@ +{{- define "tc.v1.common.lib.volsync.moversecuritycontext" -}} + {{- $creds := .creds -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + {{- $volsyncData := .volsyncData -}} + {{- $target := get $volsyncData .target -}} + + {{- $runAsUser := $rootCtx.Values.securityContext.container.runAsUser -}} + {{- $runAsGroup := $rootCtx.Values.securityContext.container.runAsGroup -}} + {{- $fsGroup := $rootCtx.Values.securityContext.pod.fsGroup -}} + + {{- if $target.moverSecurityContext -}} + {{- with $target.moverSecurityContext.runAsUser -}} {{/* TODO: Handle 0 here */}} + {{- $runAsUser = . | default $runAsUser -}} + {{- end -}} + {{- with $target.moverSecurityContext.runAsGroup -}} {{/* TODO: Handle 0 here */}} + {{- $runAsGroup = . | default $runAsGroup -}} + {{- end -}} + {{- with $target.moverSecurityContext.fsGroup -}} {{/* TODO: Handle 0 here */}} + {{- $fsGroup = . | default $fsGroup -}} + {{- end -}} + {{- end }} + +moverSecurityContext: + runAsUser: {{ $runAsUser }} + runAsGroup: {{ $runAsGroup }} + fsGroup: {{ $fsGroup }} +{{- end -}} diff --git a/library/common/templates/lib/volsync/_storage.tpl b/library/common/templates/lib/volsync/_storage.tpl new file mode 100644 index 00000000..f9f34395 --- /dev/null +++ b/library/common/templates/lib/volsync/_storage.tpl @@ -0,0 +1,23 @@ +{{- define "tc.v1.common.lib.volsync.storage" -}} + {{- $creds := .creds -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + {{- $volsyncData := .volsyncData -}} + {{- $target := get $volsyncData .target -}} + + {{- with $target.storageClassName }} +storageClassName: {{ . }} + {{- end -}} + + {{- with $target.accessModes }} +accessModes: + {{- range . }} + - {{ . }} + {{- end }} + {{- end -}} + + {{- with $target.volumeSnapshotClassName }} +volumeSnapshotClassName: {{ . }} + {{- end -}} +{{- end -}} diff --git a/library/common/templates/spawner/_pvc.tpl b/library/common/templates/spawner/_pvc.tpl index 3197e42d..28915284 100644 --- a/library/common/templates/spawner/_pvc.tpl +++ b/library/common/templates/spawner/_pvc.tpl @@ -79,6 +79,44 @@ {{- end -}} + {{/* Create VolSync objects */}} + {{- range $objectData.volsync -}} + {{- if or .src.enabled .dest.enabled -}} + {{- $volsyncData := (mustDeepCopy .) -}} + + {{/* Create Secret for VolSync */}} + {{- $volsyncSecretName := printf "%s-volsync-%s" $objectData.name .name -}} + {{- $_ := set $volsyncData "repository" $volsyncSecretName -}} + + {{- $credentials := get $.Values.credentials .credentials -}} + {{- $resticrepository := printf "s3:%s/%s/%s/%s" $credentials.url $credentials.bucket $.Release.Name $volsyncSecretName -}} + {{- $resticpassword := $credentials.encrKey -}} + {{- $s3id := $credentials.accessKey -}} + {{- $s3key := $credentials.secretKey -}} + + {{- $volsyncSecretData := (dict + "name" $volsyncSecretName + "labels" (.labels | default dict) + "annotations" (.annotations | default dict) + "data" (dict "RESTIC_REPOSITORY" $resticrepository "RESTIC_PASSWORD" $resticpassword "AWS_ACCESS_KEY_ID" $s3id "AWS_SECRET_ACCESS_KEY" $s3key) + ) -}} + {{- include "tc.v1.common.class.secret" (dict "rootCtx" $ "objectData" $volsyncSecretData) -}} + + {{/* Create VolSync resources*/}} + {{- if .src.enabled -}} + {{- include "tc.v1.common.class.replicationsource" (dict "rootCtx" $ "objectData" $objectData "volsyncData" $volsyncData) -}} + {{- end -}} + {{- if .dest.enabled -}} + {{- include "tc.v1.common.class.replicationdestination" (dict "rootCtx" $ "objectData" $objectData "volsyncData" $volsyncData) -}} + + {{/* modify PVC if enabled */}} + {{- $destname := printf "%s-%s-dest" $objectData.name $volsyncData.name -}} + {{- $datasourceref := dict "kind" "ReplicationDestination" "apiGroup" "volsync.backube" "name" $destname -}} + {{- $_ := set $objectData "dataSourceRef" $datasourceref -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{/* Call class to create the object */}} {{- include "tc.v1.common.class.pvc" (dict "rootCtx" $ "objectData" $objectData) -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index ad78141d..aceee9cc 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -225,6 +225,17 @@ service: serviceList: [] +credentials: {} + # mys3: + # type: s3 + # url: "" + # region: "" + # bucket: "" + # accessKey: "" + # secretKey: "" + # encrKey: "" + + # -- (docs/persistence/README.md) persistence: shared: @@ -256,6 +267,20 @@ persistence: mountPath: /dev/shm medium: Memory targetSelectAll: true +# backupexample: +# enabled: true +# type: pvc +# mountPath: /backedup +# targetSelectAll: true +# volsync: +# - name: mybackup +# ## TODO: other options +# type: restic +# credentials: mys3 +# dest: +# enabled: true +# src: +# enabled: true # iscsi: # enabled: true # type: iscsi