_capabilities.tpl 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Return the target Kubernetes version
  4. */}}
  5. {{- define "common.capabilities.kubeVersion" -}}
  6. {{- if .Values.global }}
  7. {{- if .Values.global.kubeVersion }}
  8. {{- .Values.global.kubeVersion -}}
  9. {{- else }}
  10. {{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}}
  11. {{- end -}}
  12. {{- else }}
  13. {{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}}
  14. {{- end -}}
  15. {{- end -}}
  16. {{/*
  17. Return the appropriate apiVersion for deployment.
  18. */}}
  19. {{- define "common.capabilities.deployment.apiVersion" -}}
  20. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  21. {{- print "extensions/v1beta1" -}}
  22. {{- else -}}
  23. {{- print "apps/v1" -}}
  24. {{- end -}}
  25. {{- end -}}
  26. {{/*
  27. Return the appropriate apiVersion for statefulset.
  28. */}}
  29. {{- define "common.capabilities.statefulset.apiVersion" -}}
  30. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  31. {{- print "apps/v1beta1" -}}
  32. {{- else -}}
  33. {{- print "apps/v1" -}}
  34. {{- end -}}
  35. {{- end -}}
  36. {{/*
  37. Return the appropriate apiVersion for ingress.
  38. */}}
  39. {{- define "common.capabilities.ingress.apiVersion" -}}
  40. {{- if .Values.ingress -}}
  41. {{- if .Values.ingress.apiVersion -}}
  42. {{- .Values.ingress.apiVersion -}}
  43. {{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  44. {{- print "extensions/v1beta1" -}}
  45. {{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  46. {{- print "networking.k8s.io/v1beta1" -}}
  47. {{- else -}}
  48. {{- print "networking.k8s.io/v1" -}}
  49. {{- end }}
  50. {{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  51. {{- print "extensions/v1beta1" -}}
  52. {{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  53. {{- print "networking.k8s.io/v1beta1" -}}
  54. {{- else -}}
  55. {{- print "networking.k8s.io/v1" -}}
  56. {{- end -}}
  57. {{- end -}}
  58. {{/*
  59. Return the appropriate apiVersion for RBAC resources.
  60. */}}
  61. {{- define "common.capabilities.rbac.apiVersion" -}}
  62. {{- if semverCompare "<1.17-0" (include "common.capabilities.kubeVersion" .) -}}
  63. {{- print "rbac.authorization.k8s.io/v1beta1" -}}
  64. {{- else -}}
  65. {{- print "rbac.authorization.k8s.io/v1" -}}
  66. {{- end -}}
  67. {{- end -}}
  68. {{/*
  69. Return the appropriate apiVersion for CRDs.
  70. */}}
  71. {{- define "common.capabilities.crd.apiVersion" -}}
  72. {{- if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  73. {{- print "apiextensions.k8s.io/v1beta1" -}}
  74. {{- else -}}
  75. {{- print "apiextensions.k8s.io/v1" -}}
  76. {{- end -}}
  77. {{- end -}}
  78. {{/*
  79. Returns true if the used Helm version is 3.3+.
  80. A way to check the used Helm version was not introduced until version 3.3.0 with .Capabilities.HelmVersion, which contains an additional "{}}" structure.
  81. This check is introduced as a regexMatch instead of {{ if .Capabilities.HelmVersion }} because checking for the key HelmVersion in <3.3 results in a "interface not found" error.
  82. **To be removed when the catalog's minimun Helm version is 3.3**
  83. */}}
  84. {{- define "common.capabilities.supportsHelmVersion" -}}
  85. {{- if regexMatch "{(v[0-9])*[^}]*}}$" (.Capabilities | toString ) }}
  86. {{- true -}}
  87. {{- end -}}
  88. {{- end -}}