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', 'runAsUser', 'runAsGroup',
  23. ]
  24. exportVol = migrate_volume(values['appVolumeMounts']['export'])
  25. exportVol['mountPath'] = values['appVolumeMounts']['export']['mountPath']
  26. values.update({
  27. # Migrate Config
  28. 'minioConfig': {
  29. 'rootUser': values['accessKey'],
  30. 'rootPassword': values['secretKey'],
  31. 'domain': values.get('minioDomain', ''),
  32. 'extraArgs': values.get('extraArgs', []),
  33. 'additionalEnvs': values.get('environmentVariables', []),
  34. },
  35. # Migrate Network
  36. 'minioNetwork': {
  37. 'apiPort': values['service']['nodePort'],
  38. 'consolePort': values['service']['consolePort'],
  39. 'certificateID': values['certificate'],
  40. },
  41. # Migrate Resources
  42. 'resources': {
  43. 'limits': {
  44. 'cpu': values.get('cpuLimit', '4000m'),
  45. 'memory': values.get('memLimit', '8Gi'),
  46. }
  47. },
  48. # Migrate DNS
  49. 'podOptions': {
  50. 'dnsConfig': {
  51. 'options': [
  52. {'name': opt['name'], 'value': opt['value']}
  53. for opt in values.get('dnsConfig', {}).get('options', [])
  54. ]
  55. }
  56. },
  57. # Migrate Storage
  58. 'minioStorage': {
  59. 'distributedMode': values['distributedMode'],
  60. 'distributedIps': values['distributedIps'] if values['distributedMode'] else [],
  61. 'logSearchApi': values['logsearchapi']['enabled'],
  62. 'logSearchDiskCapacityGB': values['logsearchapi']['diskCapacityGB'] if values['logsearchapi']['enabled'] else 5,
  63. 'export': exportVol,
  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.get('readOnly', False),
  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 'appVolumeMounts' 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()))))