homer - migrate storage section (adds acl) (#1952)

* update templates

* bump version

* add migration

* update values

* update ui
This commit is contained in:
Stavros Kois
2023-12-27 13:00:36 +02:00
committed by GitHub
parent e81859a9be
commit bb92f2f900
6 changed files with 234 additions and 88 deletions

View File

@@ -3,7 +3,7 @@ description: Homer is a dead simple static HOMepage for your servER to keep your
annotations: annotations:
title: Homer title: Homer
type: application type: application
version: 1.1.6 version: 1.2.0
apiVersion: v2 apiVersion: v2
appVersion: 23.10.1 appVersion: 23.10.1
kubeVersion: '>=1.16.0-0' kubeVersion: '>=1.16.0-0'

View File

@@ -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 = 'homerStorage'
storages = ['assets']
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()))))

View File

@@ -129,23 +129,63 @@ questions:
description: Host Path (Path that already exists on the system) description: Host Path (Path that already exists on the system)
- value: "ixVolume" - value: "ixVolume"
description: ixVolume (Dataset created automatically by the system) description: ixVolume (Dataset created automatically by the system)
- variable: datasetName - variable: ixVolumeConfig
label: Dataset Name label: ixVolume Configuration
description: The configuration for the ixVolume dataset.
schema: schema:
type: string type: dict
show_if: [["type", "=", "ixVolume"]] show_if: [["type", "=", "ixVolume"]]
required: true
hidden: true
immutable: true
default: "assets"
$ref: $ref:
- "normalize/ixVolume" - "normalize/ixVolume"
- variable: hostPath attrs:
label: Host Path - variable: aclEnable
label: Enable ACL
description: Enable ACL for the dataset.
schema:
type: boolean
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: "assets"
- variable: aclEntries
label: ACL Configuration
schema:
type: dict
show_if: [["aclEnable", "=", true]]
attrs: []
- variable: hostPathConfig
label: Host Path Configuration
schema: schema:
type: hostpath type: dict
show_if: [["type", "=", "hostPath"]] show_if: [["type", "=", "hostPath"]]
required: true attrs:
- variable: aclEnable
label: Enable ACL
description: Enable ACL for the dataset.
schema:
type: boolean
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 - variable: additionalStorages
label: Additional Storage label: Additional Storage
description: Additional storage for Homer. description: Additional storage for Homer.
@@ -176,74 +216,119 @@ questions:
description: ixVolume (Dataset created automatically by the system) description: ixVolume (Dataset created automatically by the system)
- value: "smb-pv-pvc" - value: "smb-pv-pvc"
description: SMB Share (Mounts a persistent volume claim to a SMB share) 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
default: false
- variable: mountPath - variable: mountPath
label: Mount Path label: Mount Path
description: The path inside the container to mount the storage. description: The path inside the container to mount the storage.
schema: schema:
type: path type: path
required: true required: true
- variable: hostPath - variable: hostPathConfig
label: Host Path label: Host Path Configuration
description: The host path to use for storage.
schema: schema:
type: hostpath type: dict
show_if: [["type", "=", "hostPath"]] show_if: [["type", "=", "hostPath"]]
required: true attrs:
- variable: datasetName - variable: aclEnable
label: Dataset Name label: Enable ACL
description: The name of the dataset to use for storage. description: Enable ACL for the dataset.
schema:
type: boolean
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: ixVolumeConfig
label: ixVolume Configuration
description: The configuration for the ixVolume dataset.
schema: schema:
type: string type: dict
show_if: [["type", "=", "ixVolume"]] show_if: [["type", "=", "ixVolume"]]
required: true
immutable: true
default: "storage_entry"
$ref: $ref:
- "normalize/ixVolume" - "normalize/ixVolume"
- variable: server attrs:
label: Server - variable: aclEnable
description: The server for the SMB share. label: Enable ACL
description: Enable ACL for the dataset.
schema:
type: boolean
default: false
- variable: datasetName
label: Dataset Name
description: The name of the dataset to use for storage.
schema:
type: string
required: true
immutable: true
default: "storage_entry"
- variable: aclEntries
label: ACL Configuration
schema:
type: dict
show_if: [["aclEnable", "=", true]]
attrs: []
- variable: smbConfig
label: SMB Share Configuration
description: The configuration for the SMB Share.
schema: schema:
type: string type: dict
show_if: [["type", "=", "smb-pv-pvc"]] show_if: [["type", "=", "smb-pv-pvc"]]
required: true attrs:
- variable: share - variable: server
label: Share label: Server
description: The share name for the SMB share. description: The server for the SMB share.
schema: schema:
type: string type: string
show_if: [["type", "=", "smb-pv-pvc"]] required: true
required: true - variable: share
- variable: domain label: Share
label: Domain (Optional) description: The share name for the SMB share.
description: The domain for the SMB share. schema:
schema: type: string
type: string required: true
show_if: [["type", "=", "smb-pv-pvc"]] - variable: domain
- variable: username label: Domain (Optional)
label: Username description: The domain for the SMB share.
description: The username for the SMB share. schema:
schema: type: string
type: string - variable: username
show_if: [["type", "=", "smb-pv-pvc"]] label: Username
required: true description: The username for the SMB share.
- variable: password schema:
label: Password type: string
description: The password for the SMB share. required: true
schema: - variable: password
type: string label: Password
show_if: [["type", "=", "smb-pv-pvc"]] description: The password for the SMB share.
required: true schema:
private: true type: string
- variable: size required: true
label: Size (in Gi) private: true
description: The size of the volume quota. - variable: size
schema: label: Size (in Gi)
type: int description: The size of the volume quota.
show_if: [["type", "=", "smb-pv-pvc"]] schema:
required: true type: int
min: 1 required: true
default: 1 min: 1
default: 1
- variable: resources - variable: resources
group: Resources Configuration group: Resources Configuration

