|
11 | 11 | {{- define "cluster.tls_certificates.secret_name" -}} |
12 | 12 | {{- if .Values.cluster.tls_certificates.create -}} |
13 | 13 | {{- include "cluster.fullname" . }}-tls-certificates |
| 14 | + {{- else if (include "cluster.tls_certificates.use_cert_manager" .) -}} |
| 15 | + {{- include "cluster.tls_certificates.cm_certificate_name" . -}} |
14 | 16 | {{- else if .Values.cluster.tls_certificates.secret_name -}} |
15 | 17 | {{- .Values.cluster.tls_certificates.secret_name -}} |
16 | 18 | {{- else -}} |
|
47 | 49 | {{- end -}} |
48 | 50 | {{- $dnsNames | toYaml -}} |
49 | 51 | {{- end }} |
| 52 | + |
| 53 | +{{- define "cluster.tls_certificates.check_conflicts" -}} |
| 54 | + {{- if and .Values.cluster.tls_certificates.create .Values.cluster.tls_certificates.cert_manager.enabled -}} |
| 55 | + {{- fail "Cannot specify both tls_certificates.create and tls_certificates.cert_manager.enabled" -}} |
| 56 | + {{- end -}} |
| 57 | + {{- if and (not (quote .Values.cluster.tls_certificates.secret_name | empty)) .Values.cluster.tls_certificates.cert_manager.enabled -}} |
| 58 | + {{- fail "Cannot specify both tls_certificates.cert_manager.enabled and tls_certificates.secret_name" -}} |
| 59 | + {{- end -}} |
| 60 | +{{- end }} |
| 61 | + |
| 62 | +{{- define "cluster.tls_certificates.use_cert_manager" -}} |
| 63 | + {{- if and .Values.cluster.tls_certificates.cert_manager .Values.cluster.tls_certificates.cert_manager.enabled -}} |
| 64 | + {{- if and (not .Values.cluster.tls_certificates.cert_manager.ca.generate) (not .Values.cluster.tls_certificates.cert_manager.ca.secret_name) -}} |
| 65 | + {{- fail "cert_manager.ca.secret_name must be specified when CA generation is disabled" -}} |
| 66 | + {{- end -}} |
| 67 | + {{- if and (not .Values.cluster.tls_certificates.cert_manager.issuer.generate) (not .Values.cluster.tls_certificates.cert_manager.issuer.name) -}} |
| 68 | + {{- fail "cert_manager.issuer.name must be specified when Issuer generation is disabled" -}} |
| 69 | + {{- end -}} |
| 70 | + {{- true -}} |
| 71 | + {{- end -}} |
| 72 | +{{- end }} |
| 73 | + |
| 74 | +{{- define "cluster.tls_certificates.cm_certificate_name" -}} |
| 75 | + {{- printf "%s-cm-tls" ((include "cluster.fullname" .) | trimSuffix "-" | trunc 57) -}} |
| 76 | +{{- end }} |
| 77 | + |
| 78 | +{{- define "cluster.tls_certificates.cm_ca_secret_name" -}} |
| 79 | + {{- if .Values.cluster.tls_certificates.cert_manager.ca.generate -}} |
| 80 | + {{- printf "%s-cm-ca" ((include "cluster.fullname" .) | trimSuffix "-" | trunc 58) -}} |
| 81 | + {{- else -}} |
| 82 | + {{- .Values.cluster.tls_certificates.cert_manager.ca.secret_name -}} |
| 83 | + {{- end -}} |
| 84 | +{{- end }} |
| 85 | + |
| 86 | +{{- define "cluster.tls_certificates.cm_generate_ca" -}} |
| 87 | + {{- if and (include "cluster.tls_certificates.use_cert_manager" .) (.Values.cluster.tls_certificates.cert_manager.ca.generate) -}} |
| 88 | + {{- true -}} |
| 89 | + {{- end -}} |
| 90 | +{{- end }} |
| 91 | + |
| 92 | +{{- define "cluster.tls_certificates.cm_generate_issuer" -}} |
| 93 | + {{- if and (include "cluster.tls_certificates.use_cert_manager" .) (.Values.cluster.tls_certificates.cert_manager.issuer.generate) -}} |
| 94 | + {{- true -}} |
| 95 | + {{- end -}} |
| 96 | +{{- end }} |
| 97 | + |
| 98 | +{{- define "cluster.tls_certificates.cm_issuer_name" -}} |
| 99 | + {{- if .Values.cluster.tls_certificates.cert_manager.issuer.generate -}} |
| 100 | + {{- printf "%s-cm-self-issuer" ((include "cluster.fullname" .) | trimSuffix "-" | trunc 49) -}} |
| 101 | + {{- else -}} |
| 102 | + {{- .Values.cluster.tls_certificates.cert_manager.issuer.name -}} |
| 103 | + {{- end -}} |
| 104 | +{{- end }} |
| 105 | + |
| 106 | +{{- define "cluster.tls_certificates.cm_issuer_namespace" -}} |
| 107 | + {{- if .Values.cluster.tls_certificates.cert_manager.issuer.generate -}} |
| 108 | + {{- if and (not .Values.cluster.tls_certificates.cert_manager.ca.generate) (not (empty .Values.cluster.tls_certificates.cert_manager.ca.secret_namespace)) -}} |
| 109 | + {{- .Values.cluster.tls_certificates.cert_manager.ca.secret_namespace -}} |
| 110 | + {{- else -}} |
| 111 | + {{- .Release.Namespace -}} |
| 112 | + {{- end -}} |
| 113 | + {{- else -}} |
| 114 | + {{- .Release.Namespace -}} |
| 115 | + {{- end -}} |
| 116 | +{{- end }} |
| 117 | + |
| 118 | +{{- define "cluster.tls_certificates.cm_self_ca_cert_name" -}} |
| 119 | + {{- printf "%s-cm-self-ca" ((include "cluster.fullname" .) | trimSuffix "-" | trunc 53) -}} |
| 120 | +{{- end }} |
| 121 | + |
| 122 | +{{- define "cluster.tls_certificates.cm_issuer_kind" -}} |
| 123 | + {{- if .Values.cluster.tls_certificates.cert_manager.issuer.generate -}} |
| 124 | + {{- if and (not .Values.cluster.tls_certificates.cert_manager.ca.generate) (not (empty .Values.cluster.tls_certificates.cert_manager.ca.secret_namespace)) -}} |
| 125 | + {{- "ClusterIssuer" -}} |
| 126 | + {{- else -}} |
| 127 | + {{- "Issuer" -}} |
| 128 | + {{- end -}} |
| 129 | + {{- else -}} |
| 130 | + {{- .Values.cluster.tls_certificates.cert_manager.issuer.kind -}} |
| 131 | + {{- end -}} |
| 132 | +{{- end }} |
| 133 | + |
| 134 | +{{- define "cluster.tls_certificates.cm_issuer_group" -}} |
| 135 | + {{- if .Values.cluster.tls_certificates.cert_manager.issuer.generate -}} |
| 136 | + {{- "cert-manager.io" -}} |
| 137 | + {{- else -}} |
| 138 | + {{- .Values.cluster.tls_certificates.cert_manager.issuer.group -}} |
| 139 | + {{- end -}} |
| 140 | +{{- end }} |
| 141 | + |
| 142 | +{{/* |
| 143 | +If we are generating the Issuer we are going to use the CA secret for the inject-ca annotation, |
| 144 | +because the Issuer maybe not ready yet. |
| 145 | +*/}} |
| 146 | +{{- define "cluster.tls_certificates.cm_use_ca_secret" -}} |
| 147 | + {{- if (include "cluster.tls_certificates.cm_generate_issuer" .) -}} |
| 148 | + {{- true -}} |
| 149 | + {{- end -}} |
| 150 | +{{- end }} |
| 151 | + |
| 152 | +{{- define "cluster.tls_certificates.cm_ca_secret_template" -}} |
| 153 | + {{- $tmpl := .Values.cluster.tls_certificates.cert_manager.ca.secret_template -}} |
| 154 | + {{- $injectAnnotation := "cert-manager.io/allow-direct-injection" -}} |
| 155 | + {{- if and (include "cluster.tls_certificates.cm_generate_ca" .) (include "cluster.tls_certificates.cm_generate_issuer" .) -}} |
| 156 | + {{- $currentAnnotations := $tmpl.annotations | default (dict) -}} |
| 157 | + {{- $_ := set $tmpl "annotations" (merge $currentAnnotations (dict $injectAnnotation "true")) -}} |
| 158 | + {{- end -}} |
| 159 | + {{- $tmpl | toYaml -}} |
| 160 | +{{- end }} |
0 commit comments