1111 {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
1212 {{- end }}
1313{{- end }}
14+ {{- $subPath := .Values.ingress.path | default "" -}}
15+ {{- $isSubpathMode := eq .Values.global.bkWebSiteAccess.mode "subpath" -}}
1416{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
1517apiVersion : networking.k8s.io/v1
1618{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
@@ -33,6 +35,10 @@ metadata:
3335 {{- range $key, $value := .Values.ingress.annotations }}
3436 {{ $key }}: {{ include "common.tplvalues.render" (dict "value" $value "context" $) | quote }}
3537 {{- end }}
38+ {{- if eq .Values.global.bkWebSiteAccess.mode "subpath" }}
39+ nginx.ingress.kubernetes.io/use-regex : " true"
40+ nginx.ingress.kubernetes.io/rewrite-target : /$2
41+ {{- end }}
3642spec :
3743 {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
3844 ingressClassName : {{ .Values.ingress.className }}
@@ -52,17 +58,25 @@ spec:
5258 - host : {{ .Values.ingress.hostname }}
5359 http :
5460 paths :
55- {{- if .Values.ingress.extraPaths }}
56- {{- toYaml .Values.ingress.extraPaths | nindent 10 }}
57- {{- end }}
5861 {{- range .Values.ingress.paths }}
59- - path : {{ .path }}
62+ {{- /* 核心逻辑:判断是否拼接子路径 */ -}}
63+ {{- $currentPath := .path -}}
64+ {{- if $isSubpathMode }}
65+ {{- /* 如果路径是 /,则直接拼接前缀;如果是其他路径如 /static/,则拼在前面 */ -}}
66+ {{- if eq .path "/" }}
67+ {{- $currentPath = printf "%s(/|$)(.*)" $subPath -}}
68+ {{- else }}
69+ {{- $currentPath = printf "%s%s(/|$)(.*)" $subPath .path -}}
70+ {{- end }}
71+ {{- end }}
72+ - path : {{ $currentPath }}
6073 {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
61- pathType : {{ .pathType }}
74+ {{- /* 注意:使用正则和重写时,pathType 必须为 ImplementationSpecific */ -}}
75+ pathType : {{ if $isSubpathMode }}ImplementationSpecific{{ else }}{{ .pathType }}{{ end }}
6276 {{- end }}
6377 backend :
64- {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
6578 service :
79+ {{- /* 这里保持原有的 Service 分流逻辑,使用原始的 .path 匹配 */ -}}
6680 {{- if or (eq "/backend/" .path) (eq "/core/api/gray/" .path) }}
6781 name : " {{ $backendApiFullName }}"
6882 port :
7690 port :
7791 number : {{ $saasApiSvcPort }}
7892 {{- end }}
79- {{- else }}
80- {{- if eq "/backend/" .path }}
81- serviceName : " {{ $backendApiFullName }}"
82- servicePort : {{ $backendApiSvcPort }}
83- {{- else if eq "/static/" .path }}
84- serviceName : " {{ $saasWebFullName }}"
85- servicePort : {{ $saasWebSvcPort }}
86- {{- else }}
87- serviceName : " {{ $saasApiFullName }}"
88- servicePort : {{ $saasApiSvcPort }}
89- {{- end }}
90- {{- end }}
9193 {{- end }}
9294 {{- end }}
9395 {{- if or (and .Values.ingress.tls (or (include "bk-nodeman.ingress.certManagerRequest" .Values.ingress.annotations) .Values.ingress.selfSigned)) .Values.ingress.extraTls }}
0 commit comments