migrate 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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']['port'] if values['hostNetwork'] else 9096,
  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. 'embyGPU': values.get('gpuConfiguration', {}),
  59. })
  60. for k in delete_keys:
  61. values.pop(k, None)
  62. return values
  63. def migrate(values):
  64. # If this missing, we have already migrated
  65. if not 'appVolumeMounts' in values.keys():
  66. return values
  67. return migrate_common_lib(values)
  68. if __name__ == '__main__':
  69. if len(sys.argv) != 2:
  70. exit(1)
  71. if os.path.exists(sys.argv[1]):
  72. with open(sys.argv[1], 'r') as f:
  73. print(json.dumps(migrate(json.loads(f.read()))))