From 14da8490461ff924a49659658a6fedf8a789d83c Mon Sep 17 00:00:00 2001 From: gary fly <1779905848@qq.com> Date: Tue, 14 Apr 2026 17:00:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=94=A8=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E6=90=9C=E7=B4=A2=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/lib/k8s.ts | 34 ++++++++++++++++++++++++++++++ ui/src/pages/service-list-page.tsx | 9 ++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ui/src/lib/k8s.ts b/ui/src/lib/k8s.ts index 84c6adea..b22a92d7 100644 --- a/ui/src/lib/k8s.ts +++ b/ui/src/lib/k8s.ts @@ -402,6 +402,40 @@ export function getServiceExternalIP(service: Service): string { } } +/** Tokens used by the Services list search (name/type/IP + port / nodePort / targetPort). */ +export function getServicePortSearchValues(service: Service): string[] { + const ports = service.spec?.ports ?? [] + const out: string[] = [] + for (const p of ports) { + const protocol = (p.protocol || 'TCP').toLowerCase() + if (p.port != null) { + out.push(String(p.port)) + out.push(`${p.port}/${protocol}`) + } + if (p.nodePort != null) { + out.push(String(p.nodePort)) + } + const tp = p.targetPort as unknown + if (tp !== undefined && tp !== null) { + if (typeof tp === 'number' || typeof tp === 'string') { + out.push(String(tp)) + } else if (typeof tp === 'object') { + const o = tp as { StrVal?: string; IntVal?: number } + if (o.StrVal != null) out.push(o.StrVal) + else if (o.IntVal != null) out.push(String(o.IntVal)) + } + } + if (p.port != null) { + if (p.nodePort != null) { + out.push(`${p.port}:${p.nodePort}/${p.protocol || 'TCP'}`) + } else { + out.push(`${p.port}/${p.protocol || 'TCP'}`) + } + } + } + return out +} + // Helper function to check if pod has ready condition function hasPodReadyCondition(conditions?: Array<{ type?: string }>): boolean { return conditions?.some((condition) => condition.type === 'Ready') ?? false diff --git a/ui/src/pages/service-list-page.tsx b/ui/src/pages/service-list-page.tsx index c709c25e..bf014087 100644 --- a/ui/src/pages/service-list-page.tsx +++ b/ui/src/pages/service-list-page.tsx @@ -4,7 +4,11 @@ import { Service } from 'kubernetes-types/core/v1' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' -import { createSearchFilter, getServiceExternalIP } from '@/lib/k8s' +import { + createSearchFilter, + getServiceExternalIP, + getServicePortSearchValues, +} from '@/lib/k8s' import { formatDate } from '@/lib/utils' import { Badge } from '@/components/ui/badge' import { ResourceTable } from '@/components/resource-table' @@ -12,7 +16,8 @@ import { ResourceTable } from '@/components/resource-table' const serviceSearchFilter = createSearchFilter( (s) => s.metadata?.name, (s) => s.spec?.type, - (s) => s.spec?.clusterIP + (s) => s.spec?.clusterIP, + (s) => getServicePortSearchValues(s) ) export function ServiceListPage() { From 83db3de13a08c462413865614c0451fa63ace6b7 Mon Sep 17 00:00:00 2001 From: Zzde Date: Sun, 19 Apr 2026 23:55:35 +0800 Subject: [PATCH 2/2] Update ui/src/lib/k8s.ts --- ui/src/lib/k8s.ts | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/ui/src/lib/k8s.ts b/ui/src/lib/k8s.ts index b22a92d7..7d2b5679 100644 --- a/ui/src/lib/k8s.ts +++ b/ui/src/lib/k8s.ts @@ -404,36 +404,12 @@ export function getServiceExternalIP(service: Service): string { /** Tokens used by the Services list search (name/type/IP + port / nodePort / targetPort). */ export function getServicePortSearchValues(service: Service): string[] { - const ports = service.spec?.ports ?? [] - const out: string[] = [] - for (const p of ports) { - const protocol = (p.protocol || 'TCP').toLowerCase() - if (p.port != null) { - out.push(String(p.port)) - out.push(`${p.port}/${protocol}`) - } - if (p.nodePort != null) { - out.push(String(p.nodePort)) - } - const tp = p.targetPort as unknown - if (tp !== undefined && tp !== null) { - if (typeof tp === 'number' || typeof tp === 'string') { - out.push(String(tp)) - } else if (typeof tp === 'object') { - const o = tp as { StrVal?: string; IntVal?: number } - if (o.StrVal != null) out.push(o.StrVal) - else if (o.IntVal != null) out.push(String(o.IntVal)) - } - } - if (p.port != null) { - if (p.nodePort != null) { - out.push(`${p.port}:${p.nodePort}/${p.protocol || 'TCP'}`) - } else { - out.push(`${p.port}/${p.protocol || 'TCP'}`) - } - } - } - return out + return (service.spec?.ports ?? []).map((port) => { + const protocol = (port.protocol ?? 'TCP').toLowerCase() + return port.nodePort != null + ? `${port.port}:${port.nodePort}/${protocol}` + : `${port.port}/${protocol}` + }) } // Helper function to check if pod has ready condition