migrate 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 'enableResourceLimits', 'cpuLimit', 'memLimit', 'dnsConfig',
  20. 'environmentVariables', 'runAsUser', 'runAsGroup', 'webPort',
  21. 'nodePort', 'wallet', 'authToken', 'email', 'domainAddress',
  22. 'terminationGracePeriod', 'storageSize', 'zksync', 'zksyncEra',
  23. 'extraAppVolumeMounts', 'appVolumeMounts', 'identityCreationMountPath',
  24. ]
  25. values.update({
  26. # Migrate Network
  27. 'storjNetwork': {
  28. 'webPort': values['webPort'],
  29. 'p2pPort': values['nodePort'],
  30. },
  31. # Migrate Resources
  32. 'resources': {
  33. 'limits': {
  34. 'cpu': values.get('cpuLimit', '4000m'),
  35. 'memory': values.get('memLimit', '8Gi'),
  36. }
  37. },
  38. # Migrate DNS
  39. 'podOptions': {
  40. 'dnsConfig': {
  41. 'options': [
  42. {'name': opt['name'], 'value': opt['value']}
  43. for opt in values.get('dnsConfig', {}).get('options', [])
  44. ]
  45. }
  46. },
  47. # Migrate ID
  48. 'storjRunAs': {
  49. 'user': values['runAsUser'],
  50. 'group': values['runAsGroup'],
  51. },
  52. # Migrate Config
  53. 'storjConfig': {
  54. 'wallet': values['wallet'],
  55. 'authToken': values['authToken'],
  56. 'email': values['email'],
  57. 'domainAddress': values['domainAddress'],
  58. 'storageSizeGB': values['storageSize'],
  59. 'gracePeriod': values['terminationGracePeriod'],
  60. 'wallets': {
  61. 'zkSync': values['zksync'],
  62. 'zkSyncEra': values['zksyncEra'],
  63. },
  64. 'additionalEnvs': [e for e in values.get('environmentVariables', [])],
  65. },
  66. # Migrate Storage
  67. 'storjStorage': {
  68. 'data': migrate_volume(values['appVolumeMounts']['data']),
  69. 'identity': migrate_volume(values['appVolumeMounts']['identity']),
  70. 'additionalStorages': [
  71. {
  72. 'type': 'hostPath',
  73. 'hostPathConfig': {'hostPath': e['hostPath']},
  74. 'mountPath': e['mountPath'],
  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 'appVolumeMounts' 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()))))