View File

@@ -45,5 +45,5 @@ workload:
"UID" .Values.homerRunAs.user "UID" .Values.homerRunAs.user
"GID" .Values.homerRunAs.group "GID" .Values.homerRunAs.group
"mode" "check" "mode" "check"
"type" "init") | nindent 8 }} "type" "install") | nindent 8 }}
{{- end -}} {{- end -}}

View File

@@ -2,15 +2,16 @@
persistence: persistence:
assets: assets:
enabled: true enabled: true
type: {{ .Values.homerStorage.assets.type }} {{- include "ix.v1.common.app.storageOptions" (dict "storage" .Values.homerStorage.assets) | nindent 4 }}
datasetName: {{ .Values.homerStorage.assets.datasetName | default "" }}
hostPath: {{ .Values.homerStorage.assets.hostPath | default "" }}
targetSelector: targetSelector:
homer: homer:
homer: homer:
mountPath: /www/assets mountPath: /www/assets
{{- if and (eq .Values.homerStorage.assets.type "ixVolume")
(not (.Values.homerStorage.assets.ixVolumeConfig | default dict).aclEnable) }}
01-permissions: 01-permissions:
mountPath: /mnt/directories/assets mountPath: /mnt/directories/assets
{{- end }}
tmp: tmp:
enabled: true enabled: true
type: emptyDir type: emptyDir
@@ -20,29 +21,15 @@ persistence:
mountPath: /tmp mountPath: /tmp
{{- range $idx, $storage := .Values.homerStorage.additionalStorages }} {{- range $idx, $storage := .Values.homerStorage.additionalStorages }}
{{ printf "homer-%v" (int $idx) }}: {{ printf "homer-%v" (int $idx) }}:
{{- $size := "" -}}
{{- if $storage.size -}}
{{- $size = (printf "%vGi" $storage.size) -}}
{{- end }}
enabled: true enabled: true
type: {{ $storage.type }} {{- include "ix.v1.common.app.storageOptions" (dict "storage" $storage) | nindent 4 }}
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 }}
targetSelector: targetSelector:
homer: homer:
homer: homer:
mountPath: {{ $storage.mountPath }} mountPath: {{ $storage.mountPath }}
{{- if and (eq $storage.type "ixVolume") (not ($storage.ixVolumeConfig | default dict).aclEnable) }}
01-permissions: 01-permissions:
mountPath: /mnt/directories{{ $storage.mountPath }} mountPath: /mnt/directories{{ $storage.mountPath }}
{{- end }}
{{- end }} {{- end }}
{{- end -}} {{- end -}}

View File

@@ -23,5 +23,6 @@ homerRunAs:
homerStorage: homerStorage:
assets: assets:
type: ixVolume type: ixVolume
datasetName: assets ixVolumeConfig:
datasetName: assets
additionalStorages: [] additionalStorages: []