_capabilities.tpl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. {{/*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Return the target Kubernetes version
  8. */}}
  9. {{- define "common.capabilities.kubeVersion" -}}
  10. {{- if .Values.global }}
  11. {{- if .Values.global.kubeVersion }}
  12. {{- .Values.global.kubeVersion -}}
  13. {{- else }}
  14. {{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}}
  15. {{- end -}}
  16. {{- else }}
  17. {{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}}
  18. {{- end -}}
  19. {{- end -}}
  20. {{/*
  21. Return the appropriate apiVersion for poddisruptionbudget.
  22. */}}
  23. {{- define "common.capabilities.policy.apiVersion" -}}
  24. {{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
  25. {{- print "policy/v1beta1" -}}
  26. {{- else -}}
  27. {{- print "policy/v1" -}}
  28. {{- end -}}
  29. {{- end -}}
  30. {{/*
  31. Return the appropriate apiVersion for networkpolicy.
  32. */}}
  33. {{- define "common.capabilities.networkPolicy.apiVersion" -}}
  34. {{- if semverCompare "<1.7-0" (include "common.capabilities.kubeVersion" .) -}}
  35. {{- print "extensions/v1beta1" -}}
  36. {{- else -}}
  37. {{- print "networking.k8s.io/v1" -}}
  38. {{- end -}}
  39. {{- end -}}
  40. {{/*
  41. Return the appropriate apiVersion for cronjob.
  42. */}}
  43. {{- define "common.capabilities.cronjob.apiVersion" -}}
  44. {{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
  45. {{- print "batch/v1beta1" -}}
  46. {{- else -}}
  47. {{- print "batch/v1" -}}
  48. {{- end -}}
  49. {{- end -}}
  50. {{/*
  51. Return the appropriate apiVersion for daemonset.
  52. */}}
  53. {{- define "common.capabilities.daemonset.apiVersion" -}}
  54. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  55. {{- print "extensions/v1beta1" -}}
  56. {{- else -}}
  57. {{- print "apps/v1" -}}
  58. {{- end -}}
  59. {{- end -}}
  60. {{/*
  61. Return the appropriate apiVersion for deployment.
  62. */}}
  63. {{- define "common.capabilities.deployment.apiVersion" -}}
  64. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  65. {{- print "extensions/v1beta1" -}}
  66. {{- else -}}
  67. {{- print "apps/v1" -}}
  68. {{- end -}}
  69. {{- end -}}
  70. {{/*
  71. Return the appropriate apiVersion for statefulset.
  72. */}}
  73. {{- define "common.capabilities.statefulset.apiVersion" -}}
  74. {{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  75. {{- print "apps/v1beta1" -}}
  76. {{- else -}}
  77. {{- print "apps/v1" -}}
  78. {{- end -}}
  79. {{- end -}}
  80. {{/*
  81. Return the appropriate apiVersion for ingress.
  82. */}}
  83. {{- define "common.capabilities.ingress.apiVersion" -}}
  84. {{- if .Values.ingress -}}
  85. {{- if .Values.ingress.apiVersion -}}
  86. {{- .Values.ingress.apiVersion -}}
  87. {{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  88. {{- print "extensions/v1beta1" -}}
  89. {{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  90. {{- print "networking.k8s.io/v1beta1" -}}
  91. {{- else -}}
  92. {{- print "networking.k8s.io/v1" -}}
  93. {{- end }}
  94. {{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
  95. {{- print "extensions/v1beta1" -}}
  96. {{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  97. {{- print "networking.k8s.io/v1beta1" -}}
  98. {{- else -}}
  99. {{- print "networking.k8s.io/v1" -}}
  100. {{- end -}}
  101. {{- end -}}
  102. {{/*
  103. Return the appropriate apiVersion for RBAC resources.
  104. */}}
  105. {{- define "common.capabilities.rbac.apiVersion" -}}
  106. {{- if semverCompare "<1.17-0" (include "common.capabilities.kubeVersion" .) -}}
  107. {{- print "rbac.authorization.k8s.io/v1beta1" -}}
  108. {{- else -}}
  109. {{- print "rbac.authorization.k8s.io/v1" -}}
  110. {{- end -}}
  111. {{- end -}}
  112. {{/*
  113. Return the appropriate apiVersion for CRDs.
  114. */}}
  115. {{- define "common.capabilities.crd.apiVersion" -}}
  116. {{- if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
  117. {{- print "apiextensions.k8s.io/v1beta1" -}}
  118. {{- else -}}
  119. {{- print "apiextensions.k8s.io/v1" -}}
  120. {{- end -}}
  121. {{- end -}}
  122. {{/*
  123. Return the appropriate apiVersion for APIService.
  124. */}}
  125. {{- define "common.capabilities.apiService.apiVersion" -}}
  126. {{- if semverCompare "<1.10-0" (include "common.capabilities.kubeVersion" .) -}}
  127. {{- print "apiregistration.k8s.io/v1beta1" -}}
  128. {{- else -}}
  129. {{- print "apiregistration.k8s.io/v1" -}}
  130. {{- end -}}
  131. {{- end -}}
  132. {{/*
  133. Return the appropriate apiVersion for Horizontal Pod Autoscaler.
  134. */}}
  135. {{- define "common.capabilities.hpa.apiVersion" -}}
  136. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .context) -}}
  137. {{- if .beta2 -}}
  138. {{- print "autoscaling/v2beta2" -}}
  139. {{- else -}}
  140. {{- print "autoscaling/v2beta1" -}}
  141. {{- end -}}
  142. {{- else -}}
  143. {{- print "autoscaling/v2" -}}
  144. {{- end -}}
  145. {{- end -}}
  146. {{/*
  147. Return the appropriate apiVersion for Vertical Pod Autoscaler.
  148. */}}
  149. {{- define "common.capabilities.vpa.apiVersion" -}}
  150. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .context) -}}
  151. {{- if .beta2 -}}
  152. {{- print "autoscaling/v2beta2" -}}
  153. {{- else -}}
  154. {{- print "autoscaling/v2beta1" -}}
  155. {{- end -}}
  156. {{- else -}}
  157. {{- print "autoscaling/v2" -}}
  158. {{- end -}}
  159. {{- end -}}
  160. {{/*
  161. Returns true if PodSecurityPolicy is supported
  162. */}}
  163. {{- define "common.capabilities.psp.supported" -}}
  164. {{- if semverCompare "<1.25-0" (include "common.capabilities.kubeVersion" .) -}}
  165. {{- true -}}
  166. {{- end -}}
  167. {{- end -}}
  168. {{/*
  169. Returns true if AdmissionConfiguration is supported
  170. */}}
  171. {{- define "common.capabilities.admissionConfiguration.supported" -}}
  172. {{- if semverCompare ">=1.23-0" (include "common.capabilities.kubeVersion" .) -}}
  173. {{- true -}}
  174. {{- end -}}
  175. {{- end -}}
  176. {{/*
  177. Return the appropriate apiVersion for AdmissionConfiguration.
  178. */}}
  179. {{- define "common.capabilities.admissionConfiguration.apiVersion" -}}
  180. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .) -}}
  181. {{- print "apiserver.config.k8s.io/v1alpha1" -}}
  182. {{- else if semverCompare "<1.25-0" (include "common.capabilities.kubeVersion" .) -}}
  183. {{- print "apiserver.config.k8s.io/v1beta1" -}}
  184. {{- else -}}
  185. {{- print "apiserver.config.k8s.io/v1" -}}
  186. {{- end -}}
  187. {{- end -}}
  188. {{/*
  189. Return the appropriate apiVersion for PodSecurityConfiguration.
  190. */}}
  191. {{- define "common.capabilities.podSecurityConfiguration.apiVersion" -}}
  192. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .) -}}
  193. {{- print "pod-security.admission.config.k8s.io/v1alpha1" -}}
  194. {{- else if semverCompare "<1.25-0" (include "common.capabilities.kubeVersion" .) -}}
  195. {{- print "pod-security.admission.config.k8s.io/v1beta1" -}}
  196. {{- else -}}
  197. {{- print "pod-security.admission.config.k8s.io/v1" -}}
  198. {{- end -}}
  199. {{- end -}}
  200. {{/*
  201. Returns true if the used Helm version is 3.3+.
  202. A way to check the used Helm version was not introduced until version 3.3.0 with .Capabilities.HelmVersion, which contains an additional "{}}" structure.
  203. 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.
  204. **To be removed when the catalog's minimun Helm version is 3.3**
  205. */}}
  206. {{- define "common.capabilities.supportsHelmVersion" -}}
  207. {{- if regexMatch "{(v[0-9])*[^}]*}}$" (.Capabilities | toString ) }}
  208. {{- true -}}
  209. {{- end -}}
  210. {{- end -}}