_capabilities.tpl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. {{/*
  2. Copyright Broadcom, Inc. All Rights Reserved.
  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. {{- default (default .Capabilities.KubeVersion.Version .Values.kubeVersion) ((.Values.global).kubeVersion) -}}
  11. {{- end -}}
  12. {{/*
  13. Return the appropriate apiVersion for poddisruptionbudget.
  14. */}}
  15. {{- define "common.capabilities.policy.apiVersion" -}}
  16. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  17. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.21-0" $kubeVersion) -}}
  18. {{- print "policy/v1beta1" -}}
  19. {{- else -}}
  20. {{- print "policy/v1" -}}
  21. {{- end -}}
  22. {{- end -}}
  23. {{/*
  24. Return the appropriate apiVersion for networkpolicy.
  25. */}}
  26. {{- define "common.capabilities.networkPolicy.apiVersion" -}}
  27. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  28. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.7-0" $kubeVersion) -}}
  29. {{- print "extensions/v1beta1" -}}
  30. {{- else -}}
  31. {{- print "networking.k8s.io/v1" -}}
  32. {{- end -}}
  33. {{- end -}}
  34. {{/*
  35. Return the appropriate apiVersion for cronjob.
  36. */}}
  37. {{- define "common.capabilities.cronjob.apiVersion" -}}
  38. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  39. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.21-0" $kubeVersion) -}}
  40. {{- print "batch/v1beta1" -}}
  41. {{- else -}}
  42. {{- print "batch/v1" -}}
  43. {{- end -}}
  44. {{- end -}}
  45. {{/*
  46. Return the appropriate apiVersion for daemonset.
  47. */}}
  48. {{- define "common.capabilities.daemonset.apiVersion" -}}
  49. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  50. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.14-0" $kubeVersion) -}}
  51. {{- print "extensions/v1beta1" -}}
  52. {{- else -}}
  53. {{- print "apps/v1" -}}
  54. {{- end -}}
  55. {{- end -}}
  56. {{/*
  57. Return the appropriate apiVersion for deployment.
  58. */}}
  59. {{- define "common.capabilities.deployment.apiVersion" -}}
  60. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  61. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.14-0" $kubeVersion) -}}
  62. {{- print "extensions/v1beta1" -}}
  63. {{- else -}}
  64. {{- print "apps/v1" -}}
  65. {{- end -}}
  66. {{- end -}}
  67. {{/*
  68. Return the appropriate apiVersion for statefulset.
  69. */}}
  70. {{- define "common.capabilities.statefulset.apiVersion" -}}
  71. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  72. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.14-0" $kubeVersion) -}}
  73. {{- print "apps/v1beta1" -}}
  74. {{- else -}}
  75. {{- print "apps/v1" -}}
  76. {{- end -}}
  77. {{- end -}}
  78. {{/*
  79. Return the appropriate apiVersion for ingress.
  80. */}}
  81. {{- define "common.capabilities.ingress.apiVersion" -}}
  82. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  83. {{- if (.Values.ingress).apiVersion -}}
  84. {{- .Values.ingress.apiVersion -}}
  85. {{- else if and (not (empty $kubeVersion)) (semverCompare "<1.14-0" $kubeVersion) -}}
  86. {{- print "extensions/v1beta1" -}}
  87. {{- else if and (not (empty $kubeVersion)) (semverCompare "<1.19-0" $kubeVersion) -}}
  88. {{- print "networking.k8s.io/v1beta1" -}}
  89. {{- else -}}
  90. {{- print "networking.k8s.io/v1" -}}
  91. {{- end }}
  92. {{- end -}}
  93. {{/*
  94. Return the appropriate apiVersion for RBAC resources.
  95. */}}
  96. {{- define "common.capabilities.rbac.apiVersion" -}}
  97. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  98. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.17-0" $kubeVersion) -}}
  99. {{- print "rbac.authorization.k8s.io/v1beta1" -}}
  100. {{- else -}}
  101. {{- print "rbac.authorization.k8s.io/v1" -}}
  102. {{- end -}}
  103. {{- end -}}
  104. {{/*
  105. Return the appropriate apiVersion for CRDs.
  106. */}}
  107. {{- define "common.capabilities.crd.apiVersion" -}}
  108. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  109. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.19-0" $kubeVersion) -}}
  110. {{- print "apiextensions.k8s.io/v1beta1" -}}
  111. {{- else -}}
  112. {{- print "apiextensions.k8s.io/v1" -}}
  113. {{- end -}}
  114. {{- end -}}
  115. {{/*
  116. Return the appropriate apiVersion for APIService.
  117. */}}
  118. {{- define "common.capabilities.apiService.apiVersion" -}}
  119. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  120. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.10-0" $kubeVersion) -}}
  121. {{- print "apiregistration.k8s.io/v1beta1" -}}
  122. {{- else -}}
  123. {{- print "apiregistration.k8s.io/v1" -}}
  124. {{- end -}}
  125. {{- end -}}
  126. {{/*
  127. Return the appropriate apiVersion for Horizontal Pod Autoscaler.
  128. */}}
  129. {{- define "common.capabilities.hpa.apiVersion" -}}
  130. {{- $kubeVersion := include "common.capabilities.kubeVersion" .context -}}
  131. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.23-0" $kubeVersion) -}}
  132. {{- if .beta2 -}}
  133. {{- print "autoscaling/v2beta2" -}}
  134. {{- else -}}
  135. {{- print "autoscaling/v2beta1" -}}
  136. {{- end -}}
  137. {{- else -}}
  138. {{- print "autoscaling/v2" -}}
  139. {{- end -}}
  140. {{- end -}}
  141. {{/*
  142. Return the appropriate apiVersion for Vertical Pod Autoscaler.
  143. */}}
  144. {{- define "common.capabilities.vpa.apiVersion" -}}
  145. {{- $kubeVersion := include "common.capabilities.kubeVersion" .context -}}
  146. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.23-0" $kubeVersion) -}}
  147. {{- if .beta2 -}}
  148. {{- print "autoscaling/v2beta2" -}}
  149. {{- else -}}
  150. {{- print "autoscaling/v2beta1" -}}
  151. {{- end -}}
  152. {{- else -}}
  153. {{- print "autoscaling/v2" -}}
  154. {{- end -}}
  155. {{- end -}}
  156. {{/*
  157. Returns true if PodSecurityPolicy is supported
  158. */}}
  159. {{- define "common.capabilities.psp.supported" -}}
  160. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  161. {{- if or (empty $kubeVersion) (semverCompare "<1.25-0" $kubeVersion) -}}
  162. {{- true -}}
  163. {{- end -}}
  164. {{- end -}}
  165. {{/*
  166. Returns true if AdmissionConfiguration is supported
  167. */}}
  168. {{- define "common.capabilities.admissionConfiguration.supported" -}}
  169. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  170. {{- if or (empty $kubeVersion) (not (semverCompare "<1.23-0" $kubeVersion)) -}}
  171. {{- true -}}
  172. {{- end -}}
  173. {{- end -}}
  174. {{/*
  175. Return the appropriate apiVersion for AdmissionConfiguration.
  176. */}}
  177. {{- define "common.capabilities.admissionConfiguration.apiVersion" -}}
  178. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  179. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.23-0" $kubeVersion) -}}
  180. {{- print "apiserver.config.k8s.io/v1alpha1" -}}
  181. {{- else if and (not (empty $kubeVersion)) (semverCompare "<1.25-0" $kubeVersion) -}}
  182. {{- print "apiserver.config.k8s.io/v1beta1" -}}
  183. {{- else -}}
  184. {{- print "apiserver.config.k8s.io/v1" -}}
  185. {{- end -}}
  186. {{- end -}}
  187. {{/*
  188. Return the appropriate apiVersion for PodSecurityConfiguration.
  189. */}}
  190. {{- define "common.capabilities.podSecurityConfiguration.apiVersion" -}}
  191. {{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
  192. {{- if and (not (empty $kubeVersion)) (semverCompare "<1.23-0" $kubeVersion) -}}
  193. {{- print "pod-security.admission.config.k8s.io/v1alpha1" -}}
  194. {{- else if and (not (empty $kubeVersion)) (semverCompare "<1.25-0" $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 -}}