1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/python3
- import json
- import os
- import sys
- def migrate_common_lib(values):
- delete_keys = [
- 'nodePort', 'certificate', 'enableResourceLimits', 'cpuLimit', 'memLimit',
- 'environmentVariables', 'extraAppVolumeMounts', 'config', 'updateStrategy',
- 'nginx',
- ]
- values.update({
- # Migrate Network
- 'collaboraNetwork': {
- 'webPort': values['nodePort'],
- 'certificateID': values['certificate'],
- },
- # Migrate Resources
- 'resources': {
- 'limits': {
- 'cpu': values.get('cpuLimit', '4000m'),
- 'memory': values.get('memLimit', '8Gi'),
- }
- },
- 'TZ': values['config']['timezone'],
- # Migrate Config
- 'collaboraConfig': {
- 'enableWebUI': values['config']['enableWebUI'],
- 'username': values['config']['username'],
- 'password': values['config']['password'],
- 'serverName': values['config']['server_name'],
- 'dictionaries': [d for d in values['config']['dictionaries'].split(' ') if d],
- 'extraParams': [p for p in values['config']['extra_params'].split(' ') if p],
- 'aliasGroup1': values['config']['aliasgroup1'],
- 'additionalEnvs': values.get('environmentVariables', []),
- },
- # Migrate Storage
- 'collaboraStorage': {
- 'additionalStorages': [
- {
- 'type': 'hostPath',
- 'hostPathConfig': {'hostPath': e['hostPath']},
- 'mountPath': e['mountPath'],
- 'readOnly': e.get('readOnly', False),
- }
- for e in values.get('extraAppVolumeMounts', [])
- ],
- },
- })
- for k in delete_keys:
- values.pop(k, None)
- return values
- def migrate(values):
- # If this missing, we have already migrated
- if not 'nodePort' in values.keys():
- return values
- return migrate_common_lib(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()))))
|