|
| 1 | +{{/* |
| 2 | + ====== Return the target Kubernetes version ====== |
| 3 | +*/}} |
| 4 | +{{- define "common.capabilities.kubeVersion" -}} |
| 5 | +{{- if .Values.global }} |
| 6 | + {{- if .Values.global.kubeVersion }} |
| 7 | + {{- .Values.global.kubeVersion -}} |
| 8 | + {{- else }} |
| 9 | + {{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}} |
| 10 | + {{- end -}} |
| 11 | +{{- else }} |
| 12 | +{{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}} |
| 13 | +{{- end -}} |
| 14 | +{{- end -}} |
| 15 | + |
| 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 | +{{/* |
| 28 | + ====== Return the appropriate apiVersion for networkpolicy. ====== |
| 29 | +*/}} |
| 30 | +{{- define "common.capabilities.networkPolicy.apiVersion" -}} |
| 31 | +{{- if semverCompare "<1.7-0" (include "common.capabilities.kubeVersion" .) -}} |
| 32 | +{{- print "extensions/v1beta1" -}} |
| 33 | +{{- else -}} |
| 34 | +{{- print "networking.k8s.io/v1" -}} |
| 35 | +{{- end -}} |
| 36 | +{{- end -}} |
| 37 | + |
| 38 | +{{/* |
| 39 | + ====== Return the appropriate apiVersion for cronjob. ====== |
| 40 | +*/}} |
| 41 | +{{- define "common.capabilities.cronjob.apiVersion" -}} |
| 42 | +{{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}} |
| 43 | +{{- print "batch/v1beta1" -}} |
| 44 | +{{- else -}} |
| 45 | +{{- print "batch/v1" -}} |
| 46 | +{{- end -}} |
| 47 | +{{- end -}} |
| 48 | + |
| 49 | +{{/* |
| 50 | + ====== Return the appropriate apiVersion for deployment. ====== |
| 51 | +*/}} |
| 52 | +{{- define "common.capabilities.deployment.apiVersion" -}} |
| 53 | +{{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}} |
| 54 | +{{- print "extensions/v1beta1" -}} |
| 55 | +{{- else -}} |
| 56 | +{{- print "apps/v1" -}} |
| 57 | +{{- end -}} |
| 58 | +{{- end -}} |
| 59 | + |
| 60 | +{{/* |
| 61 | + ====== Return the appropriate apiVersion for statefulset.====== |
| 62 | +*/}} |
| 63 | +{{- define "common.capabilities.statefulset.apiVersion" -}} |
| 64 | +{{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}} |
| 65 | +{{- print "apps/v1beta1" -}} |
| 66 | +{{- else -}} |
| 67 | +{{- print "apps/v1" -}} |
| 68 | +{{- end -}} |
| 69 | +{{- end -}} |
| 70 | + |
| 71 | +{{/* |
| 72 | + ====== Return the appropriate apiVersion for ingress. ====== |
| 73 | +*/}} |
| 74 | +{{- define "common.capabilities.ingress.apiVersion" -}} |
| 75 | +{{- if .Values.ingress -}} |
| 76 | +{{- if .Values.ingress.apiVersion -}} |
| 77 | +{{- .Values.ingress.apiVersion -}} |
| 78 | +{{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}} |
| 79 | +{{- print "extensions/v1beta1" -}} |
| 80 | +{{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}} |
| 81 | +{{- print "networking.k8s.io/v1beta1" -}} |
| 82 | +{{- else -}} |
| 83 | +{{- print "networking.k8s.io/v1" -}} |
| 84 | +{{- end }} |
| 85 | +{{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}} |
| 86 | +{{- print "extensions/v1beta1" -}} |
| 87 | +{{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}} |
| 88 | +{{- print "networking.k8s.io/v1beta1" -}} |
| 89 | +{{- else -}} |
| 90 | +{{- print "networking.k8s.io/v1" -}} |
| 91 | +{{- end -}} |
| 92 | +{{- end -}} |
| 93 | + |
| 94 | +{{/* |
| 95 | + ====== Return the appropriate apiVersion for RBAC resources. ====== |
| 96 | +*/}} |
| 97 | +{{- define "common.capabilities.rbac.apiVersion" -}} |
| 98 | +{{- if semverCompare "<1.17-0" (include "common.capabilities.kubeVersion" .) -}} |
| 99 | +{{- print "rbac.authorization.k8s.io/v1beta1" -}} |
| 100 | +{{- else -}} |
| 101 | +{{- print "rbac.authorization.k8s.io/v1" -}} |
| 102 | +{{- end -}} |
| 103 | +{{- end -}} |
| 104 | + |
| 105 | +{{/* |
| 106 | + ====== Return the appropriate apiVersion for CRDs. ====== |
| 107 | +*/}} |
| 108 | +{{- define "common.capabilities.crd.apiVersion" -}} |
| 109 | +{{- if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}} |
| 110 | +{{- print "apiextensions.k8s.io/v1beta1" -}} |
| 111 | +{{- else -}} |
| 112 | +{{- print "apiextensions.k8s.io/v1" -}} |
| 113 | +{{- end -}} |
| 114 | +{{- end -}} |
| 115 | + |
| 116 | +{{/* |
| 117 | +Returns true if the used Helm version is 3.3+. |
| 118 | +A way to check the used Helm version was not introduced until version 3.3.0 with .Capabilities.HelmVersion, which contains an additional "{}}" structure. |
| 119 | +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. |
| 120 | +**To be removed when the catalog's minimun Helm version is 3.3** |
| 121 | +*/}} |
| 122 | +{{- define "common.capabilities.supportsHelmVersion" -}} |
| 123 | +{{- if regexMatch "{(v[0-9])*[^}]*}}$" (.Capabilities | toString ) }} |
| 124 | + {{- true -}} |
| 125 | +{{- end -}} |
| 126 | +{{- end -}} |
0 commit comments