-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
planka - migrate storage section (#1768)
* planka - migrate storage section * reduce diff * typo * add missing key * remove test snippet * optimize * remove empty lines * restore immutable flag
- Loading branch information
Showing
11 changed files
with
512 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
dependencies: | ||
- name: common | ||
repository: file://../../../common | ||
version: 1.2.2 | ||
digest: sha256:fb077cb81f6acecd5c9e6adc22a18e156f780cd78f27198cdb47810f95364b56 | ||
generated: "2023-11-09T15:43:04.016439777+02:00" | ||
version: 1.2.3 | ||
digest: sha256:e6ff49b06bf5d4d159e505ae6d153f36cd46170bb519caf90462cd5caebfd0fb | ||
generated: "2023-11-20T10:17:20.436068522+02:00" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/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': | ||
# Fixes an invalid key carried from values.yaml | ||
storage.pop('hostPath', None) | ||
|
||
# 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 = 'plankaStorage' | ||
storages = ['avatars', 'backgroundImages', 'attachments', 'pgData', 'pgBackup'] | ||
|
||
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())))) |
Oops, something went wrong.