Skip to content

Commit c586506

Browse files
authored
feat(dashboard): show a connection hostname for LoadBalancer services (#4035)
## What this PR does The Services tab on the application page shows a connection hostname under the External IP of every LoadBalancer Service, as `<service-name>.<suffix>`, also while the IP is still Pending. ClusterIP Services get nothing. The suffix is a new platform value, `publishing.serviceDomain`. It travels the same path as `cluster-domain` and `branding`: `_cluster.service-domain` in the cozystack-values Secret (leading and trailing dots stripped there), then `serviceDomain` in the dashboard's `config.json`, written only when non-empty. Empty by default, and with it empty the tab shows no hostname. There is deliberately no fallback to a tenant-derived name: the app charts certify `<release>.<tenant host>` while the LoadBalancer Services are named `<release>-external-write` and similar, so a name built from the tenant apex would match neither DNS nor the certificate. Showing nothing beats showing a name nobody publishes. The value is display-only. Nothing in the platform creates DNS records for it. Set it when your DNS already resolves `<service-name>.<serviceDomain>` to that Service's LoadBalancer IP, external-dns with a matching fqdn template for example. A CoreDNS `k8s_external` zone does not fit, it answers `<service>.<namespace>.<zone>`. The shown name is not the one in the app certificates, so a TLS client may see a SAN mismatch unless DNS and certificates are aligned by the operator, and two tenants with a release of the same name get the same hostname. The values comment says all of this. Left for follow-ups: reading `external-dns.alpha.kubernetes.io/hostname` from the Service as the first source (only the opensearch chart stamps it today), and a per-Service override annotation. Parked from review, not blocking: the Admin External IPs page does not show the hostname yet, the column header still says "External IP", and surrounding whitespace in the value is not trimmed. Closes #3112 ### Screenshots <img width="1200" height="360" alt="services-tab" src="https://github.com/user-attachments/assets/01e1f3e0-836e-41cc-b916-f675b62580cd" /> ### Downstream repositories `packages/core/platform/values.yaml` gains a key, so the hand-written table in `content/en/docs/next/operations/configuration/platform-package.md` on cozystack/website needs a row for `publishing.serviceDomain`. I will open that website PR once this one merges. No other repository restates this key: ansible-cozystack passes a fixed list of `publishing.*` keys that does not include it, and the terraform provider models app schemas, not platform values. - [ ] No downstream repository is affected by this change - [x] [cozystack/website](https://github.com/cozystack/website) - follow-up: a `publishing.serviceDomain` row in the platform-package table, opened after this PR merges - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: ### Release note ```release-note feat(dashboard): the application Services tab shows `<service>.<suffix>` under the external IP of LoadBalancer services when the new platform value `publishing.serviceDomain` is set ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an optional service domain setting for displaying LoadBalancer service hostnames in the dashboard. - When configured, services display hostnames in the format `<service-name>.<service-domain>` alongside external IP information. - Hostnames are shown only for LoadBalancer services and remain hidden when no service domain is configured. - Dashboard configuration now receives the service domain setting automatically, including support for custom domain formatting. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 52c74be + 97fa2a6 commit c586506

10 files changed

Lines changed: 220 additions & 17 deletions

File tree

‎packages/core/platform/templates/apps.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ stringData:
255255
monitoring-enabled: {{ dig "rootEnabled" true (.Values.monitoring | default dict) | quote }}
256256
cluster-domain: {{ .Values.networking.clusterDomain | quote }}
257257
api-server-endpoint: {{ .Values.publishing.apiServerEndpoint | quote }}
258+
{{- /* Display-only DNS suffix for the dashboard's Services tab
259+
(<service>.<suffix>). Empty -> the console shows no hostname. */}}
260+
service-domain: {{ .Values.publishing.serviceDomain | default "" | toString | trimAll "." | quote }}
258261
{{- with .Values.branding }}
259262
branding:
260263
{{- . | toYaml | nindent 8 }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
suite: apps.yaml publishing.serviceDomain → _cluster wiring
2+
templates:
3+
- templates/apps.yaml
4+
5+
release:
6+
name: cozy-platform
7+
namespace: cozy-system
8+
9+
# publishing.serviceDomain is the DNS suffix the dashboard appends to a
10+
# LoadBalancer Service name on the application Services tab. It reaches the
11+
# dashboard chart through _cluster.service-domain in the cozystack-values
12+
# Secret (the same path cluster-domain and branding travel). Pin both
13+
# directions: the empty default, which the console turns into "show no
14+
# hostname", and a configured value landing verbatim. Without these a refactor
15+
# of the values map could drop the key and the dashboard would silently stop
16+
# showing hostnames on every cluster that configured one.
17+
18+
tests:
19+
- it: writes an empty service-domain by default
20+
asserts:
21+
- matchRegex:
22+
path: stringData["values.yaml"]
23+
pattern: '(?m)^\s*service-domain:\s*""'
24+
25+
- it: writes the service-domain when publishing.serviceDomain is set
26+
set:
27+
publishing.serviceDomain: svc.example.org
28+
asserts:
29+
- matchRegex:
30+
path: stringData["values.yaml"]
31+
pattern: '(?m)^\s*service-domain:\s*"svc\.example\.org"'
32+
33+
# The console joins "<service>.<suffix>" verbatim, so a leading or trailing
34+
# dot from the operator would render "demo..svc.example.org." — strip them
35+
# here, the single place every consumer reads from.
36+
- it: strips leading and trailing dots from publishing.serviceDomain
37+
set:
38+
publishing.serviceDomain: .svc.example.org.
39+
asserts:
40+
- matchRegex:
41+
path: stringData["values.yaml"]
42+
pattern: '(?m)^\s*service-domain:\s*"svc\.example\.org"'
43+
44+
# An unquoted scalar in the operator's values arrives as a number, and
45+
# trimAll on a float64 aborts the whole platform render. Coerce first.
46+
- it: renders an unquoted numeric publishing.serviceDomain instead of failing
47+
set:
48+
publishing.serviceDomain: 123
49+
asserts:
50+
- matchRegex:
51+
path: stringData["values.yaml"]
52+
pattern: '(?m)^\s*service-domain:\s*"123"'

‎packages/core/platform/values.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ publishing:
193193
# value requires recreating that Service once (the chart fails early with the
194194
# exact command).
195195
loadBalancerClass: ""
196+
# DNS suffix the dashboard appends to the name of a LoadBalancer Service on
197+
# the application Services tab, shown under the external IP as
198+
# `<service-name>.<serviceDomain>` (e.g. demo-external-write.svc.example.org
199+
# for a postgres release named demo). Display-only: nothing in the platform
200+
# creates DNS records for it. Set it only when your DNS already resolves
201+
# exactly that name to the Service's LoadBalancer IP, e.g. external-dns with
202+
# a matching fqdn template. A CoreDNS k8s_external zone does not fit: it
203+
# answers <service>.<namespace>.<zone>, which this suffix cannot express.
204+
# This is not the `<release>.<tenant host>` name the app charts put into
205+
# their certificates, so a TLS client may see a SAN mismatch unless DNS and
206+
# certificates are aligned by the operator. The suffix is cluster-wide, so
207+
# two tenants with a release of the same name get the same hostname.
208+
# Empty (the default) shows no hostname.
209+
serviceDomain: ""
196210
# Enable PROXY-protocol on the host ingress-nginx and auto-deploy
197211
# ouroboros (system/ouroboros) to fix the resulting hairpin-NAT
198212
# problem (intra-cluster traffic to the cluster's own public hostnames

‎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
@@ -96,3 +96,18 @@ describe("default landing", () => {
9696
expect(screen.getByTestId("location").textContent).toBe("/admin/taps")
9797
})
9898
})
99+
100+
describe("runtime config", () => {
101+
it("reaches the tree through AppConfigContext", async () => {
102+
const client = makeClient()
103+
renderWithK8sProvider(<App config={{ version: "v0.0.0-test" }} />, {
104+
client,
105+
initialRoute: "/",
106+
})
107+
108+
// The header prints config.version verbatim, so it is the cheapest proof
109+
// that the loaded config is published to the whole tree (routes read the
110+
// same context for serviceDomain).
111+
expect(await screen.findByText("v0.0.0-test")).toBeTruthy()
112+
})
113+
})

