|
| 1 | +{{/* vim: set filetype=mustache: */}} |
| 2 | + |
| 3 | +{{/* |
| 4 | +Return the target Kubernetes version |
| 5 | +*/}} |
| 6 | +{{- define "common.capabilities.kubeVersion" -}} |
| 7 | +{{- if .Values.global }} |
| 8 | + {{- if .Values.global.kubeVersion }} |
| 9 | + {{- .Values.global.kubeVersion -}} |
| 10 | + {{- else }} |
| 11 | + {{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}} |
| 12 | + {{- end -}} |
| 13 | +{{- else }} |
| 14 | +{{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}} |
| 15 | +{{- end -}} |
| 16 | +{{- end -}} |
| 17 | + |
| 18 | +{{/* |
| 19 | +Return the appropriate apiVersion for poddisruptionbudget. |
| 20 | +*/}} |
| 21 | +{{- define "common.capabilities.policy.apiVersion" -}} |
| 22 | +{{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}} |
| 23 | +{{- print "policy/v1beta1" -}} |
| 24 | +{{- else -}} |
| 25 | +{{- print "policy/v1" -}} |
| 26 | +{{- end -}} |
| 27 | +{{- end -}} |
| 28 | + |
| 29 | +{{/* |
| 30 | +Return the appropriate apiVersion for networkpolicy. |
| 31 | +*/}} |
| 32 | +{{- define "common.capabilities.networkPolicy.apiVersion" -}} |
| 33 | +{{- if semverCompare "<1.7-0" (include "common.capabilities.kubeVersion" .) -}} |
| 34 | +{{- print "extensions/v1beta1" -}} |
| 35 | +{{- else -}} |
| 36 | +{{- print "networking.k8s.io/v1" -}} |
| 37 | +{{- end -}} |
| 38 | +{{- end -}} |
| 39 | + |
| 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 | +{{/* |
| 52 | +Return the appropriate apiVersion for deployment. |
| 53 | +*/}} |
| 54 | +{{- define "common.capabilities.deployment.apiVersion" -}} |
| 55 | +{{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}} |
| 56 | +{{- print "extensions/v1beta1" -}} |
| 57 | +{{- else -}} |
| 58 | +{{- print "apps/v1" -}} |
| 59 | +{{- end -}} |
| 60 | +{{- end -}} |
| 61 | + |
| 62 | +{{/* |
| 63 | +Return the appropriate apiVersion for statefulset. |
| 64 | +*/}} |
| 65 | +{{- define "common.capabilities.statefulset.apiVersion" -}} |
| 66 | +{{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}} |
| 67 | +{{- print "apps/v1beta1" -}} |
| 68 | +{{- else -}} |
| 69 | +{{- print "apps/v1" -}} |
| 70 | +{{- end -}} |
| 71 | +{{- end -}} |
| 72 | + |
| 73 | +{{/* |
| 74 | +Return the appropriate apiVersion for ingress. |
| 75 | +*/}} |
| 76 | +{{- define "common.capabilities.ingress.apiVersion" -}} |
| 77 | +{{- if .Values.ingress -}} |
| 78 | +{{- if .Values.ingress.apiVersion -}} |
| 79 | +{{- .Values.ingress.apiVersion -}} |
| 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 | +{{- 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 | +{{- end -}} |
| 95 | + |
| 96 | +{{/* |
| 97 | +Return the appropriate apiVersion for RBAC resources. |
| 98 | +*/}} |
| 99 | +{{- define "common.capabilities.rbac.apiVersion" -}} |
| 100 | +{{- if semverCompare "<1.17-0" (include "common.capabilities.kubeVersion" .) -}} |
| 101 | +{{- print "rbac.authorization.k8s.io/v1beta1" -}} |
| 102 | +{{- else -}} |
| 103 | +{{- print "rbac.authorization.k8s.io/v1" -}} |
| 104 | +{{- end -}} |
| 105 | +{{- end -}} |
| 106 | + |
| 107 | +{{/* |
| 108 | +Return the appropriate apiVersion for CRDs. |
| 109 | +*/}} |
| 110 | +{{- define "common.capabilities.crd.apiVersion" -}} |
| 111 | +{{- if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}} |
| 112 | +{{- print "apiextensions.k8s.io/v1beta1" -}} |
| 113 | +{{- else -}} |
| 114 | +{{- print "apiextensions.k8s.io/v1" -}} |
| 115 | +{{- end -}} |
| 116 | +{{- end -}} |
| 117 | + |
| 118 | +{{/* |
| 119 | +Return the appropriate apiVersion for APIService. |
| 120 | +*/}} |
| 121 | +{{- define "common.capabilities.apiService.apiVersion" -}} |
| 122 | +{{- if semverCompare "<1.10-0" (include "common.capabilities.kubeVersion" .) -}} |
| 123 | +{{- print "apiregistration.k8s.io/v1beta1" -}} |
| 124 | +{{- else -}} |
| 125 | +{{- print "apiregistration.k8s.io/v1" -}} |
| 126 | +{{- end -}} |
| 127 | +{{- end -}} |
| 128 | + |
| 129 | +{{/* |
| 130 | +Return the appropriate apiVersion for Horizontal Pod Autoscaler. |
| 131 | +*/}} |
| 132 | +{{- define "common.capabilities.hpa.apiVersion" -}} |
| 133 | +{{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .context) -}} |
| 134 | +{{- if .beta2 -}} |
| 135 | +{{- print "autoscaling/v2beta2" -}} |
| 136 | +{{- else -}} |
| 137 | +{{- print "autoscaling/v2beta1" -}} |
| 138 | +{{- end -}} |
| 139 | +{{- else -}} |
| 140 | +{{- print "autoscaling/v2" -}} |
| 141 | +{{- end -}} |
| 142 | +{{- end -}} |
| 143 | + |
| 144 | +{{/* |
| 145 | +Returns true if the used Helm version is 3.3+. |
| 146 | +A way to check the used Helm version was not introduced until version 3.3.0 with .Capabilities.HelmVersion, which contains an additional "{}}" structure. |
| 147 | +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. |
| 148 | +**To be removed when the catalog's minimun Helm version is 3.3** |
| 149 | +*/}} |
| 150 | +{{- define "common.capabilities.supportsHelmVersion" -}} |
| 151 | +{{- if regexMatch "{(v[0-9])*[^}]*}}$" (.Capabilities | toString ) }} |
| 152 | + {{- true -}} |
| 153 | +{{- end -}} |
| 154 | +{{- end -}} |
0 commit comments