_migration.tpl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. {{- define "home-assistant.get-versions" -}}
  2. {{- $oldChartVersion := "" -}}
  3. {{- $newChartVersion := "" -}}
  4. {{/* Safely access the context, so it wont block CI */}}
  5. {{- if hasKey .Values.global "ixChartContext" -}}
  6. {{- if .Values.global.ixChartContext.upgradeMetadata -}}
  7. {{- $oldChartVersion = .Values.global.ixChartContext.upgradeMetadata.oldChartVersion -}}
  8. {{- $newChartVersion = .Values.global.ixChartContext.upgradeMetadata.newChartVersion -}}
  9. {{- if and (not $oldChartVersion) (not $newChartVersion) -}}
  10. {{- fail "Upgrade Metadata is missing. Cannot proceed" -}}
  11. {{- end -}}
  12. {{- end -}}
  13. {{- end -}}
  14. {{- toYaml (dict "old" $oldChartVersion "new" $newChartVersion) -}}
  15. {{- end -}}
  16. {{- define "home-assistant.migration" -}}
  17. {{- $versions := (fromYaml (include "home-assistant.get-versions" $)) -}}
  18. {{- if and $versions.old $versions.new -}}
  19. {{- $oldV := semver $versions.old -}}
  20. {{- $newV := semver $versions.new -}}
  21. {{/* If new is v2.x.x */}}
  22. {{- if eq ($newV.Major | int) 2 -}}
  23. {{/* And old is v1.x.x, but lower than .130 */}}
  24. {{- if and (eq $oldV.Major 1) (lt ($oldV.Patch | int) 130) -}}
  25. {{/* Block the upgrade */}}
  26. {{- fail "Migration to 2.x.x is only allowed from 1.0.130 or higher" -}}
  27. {{- end -}}
  28. {{- end -}}
  29. {{- end -}}
  30. {{- end -}}
  31. {{- define "home-assistant.is-migration" -}}
  32. {{- $isMigration := "" -}}
  33. {{- $versions := (fromYaml (include "home-assistant.get-versions" $)) -}}
  34. {{- if $versions.old -}}
  35. {{- $oldV := semver $versions.old -}}
  36. {{- if and (eq $oldV.Major 1) (eq ($oldV.Patch | int) 130) -}}
  37. {{- $isMigration = "true" -}}
  38. {{- end -}}
  39. {{- end -}}
  40. {{- $isMigration -}}
  41. {{- end -}}