migrate 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/python3
  2. import json
  3. import os
  4. import sys
  5. def migrate_common_lib(values):
  6. delete_keys = [
  7. 'nodePort', 'certificate', 'enableResourceLimits', 'cpuLimit', 'memLimit',
  8. 'environmentVariables', 'extraAppVolumeMounts', 'config', 'updateStrategy',
  9. 'nginx',
  10. ]
  11. values.update({
  12. # Migrate Network
  13. 'collaboraNetwork': {
  14. 'webPort': values['nodePort'],
  15. 'certificateID': values['certificate'],
  16. },
  17. # Migrate Resources
  18. 'resources': {
  19. 'limits': {
  20. 'cpu': values.get('cpuLimit', '4000m'),
  21. 'memory': values.get('memLimit', '8Gi'),
  22. }
  23. },
  24. 'TZ': values['config']['timezone'],
  25. # Migrate Config
  26. 'collaboraConfig': {
  27. 'enableWebUI': values['config']['enableWebUI'],
  28. 'username': values['config'].get('username', ''),
  29. 'password': values['config'].get('password', ''),
  30. 'serverName': values['config']['server_name'],
  31. 'dictionaries': [d for d in values['config']['dictionaries'].split(' ') if d],
  32. 'extraParams': [p for p in values['config']['extra_params'].split(' ') if p],
  33. 'aliasGroup1': values['config']['aliasgroup1'],
  34. 'additionalEnvs': values.get('environmentVariables', []),
  35. },
  36. # Migrate Storage
  37. 'collaboraStorage': {
  38. 'additionalStorages': [
  39. {
  40. 'type': 'hostPath',
  41. 'hostPathConfig': {'hostPath': e['hostPath']},
  42. 'mountPath': e['mountPath'],
  43. 'readOnly': e.get('readOnly', False),
  44. }
  45. for e in values.get('extraAppVolumeMounts', [])
  46. ],
  47. },
  48. })
  49. for k in delete_keys:
  50. values.pop(k, None)
  51. return values
  52. def migrate(values):
  53. # If this missing, we have already migrated
  54. if not 'nodePort' in values.keys():
  55. return values
  56. return migrate_common_lib(values)
  57. if __name__ == '__main__':
  58. if len(sys.argv) != 2:
  59. exit(1)
  60. if os.path.exists(sys.argv[1]):
  61. with open(sys.argv[1], 'r') as f:
  62. print(json.dumps(migrate(json.loads(f.read()))))