Skip to content

Commit 6bf836d

Browse files
authored
fix(dashboard): show LoadBalancer external IP on the app Services tab (#3172)
## What this PR does For an application exposed with `external: true` (which creates a `type: LoadBalancer` Service), the app detail → **Services** tab showed the service Type and Cluster IP but not the external IP assigned by MetalLB — so there was no way to learn the connection address from the per-app view. The pre-1.4.0 dashboard showed this, so it read as a regression (reported in #2789). Root cause: `ServicesTab.tsx` queried Services with a spec-only local type (`{ type, clusterIP, ports }`) and never read `status.loadBalancer.ingress[]`. The data was already reachable — `ExternalIpsPage.tsx` renders it — so this was a wiring gap in the per-app tab, not missing data. Changes: - Add a `ServiceStatus` type and extend the `useK8sList` query to `K8sResource<ServiceSpec, ServiceStatus>`. - Add an **External IP** column: `ip ?? hostname ?? "Pending"` for `LoadBalancer` services, `—` otherwise — mirroring `ExternalIpsPage`. - Add a co-located regression test (`ServicesTab.test.tsx`) covering the IP, hostname→Pending fallback, and the ClusterIP no-external case. Verified: `pnpm typecheck` clean, `pnpm test` green (320 tests, incl. 3 new), `eslint` clean on the changed files. Fixes #3111 ### Screenshots <img width="1220" height="572" alt="Снимок экрана 2026-07-02 в 14 12 11" src="https://github.com/user-attachments/assets/82cd1da8-ff81-4b95-a6bf-18729b6c85c7" /> ### Release note ```release-note fix(dashboard): show the external LoadBalancer IP on the per-app Services tab ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an **External IP** column to the service details view. * Load balancer services now show the external IP or hostname when available. * **Bug Fixes** * Fixed the external IP display for load balancer services so it no longer misses valid IPs. * Improved fallback behavior by showing **Pending** when no external endpoint is assigned. * Non-load balancer services now show an em dash instead of misleading external IP text. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents a162681 + bf75d32 commit 6bf836d

2 files changed

Lines changed: 133 additions & 22 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { describe, it, expect, vi, afterEach } from "vitest"
2+
import { screen, waitFor, cleanup } from "@testing-library/react"
3+
import { K8sClient } from "@cozystack/k8s-client"
4+
import { renderWithK8sProvider } from "../../test-utils/render.tsx"
5+
import { ServicesTab } from "./ServicesTab.tsx"
6+
import type { ApplicationDefinition, ApplicationInstance } from "@cozystack/types"
7+
8+
const ad: ApplicationDefinition = {
9+
apiVersion: "cozystack.io/v1alpha1",
10+
kind: "ApplicationDefinition",
11+
metadata: { name: "http-cache" },
12+
spec: {
13+
application: {
14+
kind: "HTTPCache",
15+
plural: "httpcaches",
16+
singular: "http-cache",
17+
openAPISchema: "{}",
18+
},
19+
},
20+
}
21+
22+
const instance: ApplicationInstance = {
23+
apiVersion: "apps.cozystack.io/v1alpha1",
24+
kind: "HTTPCache",
25+
metadata: { name: "demo", namespace: "tenant-root" },
26+
}
27+
28+
function makeClient(items: unknown[]) {
29+
const client = new K8sClient()
30+
vi.spyOn(client, "list").mockResolvedValue({
31+
apiVersion: "v1",
32+
kind: "List",
33+
metadata: {},
34+
items,
35+
})
36+
vi.spyOn(client, "watch").mockReturnValue(() => {})
37+
return client
38+
}
39+
40+
afterEach(() => {
41+
cleanup()
42+
vi.restoreAllMocks()
43+
})
44+
45+
describe("ServicesTab external IP", () => {
46+
it("shows the LoadBalancer external IP from status, not just the cluster IP", async () => {
47+
const client = makeClient([
48+
{
49+
metadata: { name: "demo", namespace: "tenant-root" },
50+
spec: { type: "LoadBalancer", clusterIP: "10.96.1.2", ports: [{ port: 80 }] },
51+
status: { loadBalancer: { ingress: [{ ip: "192.0.2.50" }] } },
52+
},
53+
])
54+
renderWithK8sProvider(<ServicesTab ad={ad} instance={instance} />, { client })
55+
56+
// Regression for #3111: the assigned MetalLB IP must be surfaced, not hidden.
57+
await waitFor(() => expect(screen.getByText("192.0.2.50")).toBeInTheDocument())
58+
expect(screen.getByText("10.96.1.2")).toBeInTheDocument()
59+
})
60+
61+
it("falls back to the hostname, then to Pending, for a LoadBalancer", async () => {
62+
const client = makeClient([
63+
{
64+
metadata: { name: "by-host", namespace: "tenant-root" },
65+
spec: { type: "LoadBalancer", clusterIP: "10.96.1.3", ports: [{ port: 443 }] },
66+
status: { loadBalancer: { ingress: [{ hostname: "lb.example.com" }] } },
67+
},
68+
{
69+
metadata: { name: "pending", namespace: "tenant-root" },
70+
spec: { type: "LoadBalancer", clusterIP: "10.96.1.4", ports: [{ port: 443 }] },
71+
status: {},
72+
},
73+
])
74+
renderWithK8sProvider(<ServicesTab ad={ad} instance={instance} />, { client })
75+
76+
await waitFor(() => expect(screen.getByText("lb.example.com")).toBeInTheDocument())
77+
expect(screen.getByText("Pending")).toBeInTheDocument()
78+
})
79+
80+
it("does not show an external IP for a ClusterIP service", async () => {
81+
const client = makeClient([
82+
{
83+
metadata: { name: "internal", namespace: "tenant-root" },
84+
spec: { type: "ClusterIP", clusterIP: "10.96.1.5", ports: [{ port: 8080 }] },
85+
},
86+
])
87+
renderWithK8sProvider(<ServicesTab ad={ad} instance={instance} />, { client })
88+
89+
await waitFor(() => expect(screen.getByText("internal")).toBeInTheDocument())
90+
expect(screen.queryByText("Pending")).not.toBeInTheDocument()
91+
// The External IP cell renders an em dash for non-LoadBalancer services.
92+
expect(screen.getAllByText("—").length).toBeGreaterThan(0)
93+
})
94+
})

‎packages/system/dashboard/images/console/apps/console/src/routes/detail/ServicesTab.tsx‎

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ interface ServiceSpec {
1010
ports?: { port: number; protocol?: string; name?: string }[]
1111
}
1212

13+
interface ServiceStatus {
14+
loadBalancer?: {
15+
ingress?: { ip?: string; hostname?: string }[]
16+
}
17+
}
18+
1319
export function ServicesTab({
1420
ad,
1521
instance,
@@ -18,7 +24,7 @@ export function ServicesTab({
1824
instance: ApplicationInstance
1925
}) {
2026
const ns = instance.metadata.namespace ?? ""
21-
const { data, isLoading } = useK8sList<K8sResource<ServiceSpec>>(
27+
const { data, isLoading } = useK8sList<K8sResource<ServiceSpec, ServiceStatus>>(
2228
{ apiGroup: "", apiVersion: "v1", plural: "services", namespace: ns },
2329
{ labelSelector: appInstanceLabel(ad, instance) },
2430
)
@@ -40,32 +46,43 @@ export function ServicesTab({
4046
<th className="px-4 py-3">Name</th>
4147
<th className="px-4 py-3">Type</th>
4248
<th className="px-4 py-3">Cluster IP</th>
49+
<th className="px-4 py-3">External IP</th>
4350
<th className="px-4 py-3">Ports</th>
4451
<th className="px-4 py-3">Age</th>
4552
</tr>
4653
</thead>
4754
<tbody className="divide-y divide-slate-100">
48-
{items.map((svc) => (
49-
<tr key={svc.metadata.name} className="hover:bg-slate-50">
50-
<td className="px-4 py-3 font-mono text-xs text-slate-800">
51-
{svc.metadata.name}
52-
</td>
53-
<td className="px-4 py-3 text-slate-700">
54-
{svc.spec?.type ?? "ClusterIP"}
55-
</td>
56-
<td className="px-4 py-3 font-mono text-xs text-slate-600">
57-
{svc.spec?.clusterIP ?? "—"}
58-
</td>
59-
<td className="px-4 py-3 text-slate-700">
60-
{svc.spec?.ports
61-
?.map((p) => `${p.port}/${p.protocol ?? "TCP"}`)
62-
.join(", ") ?? "—"}
63-
</td>
64-
<td className="px-4 py-3 tabular-nums text-slate-500">
65-
{formatAge(svc.metadata.creationTimestamp)}
66-
</td>
67-
</tr>
68-
))}
55+
{items.map((svc) => {
56+
const lb = svc.status?.loadBalancer?.ingress?.[0]
57+
const external =
58+
svc.spec?.type === "LoadBalancer"
59+
? (lb?.ip ?? lb?.hostname ?? "Pending")
60+
: "—"
61+
return (
62+
<tr key={svc.metadata.name} className="hover:bg-slate-50">
63+
<td className="px-4 py-3 font-mono text-xs text-slate-800">
64+
{svc.metadata.name}
65+
</td>
66+
<td className="px-4 py-3 text-slate-700">
67+
{svc.spec?.type ?? "ClusterIP"}
68+
</td>
69+
<td className="px-4 py-3 font-mono text-xs text-slate-600">
70+
{svc.spec?.clusterIP ?? "—"}
71+
</td>
72+
<td className="px-4 py-3 font-mono text-xs text-slate-700">
73+
{external}
74+
</td>
75+
<td className="px-4 py-3 text-slate-700">
76+
{svc.spec?.ports
77+
?.map((p) => `${p.port}/${p.protocol ?? "TCP"}`)
78+
.join(", ") ?? "—"}
79+
</td>
80+
<td className="px-4 py-3 tabular-nums text-slate-500">
81+
{formatAge(svc.metadata.creationTimestamp)}
82+
</td>
83+
</tr>
84+
)
85+
})}
6986
</tbody>
7087
</table>
7188
)}

0 commit comments

Comments
 (0)