fix: kubectl本地打包避docker下载超时; Service关联用spec.selector而非metadata.labels; 数据源兼容SvcSummary/IngSummary格式
This commit is contained in:
1 parent
451f65f9c8
commit
60934277ac
5 files changed
+36
-26
No files matched your search
@@ -59,3 +59,6 @@ backend/cmd/static/
|
|||||||
|
|
||||||
# Hermes agent config (personal, not project)
|
# Hermes agent config (personal, not project)
|
||||||
.hermes/
|
.hermes/
|
||||||
|
|
||||||
|
# kubectl 二进制(预打包进镜像,避免 Docker build 时网络下载)
|
||||||
|
backend/kubectl
|
||||||
+3
-4
@@ -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懒加载
|
# kubectl=预装(~50MB),maven/nodejs/helm → 工具配置Tab懒加载
|
||||||
RUN apk --no-cache add ca-certificates tzdata bash curl git docker-cli docker-cli-buildx
|
RUN apk --no-cache add ca-certificates tzdata bash curl git docker-cli docker-cli-buildx
|
||||||
|
|
||||||
# kubectl 预装 // Logan.Li
|
# kubectl 预装(本地打包进镜像,避免 Docker build 时网络下载)// Logan.Li
|
||||||
ARG KUBECTL_VERSION=v1.32.0
|
COPY backend/kubectl /usr/local/bin/kubectl
|
||||||
RUN curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
|
RUN chmod +x /usr/local/bin/kubectl
|
||||||
chmod +x /usr/local/bin/kubectl
|
|
||||||
|
|
||||||
# Maven 阿里云镜像加速(maven 懒加载后生效)
|
# Maven 阿里云镜像加速(maven 懒加载后生效)
|
||||||
RUN mkdir -p /root/.m2 && \
|
RUN mkdir -p /root/.m2 && \
|
||||||
|
|||||||
+3
-4
@@ -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 \
|
RUN --mount=type=cache,target=/var/cache/apk \
|
||||||
apk add ca-certificates tzdata bash curl git docker-cli docker-cli-buildx
|
apk add ca-certificates tzdata bash curl git docker-cli docker-cli-buildx
|
||||||
|
|
||||||
# kubectl 预装(~50MB,国内网络从 dl.k8s.io 下载约10s)// Logan.Li
|
# kubectl 预装(~50MB,本地打包进镜像,避免 Docker build 时网络下载)// Logan.Li
|
||||||
ARG KUBECTL_VERSION=v1.32.0
|
COPY backend/kubectl /usr/local/bin/kubectl
|
||||||
RUN curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
|
RUN chmod +x /usr/local/bin/kubectl
|
||||||
chmod +x /usr/local/bin/kubectl
|
|
||||||
|
|
||||||
# npm 淘宝镜像加速(node 懒加载后生效)
|
# npm 淘宝镜像加速(node 懒加载后生效)
|
||||||
RUN npm config set registry https://registry.npmmirror.com 2>/dev/null || true
|
RUN npm config set registry https://registry.npmmirror.com 2>/dev/null || true
|
||||||
|
|||||||
@@ -82,40 +82,49 @@ export function DeploymentEditService({ clusterCode, namespace, deploymentName,
|
|||||||
const allIngs = toArray(ingRes);
|
const allIngs = toArray(ingRes);
|
||||||
|
|
||||||
const svcSummaries: SvcSummary[] = allSvcs.map((s: any) => {
|
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) => ({
|
const ports = Array.isArray(spec.ports) ? spec.ports.map((p: any) => ({
|
||||||
port: p.port, targetPort: p.targetPort, protocol: p.protocol || 'TCP',
|
port: p.port, targetPort: p.targetPort, protocol: p.protocol || 'TCP',
|
||||||
nodePort: p.nodePort, name: p.name,
|
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 {
|
return {
|
||||||
name: s.name || s.metadata?.name || '',
|
name: s.name || s.metadata?.name || '',
|
||||||
type: spec.type || 'ClusterIP',
|
type: spec.type || s.type || 'ClusterIP',
|
||||||
clusterIP: spec.clusterIP || '<none>',
|
clusterIP: spec.clusterIP || s.cluster_ip || '<none>',
|
||||||
externalIP: Array.isArray(spec.externalIPs) ? spec.externalIPs.join(',') : '',
|
externalIP: Array.isArray(spec.externalIPs) ? spec.externalIPs.join(',') : '',
|
||||||
ports,
|
ports,
|
||||||
selector: spec.selector || {},
|
// selector: 优先 spec.selector(完整 K8s),降级 s.selector(SvcSummary 顶层)
|
||||||
|
selector: spec.selector || s.selector || {},
|
||||||
age: s.age || s.created_at || '',
|
age: s.age || s.created_at || '',
|
||||||
raw: s,
|
raw: s,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const ingSummaries: IngSummary[] = allIngs.map((i: any) => {
|
const ingSummaries: IngSummary[] = allIngs.map((i: any) => {
|
||||||
const spec = i.spec || i.raw?.spec || {};
|
// 兼容:完整 K8s spec 或后端 IngSummary 顶层字段
|
||||||
const rules: any[] = Array.isArray(spec.rules) ? spec.rules : [];
|
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 {
|
return {
|
||||||
name: i.name || i.metadata?.name || '',
|
name: i.name || i.metadata?.name || '',
|
||||||
className: spec.ingressClassName || '<none>',
|
className: spec.ingressClassName || i.ingressClass || '<none>',
|
||||||
hosts: rules.map((r: any) => r.host).filter(Boolean),
|
hosts: rules.map((r: any) => r.host).filter(Boolean),
|
||||||
rules: rules.map((r: any) => ({
|
rules,
|
||||||
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 || '',
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
raw: i,
|
raw: i,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ export function DeploymentWorkload({ clusterCode, namespace, deploymentName, mod
|
|||||||
<Cpu className="h-4 w-4 mr-2 text-slate-400" /> 运行时
|
<Cpu className="h-4 w-4 mr-2 text-slate-400" /> 运行时
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem className="text-slate-300 hover:bg-slate-800 cursor-pointer"
|
<DropdownMenuItem className="text-slate-300 hover:bg-slate-800 cursor-pointer"
|
||||||
onClick={() => 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 || {}))}`)}>
|
||||||
<Network className="h-4 w-4 mr-2 text-slate-400" /> 服务
|
<Network className="h-4 w-4 mr-2 text-slate-400" /> 服务
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem className="text-slate-300 hover:bg-slate-800 cursor-pointer"
|
<DropdownMenuItem className="text-slate-300 hover:bg-slate-800 cursor-pointer"
|
||||||
|
|||||||
Reference in new issue
Block a user