migrate 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/python3
  2. import json
  3. import os
  4. import sys
  5. def migrate_volume(volume):
  6. return {
  7. 'type': 'hostPath',
  8. 'hostPathConfig': {
  9. 'hostPath': volume['hostPath']
  10. },
  11. } if volume.get('hostPathEnabled', False) else {
  12. 'type': 'ixVolume',
  13. 'ixVolumeConfig': {
  14. 'datasetName': volume['datasetName'],
  15. },
  16. }
  17. def migrate_common_lib(values):
  18. delete_keys = [
  19. 'dnsConfig', 'updateStrategy', 'enableResourceLimits', 'cpuLimit',
  20. 'memLimit', 'certificate', 'service', 'environmentVariables', 'minioDomain',
  21. 'accessKey', 'secretKey', 'distributedMode', 'distributedIps', 'logsearchapi',
  22. 'appVolumeMounts', 'extraAppVolumeMounts', 'postgresAppVolumeMounts'
  23. ]
  24. values.update({
  25. # Migrate Config
  26. 'minioConfig': {
  27. 'rootUser': values['accessKey'],
  28. 'rootPassword': values['secretKey'],
  29. 'domain': values.get('minioDomain', ''),
  30. 'extraArgs': values.get('extraArgs', []),
  31. 'additionalEnvs': [e for e in values.get('environmentVariables', []) if e['name'] not in ['PLEX_UID', 'PLEX_GID'] ],
  32. },
  33. # Migrate Network
  34. 'minioNetwork': {
  35. 'apiPort': values['service']['nodePort'],
  36. 'consolePort': values['service']['consolePort'],
  37. 'certificateID': values['certificate'],
  38. },
  39. # Migrate Resources
  40. 'resources': {
  41. 'limits': {
  42. 'cpu': values.get('cpuLimit', '4000m'),
  43. 'memory': values.get('memLimit', '8Gi'),
  44. }
  45. },
  46. # Migrate DNS
  47. 'podOptions': {
  48. 'dnsConfig': {
  49. 'options': [
  50. {'name': opt['name'], 'value': opt['value']}
  51. for opt in values.get('dnsConfig', {}).get('options', [])
  52. ]
  53. }
  54. },
  55. # Migrate Storage
  56. 'minioStorage': {
  57. 'distributedMode': values['distributedMode']
  58. 'distributedIps': values['distributedIps'] if values['distributedMode'] else [],
  59. 'logSearchApi': values['logsearchapi']['enabled'],
  60. 'logSearchDiskCapacityGB': values['logsearchapi']['diskCapacityGB'] if values['logsearchapi']['enabled'] else 5,
  61. 'export': migrate_volume(values['appVolumeMounts']['export']).update({
  62. mountPath: values['appVolumeMounts']['export'][mountPath]
  63. }),
  64. 'pgData': migrate_volume(values['postgresAppVolumeMounts']['postgres-data']),
  65. 'pgBackup': migrate_volume(values['postgresAppVolumeMounts']['postgres-backup']),
  66. 'additionalStorages': [
  67. {
  68. 'type': 'hostPath',
  69. 'hostPathConfig': {'hostPath': e['hostPath']},
  70. 'mountPath': e['mountPath'],
  71. 'readOnly': e['readOnly'],
  72. }
  73. for e in values.get('extraAppVolumeMounts', [])
  74. ],
  75. },
  76. })
  77. for k in delete_keys:
  78. values.pop(k, None)
  79. return values
  80. def migrate(values):
  81. # If this missing, we have already migrated
  82. if not 'nodePort' in values.keys():
  83. return values
  84. return migrate_common_lib(values)
  85. if __name__ == '__main__':
  86. if len(sys.argv) != 2:
  87. exit(1)
  88. if os.path.exists(sys.argv[1]):
  89. with open(sys.argv[1], 'r') as f:
  90. print(json.dumps(migrate(json.loads(f.read()))))