Преглед на файлове

syncthing/test - migrate storage section (#2008)

* bump version

* update values

* update ui

* update templates

* add migration

* keep previous version
Stavros Kois преди 1 година
родител
ревизия
95fb009bf6

+ 1 - 1
library/ix-dev/test/syncthing/Chart.yaml

@@ -3,7 +3,7 @@ description: Syncthing is a continuous file synchronization program.
 annotations:
   title: Syncthing
 type: application
-version: 1.1.5
+version: 1.2.0
 apiVersion: v2
 appVersion: '1.27.0'
 kubeVersion: '>=1.16.0-0'

+ 4 - 8
library/ix-dev/test/syncthing/ci/basic-no-hostnet-values.yaml

@@ -1,16 +1,12 @@
 syncthingStorage:
   home:
-    type: hostPath
-    hostPath: /mnt/{{ .Release.Namespace }}/home
+    type: pvc
   additionalStorages:
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir1
+    - type: pvc
       mountPath: /mnt/dir1
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir2
+    - type: pvc
       mountPath: /mnt/dir2
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir3
+    - type: pvc
       mountPath: /mnt/dir3
 
 syncthingID:

+ 4 - 8
library/ix-dev/test/syncthing/ci/basic-values.yaml

@@ -1,16 +1,12 @@
 syncthingStorage:
   home:
-    type: hostPath
-    hostPath: /mnt/{{ .Release.Namespace }}/home
+    type: pvc
   additionalStorages:
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir1
+    - type: pvc
       mountPath: /mnt/dir1
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir2
+    - type: pvc
       mountPath: /mnt/dir2
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir3
+    - type: pvc
       mountPath: /mnt/dir3
 
 syncthingID:

+ 4 - 8
library/ix-dev/test/syncthing/ci/https-no-hostnet-values.yaml

@@ -1,16 +1,12 @@
 syncthingStorage:
   home:
-    type: hostPath
-    hostPath: /mnt/{{ .Release.Namespace }}/home
+    type: pvc
   additionalStorages:
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir1
+    - type: pvc
       mountPath: /mnt/dir1
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir2
+    - type: pvc
       mountPath: /mnt/dir2
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir3
+    - type: pvc
       mountPath: /mnt/dir3
 
 syncthingID:

+ 4 - 8
library/ix-dev/test/syncthing/ci/https-values.yaml

@@ -1,16 +1,12 @@
 syncthingStorage:
   home:
-    type: hostPath
-    hostPath: /mnt/{{ .Release.Namespace }}/home
+    type: pvc
   additionalStorages:
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir1
+    - type: pvc
       mountPath: /mnt/dir1
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir2
+    - type: pvc
       mountPath: /mnt/dir2
-    - type: hostPath
-      hostPath: /mnt/{{ .Release.Namespace }}/dir3
+    - type: pvc
       mountPath: /mnt/dir3
 
 syncthingID:

+ 73 - 0
library/ix-dev/test/syncthing/migrations/migrate

@@ -0,0 +1,73 @@
+#!/usr/bin/python3
+import json
+import os
+import sys
+
+
+def storage_migrate(storage):
+    delete_keys = []
+    if storage['type'] == 'hostPath':
+        # Check if the key exists, if not we have already migrated
+        if not storage.get('hostPath'):
+            return storage
+
+        storage['hostPathConfig'] = {'hostPath': storage['hostPath']}
+        delete_keys.append('hostPath')
+
+    elif storage['type'] == 'ixVolume':
+        # Check if the key exists, if not we have already migrated
+        if not storage.get('datasetName'):
+            return storage
+
+        storage['ixVolumeConfig'] = {'datasetName': storage['datasetName']}
+        delete_keys.append('datasetName')
+
+    elif storage['type'] == 'smb-pv-pvc':
+        # Check if the key exists, if not we have already migrated
+        if not storage.get('server'):
+            return storage
+
+        storage['smbConfig'] = {
+            'server': storage['server'],
+            'share': storage['share'],
+            'domain': storage['domain'],
+            'username': storage['username'],
+            'password': storage['password'],
+            'size': storage['size'],
+        }
+        delete_keys.extend(['server', 'share', 'domain', 'username', 'password', 'size'])
+
+    for key in delete_keys:
+        storage.pop(key, None)
+
+    return storage
+
+
+def migrate(values):
+    storage_key = 'syncthingStorage'
+    storages = ['home']
+
+    for storage in storages:
+        check_val = values.get(storage_key, {}).get(storage, {})
+        if not isinstance(check_val, dict) or not check_val:
+            raise Exception(f'Storage section {storage} is malformed')
+
+        values[storage_key][storage] = storage_migrate(check_val)
+
+    additionalStorages = values.get(storage_key, {}).get('additionalStorages', [])
+    for idx, storage in enumerate(additionalStorages):
+        if not isinstance(storage, dict) or not storage:
+            raise Exception(f'Item {idx} in additionalStorages is malformed')
+
+        values[storage_key]['additionalStorages'][idx] = storage_migrate(storage)
+
+    return values
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        exit(1)
+
+    if os.path.exists(sys.argv[1]):
+        with open(sys.argv[1], 'r') as f:
+            print(json.dumps(migrate(json.loads(f.read()))))

+ 131 - 60
library/ix-dev/test/syncthing/questions.yaml

@@ -206,24 +206,66 @@ questions:
                       description: Host Path (Path that already exists on the system)
                     - value: "ixVolume"
                       description: ixVolume (Dataset created automatically by the system)
-              - variable: datasetName
-                label: Dataset Name
+              - variable: ixVolumeConfig
+                label: ixVolume Configuration
+                description: The configuration for the ixVolume dataset.
                 schema:
-                  type: string
+                  type: dict
                   show_if: [["type", "=", "ixVolume"]]
-                  required: true
-                  hidden: true
-                  immutable: true
-                  default: "home"
                   $ref:
                     - "normalize/ixVolume"
-              - variable: hostPath
-                label: Host Path
+                  attrs:
+                    - variable: aclEnable
+                      label: Enable ACL
+                      description: Enable ACL for the dataset.
+                      schema:
+                        type: boolean
+                        hidden: true
+                        default: false
+                    - variable: datasetName
+                      label: Dataset Name
+                      description: The name of the dataset to use for storage.
+                      schema:
+                        type: string
+                        required: true
+                        immutable: true
+                        hidden: true
+                        default: "home"
+                    - variable: aclEntries
+                      label: ACL Configuration
+                      schema:
+                        type: dict
+                        show_if: [["aclEnable", "=", true]]
+                        attrs: []
+              - variable: hostPathConfig
+                label: Host Path Configuration
                 schema:
-                  type: hostpath
+                  type: dict
                   show_if: [["type", "=", "hostPath"]]
-                  immutable: true
-                  required: true
+                  attrs:
+                    - variable: aclEnable
+                      label: Enable ACL
+                      description: Enable ACL for the dataset.
+                      schema:
+                        type: boolean
+                        hidden: true
+                        default: false
+                    - variable: acl
+                      label: ACL Configuration
+                      schema:
+                        type: dict
+                        show_if: [["aclEnable", "=", true]]
+                        attrs: []
+                        $ref:
+                          - "normalize/acl"
+                    - variable: hostPath
+                      label: Host Path
+                      description: The host path to use for storage.
+                      schema:
+                        type: hostpath
+                        show_if: [["aclEnable", "=", false]]
+                        required: true
+
         - variable: additionalStorages
           label: Additional Storage
           description: Additional storage for Syncthing.
@@ -245,7 +287,7 @@ questions:
                       label: Type
                       description: |
                         Host Path: Is a path that already exists on the system.</br>
-                        SMB Share: Mounts a persistent volume claim to a SMB share.
+                        SMB Share: Is a SMB share that is mounted to a persistent volume claim.
                       schema:
                         type: string
                         required: true
@@ -256,63 +298,92 @@ questions:
                             description: Host Path (Path that already exists on the system)
                           - value: "smb-pv-pvc"
                             description: SMB Share (Mounts a persistent volume claim to a SMB share)
+                    - variable: readOnly
+                      label: Read Only
+                      description: Mount the volume as read only.
+                      schema:
+                        type: boolean
+                        hidden: true
+                        default: false
                     - variable: mountPath
                       label: Mount Path
                       description: The path inside the container to mount the storage.
                       schema:
                         type: path
                         required: true
-                    - variable: hostPath
-                      label: Host Path
-                      description: The host path to use for storage.
+                    - variable: hostPathConfig
+                      label: Host Path Configuration
                       schema:
-                        type: hostpath
+                        type: dict
                         show_if: [["type", "=", "hostPath"]]
-                        required: true
-                    - variable: server
-                      label: Server
-                      description: The server for the SMB share.
+                        attrs:
+                          - variable: aclEnable
+                            label: Enable ACL
+                            description: Enable ACL for the dataset.
+                            schema:
+                              type: boolean
+                              hidden: true
+                              default: false
+                          - variable: acl
+                            label: ACL Configuration
+                            schema:
+                              type: dict
+                              show_if: [["aclEnable", "=", true]]
+                              attrs: []
+                              $ref:
+                                - "normalize/acl"
+                          - variable: hostPath
+                            label: Host Path
+                            description: The host path to use for storage.
+                            schema:
+                              type: hostpath
+                              show_if: [["aclEnable", "=", false]]
+                              required: true
+                    - variable: smbConfig
+                      label: SMB Share Configuration
+                      description: The configuration for the SMB Share.
                       schema:
-                        type: string
+                        type: dict
                         show_if: [["type", "=", "smb-pv-pvc"]]
-                        required: true
-                    - variable: share
-                      label: Share
-                      description: The share name for the SMB share.
-                      schema:
-                        type: string
-                        show_if: [["type", "=", "smb-pv-pvc"]]
-                        required: true
-                    - variable: domain
-                      label: Domain (Optional)
-                      description: The domain for the SMB share.
-                      schema:
-                        type: string
-                        show_if: [["type", "=", "smb-pv-pvc"]]
-                    - variable: username
-                      label: Username
-                      description: The username for the SMB share.
-                      schema:
-                        type: string
-                        show_if: [["type", "=", "smb-pv-pvc"]]
-                        required: true
-                    - variable: password
-                      label: Password
-                      description: The password for the SMB share.
-                      schema:
-                        type: string
-                        show_if: [["type", "=", "smb-pv-pvc"]]
-                        required: true
-                        private: true
-                    - variable: size
-                      label: Size (in Gi)
-                      description: The size of the volume quota.
-                      schema:
-                        type: int
-                        show_if: [["type", "=", "smb-pv-pvc"]]
-                        required: true
-                        min: 1
-                        default: 1
+                        attrs:
+                          - variable: server
+                            label: Server
+                            description: The server for the SMB share.
+                            schema:
+                              type: string
+                              required: true
+                          - variable: share
+                            label: Share
+                            description: The share name for the SMB share.
+                            schema:
+                              type: string
+                              required: true
+                          - variable: domain
+                            label: Domain (Optional)
+                            description: The domain for the SMB share.
+                            schema:
+                              type: string
+                          - variable: username
+                            label: Username
+                            description: The username for the SMB share.
+                            schema:
+                              type: string
+                              required: true
+                          - variable: password
+                            label: Password
+                            description: The password for the SMB share.
+                            schema:
+                              type: string
+                              required: true
+                              private: true
+                          - variable: size
+                            label: Size (in Gi)
+                            description: The size of the volume quota.
+                            schema:
+                              type: int
+                              required: true
+                              min: 1
+                              default: 1
 
   - variable: resources
     group: Resources Configuration

+ 14 - 20
library/ix-dev/test/syncthing/templates/_persistence.tpl

@@ -2,9 +2,8 @@
 persistence:
   home:
     enabled: true
-    type: {{ .Values.syncthingStorage.home.type }}
-    datasetName: {{ .Values.syncthingStorage.home.datasetName | default "" }}
-    hostPath: {{ .Values.syncthingStorage.home.hostPath | default "" }}
+    {{- include "syncthing.storage.ci.migration" (dict "storage" .Values.syncthingStorage.home) }}
+    {{- include "ix.v1.common.app.storageOptions" (dict "storage" .Values.syncthingStorage.home) | nindent 4 }}
     targetSelector:
       syncthing:
         syncthing:
@@ -38,24 +37,9 @@ persistence:
 
   {{- range $idx, $storage := .Values.syncthingStorage.additionalStorages }}
   {{ printf "sync-%v" (int $idx) }}:
-    {{- $size := "" -}}
-    {{- if $storage.size -}}
-      {{- $size = (printf "%vGi" $storage.size) -}}
-    {{- end }}
     enabled: true
-    type: {{ $storage.type }}
-    datasetName: {{ $storage.datasetName | default "" }}
-    hostPath: {{ $storage.hostPath | default "" }}
-    server: {{ $storage.server | default "" }}
-    share: {{ $storage.share | default "" }}
-    domain: {{ $storage.domain | default "" }}
-    username: {{ $storage.username | default "" }}
-    password: {{ $storage.password | default "" }}
-    size: {{ $size }}
-    {{- if eq $storage.type "smb-pv-pvc" }}
-    mountOptions:
-      - key: noperm
-    {{- end }}
+    {{- include "syncthing.storage.ci.migration" (dict "storage" $storage) }}
+    {{- include "ix.v1.common.app.storageOptions" (dict "storage" $storage) | nindent 4 }}
     targetSelector:
       syncthing:
         syncthing:
@@ -85,3 +69,13 @@ scaleCertificate:
     id: {{ .Values.syncthingNetwork.certificateID }}
     {{- end -}}
 {{- end -}}
+
+{{/* TODO: Remove on the next version bump, eg 1.2.0+ */}}
+{{- define "syncthing.storage.ci.migration" -}}
+  {{- $storage := .storage -}}
+
+  {{- if $storage.hostPath -}}
+    {{- $_ := set $storage "hostPathConfig" dict -}}
+    {{- $_ := set $storage.hostPathConfig "hostPath" $storage.hostPath -}}
+  {{- end -}}
+{{- end -}}

+ 3 - 0
library/ix-dev/test/syncthing/to_keep_versions.md

@@ -0,0 +1,3 @@
+# 1.1.5
+
+This version is kept in order to be able to test the storage section migration

+ 1 - 0
library/ix-dev/test/syncthing/to_keep_versions.yaml

@@ -0,0 +1 @@
+- 1.1.5

+ 2 - 1
library/ix-dev/test/syncthing/values.yaml

@@ -35,5 +35,6 @@ syncthingNetwork:
 syncthingStorage:
   home:
     type: ixVolume
-    datasetName: home
+    ixVolumeConfig:
+      datasetName: home
   additionalStorages: []