Skip to content

Commit 5d42786

Browse files
committed
feat(dashboard): show a connection hostname for LoadBalancer services
Users who provision a service through the dashboard had no hostname to connect to: the Services tab showed only the raw LoadBalancer IP, while the pre-1.4.0 UI composed <service>.<root host> for every Service. Render <service>.<suffix> under the External IP of every LoadBalancer Service (also while the IP is still Pending), and nothing for ClusterIP Services. The suffix is config.json serviceDomain, set by the platform value publishing.serviceDomain. There is deliberately no fallback: the app charts fix their external name as <release>.<tenant host> while the LoadBalancer Services are named <release>-external-write and similar, so a name derived from the tenant apex would match neither the DNS nor the certificate. Without a configured suffix nothing is rendered. Runtime config previously reached only the Shell as a prop; it is now published through AppConfigContext and read from there by the Shell and the Services tab alike, so a single test on the rendered version pins the wiring. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent c88f511 commit 5d42786

5 files changed

Lines changed: 102 additions & 17 deletions

File tree

‎packages/system/dashboard/images/console/apps/console/src/App.routing.test.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,18 @@ describe("default landing", () => {
7171
).toBeTruthy()
7272
})
7373
})
74+
75+
describe("runtime config", () => {
76+
it("reaches the tree through AppConfigContext", async () => {
77+
const client = makeClient()
78+
renderWithK8sProvider(<App config={{ version: "v0.0.0-test" }} />, {
79+
client,
80+
initialRoute: "/",
81+
})
82+
83+
// The header prints config.version verbatim, so it is the cheapest proof
84+
// that the loaded config is published to the whole tree (routes read the
85+
// same context for serviceDomain).
86+
expect(await screen.findByText("v0.0.0-test")).toBeTruthy()
87+
})
88+
})

‎packages/system/dashboard/images/console/apps/console/src/App.tsx‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ import {
1414
import type { HeaderTab } from "@cozystack/ui"
1515
import { CommandPaletteProvider, useCommandPalette } from "./components/command-palette/command-palette-provider.tsx"
1616
import { CommandPalette } from "./components/command-palette/command-palette.tsx"
17-
import type { AppConfig } from "./lib/config.ts"
17+
import { AppConfigContext, useAppConfig, type AppConfig } from "./lib/config.ts"
1818
import { DEFAULT_LANDING_PATH } from "./lib/portal.ts"
1919

20-
interface ShellProps {
21-
config: AppConfig
22-
username?: string
23-
}
24-
25-
function Shell({ config, username }: ShellProps) {
20+
function Shell({ username }: { username?: string }) {
21+
const config = useAppConfig()
2622
const { pathname } = useLocation()
2723
const inMarketplace = pathname.startsWith("/marketplace")
2824
const inAdmin = pathname.startsWith("/admin")
@@ -72,10 +68,12 @@ export interface AppProps {
7268

7369
export default function App({ config = {}, username }: AppProps) {
7470
return (
75-
<TenantProvider>
76-
<CommandPaletteProvider>
77-
<Shell config={config} username={username} />
78-
</CommandPaletteProvider>
79-
</TenantProvider>
71+
<AppConfigContext.Provider value={config}>
72+
<TenantProvider>
73+
<CommandPaletteProvider>
74+
<Shell username={username} />
75+
</CommandPaletteProvider>
76+
</TenantProvider>
77+
</AppConfigContext.Provider>
8078
)
8179
}

‎packages/system/dashboard/images/console/apps/console/src/lib/config.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createContext, useContext } from "react"
2+
13
export interface AppConfig {
24
titleText?: string
35
footerText?: string
@@ -9,6 +11,16 @@ export interface AppConfig {
911
// than the rc version baked into the bundle at build. Falls back to the
1012
// build-time VITE_APP_VERSION when absent.
1113
version?: string
14+
// DNS suffix shown after a LoadBalancer Service name on the Services tab.
15+
// Absent when the platform leaves publishing.serviceDomain empty; the tab
16+
// then shows no hostname.
17+
serviceDomain?: string
18+
}
19+
20+
export const AppConfigContext = createContext<AppConfig>({})
21+
22+
export function useAppConfig(): AppConfig {
23+
return useContext(AppConfigContext)
1224
}
1325

1426
const CONFIG_NAMESPACE = "cozy-dashboard"

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, afterEach } from "vitest"
22
import { screen, waitFor, cleanup } from "@testing-library/react"
33
import { K8sClient } from "@cozystack/k8s-client"
44
import { renderWithK8sProvider } from "../../test-utils/render.tsx"
5+
import { AppConfigContext } from "../../lib/config.ts"
56
import { ServicesTab } from "./ServicesTab.tsx"
67
import type { ApplicationDefinition, ApplicationInstance } from "@cozystack/types"
78

@@ -92,3 +93,53 @@ describe("ServicesTab external IP", () => {
9293
expect(screen.getAllByText("—").length).toBeGreaterThan(0)
9394
})
9495
})
96+
97+
describe("ServicesTab connection hostname", () => {
98+
const lbService = {
99+
metadata: { name: "demo", namespace: "tenant-root" },
100+
spec: { type: "LoadBalancer", clusterIP: "10.96.1.2", ports: [{ port: 5432 }] },
101+
status: { loadBalancer: { ingress: [{ ip: "192.0.2.50" }] } },
102+
}
103+
104+
it("renders <service>.<serviceDomain> for a LoadBalancer, even while the IP is pending", async () => {
105+
const client = makeClient([lbService, { ...lbService, metadata: { name: "late" }, status: {} }])
106+
renderWithK8sProvider(
107+
<AppConfigContext.Provider value={{ serviceDomain: "svc.example.org" }}>
108+
<ServicesTab ad={ad} instance={instance} />
109+
</AppConfigContext.Provider>,
110+
{ client },
111+
)
112+
113+
await waitFor(() => expect(screen.getByText("demo.svc.example.org")).toBeInTheDocument())
114+
expect(screen.getByText("late.svc.example.org")).toBeInTheDocument()
115+
expect(screen.getByText("Pending")).toBeInTheDocument()
116+
})
117+
118+
it("renders no hostname when the platform configured no serviceDomain", async () => {
119+
// Nothing in the platform publishes DNS for a guessed name, so the tab
120+
// must not invent one: neither "demo." nor a tenant-derived suffix.
121+
const client = makeClient([lbService])
122+
renderWithK8sProvider(<ServicesTab ad={ad} instance={instance} />, { client })
123+
124+
await waitFor(() => expect(screen.getByText("192.0.2.50")).toBeInTheDocument())
125+
expect(screen.queryByText(/^demo\./)).not.toBeInTheDocument()
126+
})
127+
128+
it("renders no hostname for a ClusterIP service", async () => {
129+
const client = makeClient([
130+
{
131+
metadata: { name: "internal", namespace: "tenant-root" },
132+
spec: { type: "ClusterIP", clusterIP: "10.96.1.5", ports: [{ port: 8080 }] },
133+
},
134+
])
135+
renderWithK8sProvider(
136+
<AppConfigContext.Provider value={{ serviceDomain: "svc.example.org" }}>
137+
<ServicesTab ad={ad} instance={instance} />
138+
</AppConfigContext.Provider>,
139+
{ client },
140+
)
141+
142+
await waitFor(() => expect(screen.getByText("internal")).toBeInTheDocument())
143+
expect(screen.queryByText(/^internal\./)).not.toBeInTheDocument()
144+
})
145+
})

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Section, Spinner } from "@cozystack/ui"
33
import type { ApplicationDefinition, ApplicationInstance } from "@cozystack/types"
44
import { appInstanceLabel } from "../../lib/labels.ts"
55
import { formatAge } from "../../lib/status.ts"
6+
import { useAppConfig } from "../../lib/config.ts"
67

