初始化功能函数库

This commit is contained in:
2025-03-10 16:39:13 +08:00
parent 71ade9d8b3
commit 136d42a31e
20 changed files with 1381 additions and 2 deletions
+64
View File
@@ -0,0 +1,64 @@
{{/*
生成一个 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 需要的注解是否存在(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 -}}