migrate 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. 'hostNetwork', 'environmentVariables', 'updateStrategy', 'embyServerHttp', 'gpuConfiguration',
  20. 'appVolumeMounts', 'extraAppVolumeMounts', 'enableResourceLimits', 'cpuLimit', 'memLimit'
  21. ]
  22. values.update({
  23. # Migrate Network
  24. 'embyNetwork': {
  25. 'webPort': values['embyServerHttp'],
  26. 'hostNetwork': values['hostNetwork'],
  27. },
  28. # Migrate Resources
  29. 'resources': {
  30. 'limits': {
  31. 'cpu': values.get('cpuLimit', '4000m'),
  32. 'memory': values.get('memLimit', '8Gi'),
  33. }
  34. },
  35. 'embyID': {
  36. # We didn't have exposed this on UI the default
  37. # set by the container is 2, so we will use that
  38. 'user': 2,
  39. 'group': 2,
  40. },
  41. # Migrate Config
  42. 'embyConfig': {
  43. 'additionalEnvs': values.get('environmentVariables', []),
  44. },
  45. # Migrate Storage
  46. 'embyStorage': {
  47. 'config': migrate_volume(values['appVolumeMounts']['config']),
  48. 'additionalStorages': [
  49. {
  50. 'type': 'hostPath',
  51. 'hostPathConfig': {'hostPath': e['hostPath']},
  52. 'mountPath': e['mountPath'],
  53. 'readOnly': e['readOnly'],
  54. }
  55. for e in values.get('extraAppVolumeMounts', [])
  56. ],
  57. },
  58. })
  59. for k in delete_keys:
  60. values.pop(k, None)
  61. return values
  62. def migrate(values):
  63. # If this missing, we have already migrated
  64. if not 'appVolumeMounts' in values.keys():
  65. return values
  66. return migrate_common_lib(values)
  67. if __name__ == '__main__':
  68. if len(sys.argv) != 2:
  69. exit(1)
  70. if os.path.exists(sys.argv[1]):
  71. with open(sys.argv[1], 'r') as f:
  72. print(json.dumps(migrate(json.loads(f.read()))))