78
interface ServiceSpec {
89
type?: string
@@ -29,6 +30,7 @@ export function ServicesTab({
2930
{ labelSelector: appInstanceLabel(ad, instance) },
3031
)
3132
const items = data?.items ?? []
33+
const { serviceDomain } = useAppConfig()
3234

3335
return (
3436
<div className="p-6">
@@ -53,11 +55,17 @@ export function ServicesTab({
5355
</thead>
5456
<tbody className="divide-y divide-slate-100">
5557
{items.map((svc) => {
58+
const isLoadBalancer = svc.spec?.type === "LoadBalancer"
5659
const lb = svc.status?.loadBalancer?.ingress?.[0]
57-
const external =
58-
svc.spec?.type === "LoadBalancer"
59-
? (lb?.ip ?? lb?.hostname ?? "Pending")
60-
: "—"
60+
const external = isLoadBalancer
61+
? (lb?.ip ?? lb?.hostname ?? "Pending")
62+
: "—"
63+
// Only when the operator configured a suffix: nothing in the
64+
// platform publishes DNS for these names, so no fallback.
65+
const hostname =
66+
isLoadBalancer && serviceDomain
67+
? `${svc.metadata.name}.${serviceDomain}`
68+
: undefined
6169
return (
6270
<tr key={svc.metadata.name} className="hover:bg-slate-50">
6371
<td className="px-4 py-3 font-mono text-xs text-slate-800">
@@ -70,7 +78,8 @@ export function ServicesTab({
7078
{svc.spec?.clusterIP ?? "—"}
7179
</td>
7280
<td className="px-4 py-3 font-mono text-xs text-slate-700">
73-
{external}
81+
<div>{external}</div>
82+
{hostname && <div className="text-slate-500">{hostname}</div>}
7483
</td>
7584
<td className="px-4 py-3 text-slate-700">
7685
{svc.spec?.ports

0 commit comments

Comments
 (0)