{{/* 生成一个 K8s API 版本兼容的后端入口。 调用: {{ include "common.ingress.backend" (dict "serviceName" "backendName" "servicePort" "backendPort" "context" $) }} 参数: - serviceName: 字符串。已存在的后端服务名称。 - servicePort: 字符串/整数。已存在的后端服务的端口名称(或端口号). 根据数据类型不同,生成不同 YAML。 - context: 字典(必须)。父级上下文信息(`$`: 根上下文; `.`: 当前模板上下文)。 */}} {{- define "common.ingress.backend" -}} {{- $apiVersion := (include "common.capabilities.ingress.apiVersion" .context) -}} {{- if or (eq $apiVersion "extensions/v1beta1") (eq $apiVersion "networking.k8s.io/v1beta1") -}} serviceName: {{ .serviceName }} servicePort: {{ .servicePort }} {{- else -}} service: name: {{ .serviceName }} port: {{- if typeIs "string" .servicePort }} name: {{ .servicePort }} {{- else if or (typeIs "int" .servicePort) (typeIs "float64" .servicePort) }} number: {{ .servicePort | int }} {{- end }} {{- end -}} {{- end -}} {{/* 返回是否支持 pathType (true / false)。 调用: {{ include "common.ingress.supportsPathType" . }} */}} {{- define "common.ingress.supportsPathType" -}} {{- if (semverCompare "<1.18-0" (include "common.capabilities.kubeVersion" .)) -}} {{- print "false" -}} {{- else -}} {{- print "true" -}} {{- end -}} {{- end -}} {{/* 返回是否支持 ingressClassname (true / false)。 调用: {{ include "common.ingress.supportsIngressClassname" . }} */}} {{- define "common.ingress.supportsIngressClassname" -}} {{- if semverCompare "<1.18-0" (include "common.capabilities.kubeVersion" .) -}} {{- print "false" -}} {{- else -}} {{- print "true" -}} {{- end -}} {{- end -}} {{/* 返回 cert-manager 需要的注解(TLS 签名证书)是否存在(true / false)。 参考: https://cert-manager.io/docs/usage/ingress/#supported-annotations 调用: {{ include "common.ingress.certManagerRequest" ( dict "annotations" .Values.path.to.the.ingress.annotations ) }} */}} {{- define "common.ingress.certManagerRequest" -}} {{ if or (hasKey .annotations "cert-manager.io/cluster-issuer") (hasKey .annotations "cert-manager.io/issuer") (hasKey .annotations "kubernetes.io/tls-acme") }} {{- true -}} {{- end -}} {{- end -}}