From 60934277ac8d6c7aa6ce98957c1b9405dec0297c Mon Sep 17 00:00:00 2001 From: attacker Date: Tue, 23 Jun 2026 02:37:33 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20kubectl=E6=9C=AC=E5=9C=B0=E6=89=93?= =?UTF-8?q?=E5=8C=85=E9=81=BFdocker=E4=B8=8B=E8=BD=BD=E8=B6=85=E6=97=B6;?= =?UTF-8?q?=20Service=E5=85=B3=E8=81=94=E7=94=A8spec.selector=E8=80=8C?= =?UTF-8?q?=E9=9D=9Emetadata.labels;=20=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E5=85=BC=E5=AE=B9SvcSummary/IngSummary=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ Dockerfile.embed | 7 ++- backend/Dockerfile | 7 ++- .../kubernetes/DeploymentEditService.tsx | 43 +++++++++++-------- .../kubernetes/DeploymentWorkload.tsx | 2 +- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 2affab2..9cc8d2c 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ backend/cmd/static/ # Hermes agent config (personal, not project) .hermes/ + +# kubectl 二进制(预打包进镜像,避免 Docker build 时网络下载) +backend/kubectl diff --git a/Dockerfile.embed b/Dockerfile.embed index e2fb96c..d3d7cf3 100644 --- a/Dockerfile.embed +++ b/Dockerfile.embed @@ -89,10 +89,9 @@ RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apk/re # kubectl=预装(~50MB),maven/nodejs/helm → 工具配置Tab懒加载 RUN apk --no-cache add ca-certificates tzdata bash curl git docker-cli docker-cli-buildx -# kubectl 预装 // Logan.Li -ARG KUBECTL_VERSION=v1.32.0 -RUN curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \ - chmod +x /usr/local/bin/kubectl +# kubectl 预装(本地打包进镜像,避免 Docker build 时网络下载)// Logan.Li +COPY backend/kubectl /usr/local/bin/kubectl +RUN chmod +x /usr/local/bin/kubectl # Maven 阿里云镜像加速(maven 懒加载后生效) RUN mkdir -p /root/.m2 && \ diff --git a/backend/Dockerfile b/backend/Dockerfile index e727e01..70ed2d6 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -83,10 +83,9 @@ RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apk/re RUN --mount=type=cache,target=/var/cache/apk \ apk add ca-certificates tzdata bash curl git docker-cli docker-cli-buildx -# kubectl 预装(~50MB,国内网络从 dl.k8s.io 下载约10s)// Logan.Li -ARG KUBECTL_VERSION=v1.32.0 -RUN curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \ - chmod +x /usr/local/bin/kubectl +# kubectl 预装(~50MB,本地打包进镜像,避免 Docker build 时网络下载)// Logan.Li +COPY backend/kubectl /usr/local/bin/kubectl +RUN chmod +x /usr/local/bin/kubectl # npm 淘宝镜像加速(node 懒加载后生效) RUN npm config set registry https://registry.npmmirror.com 2>/dev/null || true diff --git a/frontend/src/components/kubernetes/DeploymentEditService.tsx b/frontend/src/components/kubernetes/DeploymentEditService.tsx index 93ff5a5..a649c67 100644 --- a/frontend/src/components/kubernetes/DeploymentEditService.tsx +++ b/frontend/src/components/kubernetes/DeploymentEditService.tsx @@ -82,40 +82,49 @@ export function DeploymentEditService({ clusterCode, namespace, deploymentName, const allIngs = toArray(ingRes); const svcSummaries: SvcSummary[] = allSvcs.map((s: any) => { - const spec = s.spec || s.raw?.spec || {}; + // 兼容两种数据源:完整 K8s spec 或后端 SvcSummary 顶层字段 + const spec = s.spec || {}; const ports = Array.isArray(spec.ports) ? spec.ports.map((p: any) => ({ port: p.port, targetPort: p.targetPort, protocol: p.protocol || 'TCP', nodePort: p.nodePort, name: p.name, + })) : Array.isArray(s.portList) ? s.portList.map((p: any) => ({ + port: p.port, targetPort: p.targetPort, protocol: p.protocol || 'TCP', + nodePort: p.nodePort, name: p.name, })) : []; return { name: s.name || s.metadata?.name || '', - type: spec.type || 'ClusterIP', - clusterIP: spec.clusterIP || '', + type: spec.type || s.type || 'ClusterIP', + clusterIP: spec.clusterIP || s.cluster_ip || '', externalIP: Array.isArray(spec.externalIPs) ? spec.externalIPs.join(',') : '', ports, - selector: spec.selector || {}, + // selector: 优先 spec.selector(完整 K8s),降级 s.selector(SvcSummary 顶层) + selector: spec.selector || s.selector || {}, age: s.age || s.created_at || '', raw: s, }; }); const ingSummaries: IngSummary[] = allIngs.map((i: any) => { - const spec = i.spec || i.raw?.spec || {}; - const rules: any[] = Array.isArray(spec.rules) ? spec.rules : []; + // 兼容:完整 K8s spec 或后端 IngSummary 顶层字段 + const spec = i.spec || {}; + // 规则来源:spec.rules (K8s) 或 i.rules (IngSummary,含 backendService/backendPort) + const rawRules: any[] = Array.isArray(spec.rules) ? spec.rules : (Array.isArray(i.rules) ? i.rules : []); + const rules = rawRules.map((r: any) => ({ + host: r.host || '', + paths: (r.http?.paths || r.paths || []).map((p: any) => ({ + path: p.path || '/', + backend: { + // K8s 格式: p.backend.service.name / IngSummary 格式: p.backendService + service: p.backend?.service?.name || p.backendService || '', + port: p.backend?.service?.port?.number || p.backend?.service?.port?.name || p.backendPort || '', + }, + })), + })); return { name: i.name || i.metadata?.name || '', - className: spec.ingressClassName || '', + className: spec.ingressClassName || i.ingressClass || '', hosts: rules.map((r: any) => r.host).filter(Boolean), - rules: rules.map((r: any) => ({ - host: r.host || '', - paths: (r.http?.paths || []).map((p: any) => ({ - path: p.path || '/', - backend: { - service: p.backend?.service?.name || '', - port: p.backend?.service?.port?.number || p.backend?.service?.port?.name || '', - }, - })), - })), + rules, raw: i, }; }); diff --git a/frontend/src/components/kubernetes/DeploymentWorkload.tsx b/frontend/src/components/kubernetes/DeploymentWorkload.tsx index 9f2f9d3..e1eca6f 100644 --- a/frontend/src/components/kubernetes/DeploymentWorkload.tsx +++ b/frontend/src/components/kubernetes/DeploymentWorkload.tsx @@ -372,7 +372,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod 运行时 navigate(`${viewBase}/view/Service?selector=${encodeURIComponent(JSON.stringify(deployment.labels || {}))}`)}> + onClick={() => navigate(`${viewBase}/view/Service?selector=${encodeURIComponent(JSON.stringify(deployment?.spec?.selector?.matchLabels || deployment?.spec?.template?.metadata?.labels || {}))}`)}> 服务