‎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

‎packages/system/dashboard/templates/configmap.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
and the vX.Y.Z release tags, rather than stripping the leading v. */}}
2222
{{- $_ := set $config "version" $tag }}
2323
{{- end }}
24+
{{- /* Omitted when empty: the console treats a missing key as "show no
25+
hostname", so an empty string must not reach config.json. */}}
26+
{{- with index .Values._cluster "service-domain" }}
27+
{{- $_ := set $config "serviceDomain" . }}
28+
{{- end }}
2429
apiVersion: v1
2530
kind: ConfigMap
2631
metadata:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
suite: console config.json service-domain wiring
2+
templates:
3+
- templates/configmap.yaml
4+
5+
release:
6+
name: dashboard
7+
namespace: cozy-dashboard
8+
9+
# The console reads config.json once at startup and treats a missing
10+
# serviceDomain as "show no hostname". The chart therefore omits
11+
# the key when _cluster.service-domain is unset or empty, and copies the value
12+
# verbatim when set. Pin all three, next to the existing branding merge, so a
13+
# refactor of the $config assembly cannot drop the key or start shipping an
14+
# empty string the console would have to special-case.
15+
16+
tests:
17+
- it: omits serviceDomain when service-domain is unset
18+
set:
19+
_cluster:
20+
root-host: example.org
21+
asserts:
22+
- notMatchRegex:
23+
path: data["config.json"]
24+
pattern: serviceDomain
25+
26+
- it: omits serviceDomain when service-domain is empty
27+
set:
28+
_cluster:
29+
root-host: example.org
30+
service-domain: ""
31+
asserts:
32+
- notMatchRegex:
33+
path: data["config.json"]
34+
pattern: serviceDomain
35+
36+
- it: writes serviceDomain when service-domain is set
37+
set:
38+
_cluster:
39+
root-host: example.org
40+
service-domain: svc.example.org
41+
asserts:
42+
- matchRegex:
43+
path: data["config.json"]
44+
pattern: '"serviceDomain":"svc\.example\.org"'

0 commit comments

Comments
 (0)