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