Skip to content

Commit a0c0530

Browse files
committed
feat: 支持子域名子路径
# Reviewed, transaction id: 68710
1 parent 3f2da5f commit a0c0530

4 files changed

Lines changed: 56 additions & 19 deletions

File tree

support-files/kubernetes/helm/bk-nodeman/templates/_helpers.tpl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,28 @@ initContainers:
290290
resources:
291291
{{- toYaml .Values.migrateJob.fileSync.resources | nindent 6 }}
292292
{{- end }}
293+
294+
{{- define "bk-nodeman.ingress-host" -}}
295+
{{- $ingress := index . 0 -}}
296+
{{- $global := index . 1 -}}
297+
{{- if eq $global.bkWebSiteAccess.mode "subpath" -}}
298+
{{- $global.bkDomain -}}
299+
{{- else -}}
300+
{{- printf "%s.%s" $ingress.name $global.bkDomain -}}
301+
{{- end -}}
302+
{{- end -}}
303+
304+
{{- define "bk-nodeman.ingress-url" -}}
305+
{{- $ingress := index . 0 -}}
306+
{{- $global := index . 1 -}}
307+
{{- $host := include "bk-nodeman.ingress-host" (list $ingress $global) -}}
308+
{{- if $ingress.port -}}
309+
{{- $host = printf "%s:%v" $host $ingress.port -}}
310+
{{- end -}}
311+
{{- $scheme := $global.bkDomainScheme -}}
312+
{{- if eq $global.bkWebSiteAccess.mode "subpath" -}}
313+
{{- printf "%s://%s" $scheme (include "bk-nodeman.urljoin" (list $host $ingress.name $ingress.path) | trimSuffix "/") -}}
314+
{{- else -}}
315+
{{- printf "%s://%s" $scheme (include "bk-nodeman.urljoin" (list $host $ingress.path) | trimSuffix "/") -}}
316+
{{- end -}}
317+
{{- end -}}

support-files/kubernetes/helm/bk-nodeman/templates/configmaps/env-configmap.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ data:
5959
BKAPP_BK_GSE_APIGATEWAY: "{{ .Values.config.bkAppBkGseApiGateway }}/"
6060
{{- end }}
6161

62+
{{- if eq .Values.global.bkWebSiteAccess.mode "subpath"}}
63+
BK_NODEMAN_SUBPATH: "/bknodeman/"
64+
{{- else}}
65+
BK_NODEMAN_SUBPATH: "/"
66+
{{- end}}
67+
6268
BK_NODEMAN_URL: "{{ .Values.bkNodemanUrl }}"
6369
BKAPP_BACKEND_HOST: "{{ .Values.config.bkAppBackendHost | default .Values.bkNodemanApiUrl }}"
6470
BKAPP_NODEMAN_CALLBACK_URL: "{{ .Values.config.bkAppNodemanCallbackUrl | default ( printf "%s/%s" .Values.bkNodemanUrl "backend" ) }}"

support-files/kubernetes/helm/bk-nodeman/templates/ingress.yaml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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 -}}
1517
apiVersion: 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 }}
3642
spec:
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:
@@ -76,18 +90,6 @@ spec:
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 }}

support-files/kubernetes/helm/bk-nodeman/values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ global:
1111
bkCryptoType: "CLASSIC"
1212
## 蓝鲸主域名访问协议http/https
1313
bkDomainScheme: http
14+
bkWebSiteAccess:
15+
mode: "subdomain"
1416

1517
nameOverride: ""
1618
fullnameOverride: ""
@@ -164,7 +166,9 @@ ingress:
164166
nginx.ingress.kubernetes.io/proxy-body-size: "1024m"
165167
# kubernetes.io/ingress.class: nginx
166168
# kubernetes.io/tls-acme: "true"
167-
169+
name: "bknodeman"
170+
path: "/bknodeman/"
171+
port: 80
168172
hostname: "bknodeman.example.com"
169173
paths:
170174
- path: /

0 commit comments

Comments
 (0)