migrate 3.5 KB

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