_capabilities.tpl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 poddisruptionbudget.
  18. */}}
  19. {{- define "common.capabilities.policy.apiVersion" -}}
  20. {{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
  21. {{- print "policy/v1beta1" -}}
  22. {{- else -}}
  23. {{- print "policy/v1" -}}
  24. {{- end -}}
  25. {{- end -}}
  26. {{/*
  27. Return the appropriate apiVersion for networkpolicy.
  28. */}}
  29. {{- define "common.capabilities.networkPolicy.apiVersion" -}}
  30. {{- if semverCompare "<1.7-0" (include "common.capabilities.kubeVersion" .) -}}
  31. {{- print "extensions/v1beta1" -}}
  32. {{- else -}}
  33. {{- print "networking.k8s.io/v1" -}}
  34. {{- end -}}
  35. {{- end -}}
  36. {{/*
  37. Return the appropriate apiVersion for cronjob.
  38. */}}
  39. {{- define "common.capabilities.cronjob.apiVersion" -}}
  40. {{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
  41. {{- print "batch/v1beta1" -}}
  42. {{- else -}}
  43. {{- print "batch/v1" -}}
  44. {{- end -}}
  45. {{- end -}}
  46. {{/*
  47. Return the appropriate apiVersion for deployment.
  48. */}}
  49. {{- define "common.capabilities.deployment.apiVersion" -}}
  50. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  51. {{- print "extensions/v1beta1" -}}
  52. {{- else -}}
  53. {{- print "apps/v1" -}}
  54. {{- end -}}
  55. {{- end -}}
  56. {{/*
  57. Return the appropriate apiVersion for statefulset.
  58. */}}
  59. {{- define "common.capabilities.statefulset.apiVersion" -}}
  60. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  61. {{- print "apps/v1beta1" -}}
  62. {{- else -}}
  63. {{- print "apps/v1" -}}
  64. {{- end -}}
  65. {{- end -}}
  66. {{/*
  67. Return the appropriate apiVersion for ingress.
  68. */}}
  69. {{- define "common.capabilities.ingress.apiVersion" -}}
  70. {{- if .Values.ingress -}}
  71. {{- if .Values.ingress.apiVersion -}}
  72. {{- .Values.ingress.apiVersion -}}
  73. {{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  74. {{- print "extensions/v1beta1" -}}
  75. {{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  76. {{- print "networking.k8s.io/v1beta1" -}}
  77. {{- else -}}
  78. {{- print "networking.k8s.io/v1" -}}
  79. {{- end }}
  80. {{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  81. {{- print "extensions/v1beta1" -}}
  82. {{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  83. {{- print "networking.k8s.io/v1beta1" -}}
  84. {{- else -}}
  85. {{- print "networking.k8s.io/v1" -}}
  86. {{- end -}}
  87. {{- end -}}
  88. {{/*
  89. Return the appropriate apiVersion for RBAC resources.
  90. */}}
  91. {{- define "common.capabilities.rbac.apiVersion" -}}
  92. {{- if semverCompare "<1.17-0" (include "common.capabilities.kubeVersion" .) -}}
  93. {{- print "rbac.authorization.k8s.io/v1beta1" -}}
  94. {{- else -}}
  95. {{- print "rbac.authorization.k8s.io/v1" -}}
  96. {{- end -}}
  97. {{- end -}}
  98. {{/*
  99. Return the appropriate apiVersion for CRDs.
  100. */}}
  101. {{- define "common.capabilities.crd.apiVersion" -}}
  102. {{- if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  103. {{- print "apiextensions.k8s.io/v1beta1" -}}
  104. {{- else -}}
  105. {{- print "apiextensions.k8s.io/v1" -}}
  106. {{- end -}}
  107. {{- end -}}
  108. {{/*
  109. Return the appropriate apiVersion for APIService.
  110. */}}
  111. {{- define "common.capabilities.apiService.apiVersion" -}}
  112. {{- if semverCompare "<1.10-0" (include "common.capabilities.kubeVersion" .) -}}
  113. {{- print "apiregistration.k8s.io/v1beta1" -}}
  114. {{- else -}}
  115. {{- print "apiregistration.k8s.io/v1" -}}
  116. {{- end -}}
  117. {{- end -}}
  118. {{/*
  119. Return the appropriate apiVersion for Horizontal Pod Autoscaler.
  120. */}}
  121. {{- define "common.capabilities.hpa.apiVersion" -}}
  122. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .context) -}}
  123. {{- if .beta2 -}}
  124. {{- print "autoscaling/v2beta2" -}}
  125. {{- else -}}
  126. {{- print "autoscaling/v2beta1" -}}
  127. {{- end -}}
  128. {{- else -}}
  129. {{- print "autoscaling/v2" -}}
  130. {{- end -}}
  131. {{- end -}}
  132. {{/*
  133. Returns true if the used Helm version is 3.3+.
  134. A way to check the used Helm version was not introduced until version 3.3.0 with .Capabilities.HelmVersion, which contains an additional "{}}" structure.
  135. 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.
  136. **To be removed when the catalog's minimun Helm version is 3.3**
  137. */}}
  138. {{- define "common.capabilities.supportsHelmVersion" -}}
  139. {{- if regexMatch "{(v[0-9])*[^}]*}}$" (.Capabilities | toString ) }}
  140. {{- true -}}
  141. {{- end -}}
  142. {{- end -}}