migrate 3.5 KB

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