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
@@ -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 || '<none>',
|
||||
type: spec.type || s.type || 'ClusterIP',
|
||||
clusterIP: spec.clusterIP || s.cluster_ip || '<none>',
|
||||
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 || '<none>',
|
||||
className: spec.ingressClassName || i.ingressClass || '<none>',
|
||||
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,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user