@skyhook-io/radar-app 1.21.8 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/App.tsx +14 -0
- package/src/api/client.ts +6 -0
- package/src/api/radarFeatures.ts +4 -0
- package/src/api/traefik.ts +33 -0
- package/src/api/traffic.ts +1 -0
- package/src/components/CloudFunnelButton.test.tsx +39 -1
- package/src/components/CloudFunnelButton.tsx +10 -3
- package/src/components/cnpg/CNPGOverview.test.tsx +75 -3
- package/src/components/cnpg/CNPGOverview.tsx +62 -4
- package/src/components/home/NetworkPolicyCoverageCard.test.tsx +37 -0
- package/src/components/home/NetworkPolicyCoverageCard.tsx +26 -2
- package/src/components/resources/renderers/TraefikIngressRouteRenderer.test.tsx +23 -0
- package/src/components/resources/renderers/TraefikIngressRouteRenderer.tsx +23 -0
- package/src/components/resources/renderers/TraefikMiddlewareRenderer.test.tsx +23 -0
- package/src/components/resources/renderers/TraefikMiddlewareRenderer.tsx +29 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +23 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +5 -4
- package/src/components/traffic/TrafficFilterSidebar.test.tsx +14 -0
- package/src/components/traffic/TrafficFilterSidebar.tsx +17 -0
- package/src/components/traffic/TrafficFlowList.tsx +5 -5
- package/src/components/traffic/TrafficGraph.test.tsx +11 -0
- package/src/components/traffic/TrafficGraph.tsx +31 -19
- package/src/components/traffic/TrafficView.tsx +17 -6
- package/src/components/traffic/traffic-export.test.ts +8 -0
- package/src/components/traffic/traffic-export.ts +7 -4
- package/src/components/traffic/trafficFilters.test.ts +51 -1
- package/src/components/traffic/trafficFilters.ts +39 -11
- package/src/components/ui/command-items-crd.test.tsx +23 -8
- package/src/components/whats-new/releaseNotes.ts +75 -1
- package/src/integrations/resourceHosts.test.tsx +1 -1
- package/src/integrations/resourceHosts.tsx +3 -0
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -1164,6 +1164,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1164
1164
|
}>({ changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null })
|
|
1165
1165
|
const cnpgInvalidationPendingRef = useRef(false)
|
|
1166
1166
|
const veleroInvalidationPendingRef = useRef(false)
|
|
1167
|
+
// Traefik route facts scan every visible IngressRoute per request, so an open
|
|
1168
|
+
// drawer refreshes at most once per batch of this length.
|
|
1169
|
+
const traefikInvalidationRef = useRef<{ timer: number | null }>({ timer: null })
|
|
1167
1170
|
const slowInvalidationRef = useRef<{
|
|
1168
1171
|
updatedKinds: Set<string> // update-only churn → throttled list + dashboard
|
|
1169
1172
|
gitopsRowsChanged: boolean // Argo/Flux row and source kinds → GitOps table rows
|
|
@@ -1265,6 +1268,15 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1265
1268
|
}, 3000)
|
|
1266
1269
|
}
|
|
1267
1270
|
|
|
1271
|
+
// Traefik route facts join routes, Middlewares, Services, Pods and Secrets;
|
|
1272
|
+
// only an open drawer's query refetches.
|
|
1273
|
+
if (traefikInvalidationRef.current.timer === null) {
|
|
1274
|
+
traefikInvalidationRef.current.timer = window.setTimeout(() => {
|
|
1275
|
+
traefikInvalidationRef.current = { timer: null }
|
|
1276
|
+
queryClient.invalidateQueries({ queryKey: ['traefik'] })
|
|
1277
|
+
}, 15000)
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1268
1280
|
// SLOW tier — throttle expensive status churn. Workload membership changes
|
|
1269
1281
|
// also pass through here so the Applications refetch lands after its cache TTL.
|
|
1270
1282
|
if ((!structural || applicationWorkload || gitops.rows || gitops.counts) && slow.timer === null) {
|
|
@@ -1292,6 +1304,8 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1292
1304
|
if (fastInvalidationRef.current.timer !== null) clearTimeout(fastInvalidationRef.current.timer)
|
|
1293
1305
|
if (slowInvalidationRef.current.timer !== null) clearTimeout(slowInvalidationRef.current.timer)
|
|
1294
1306
|
if (timelineInvalidationRef.current.timer !== null) clearTimeout(timelineInvalidationRef.current.timer)
|
|
1307
|
+
if (traefikInvalidationRef.current.timer !== null) clearTimeout(traefikInvalidationRef.current.timer)
|
|
1308
|
+
traefikInvalidationRef.current = { timer: null }
|
|
1295
1309
|
fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
|
|
1296
1310
|
slowInvalidationRef.current = { updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null }
|
|
1297
1311
|
timelineInvalidationRef.current = { timer: null }
|
package/src/api/client.ts
CHANGED
|
@@ -682,6 +682,9 @@ export interface DashboardNetworkPolicyCoverage {
|
|
|
682
682
|
coveredWorkloads: number;
|
|
683
683
|
coveredWorkloadsIfStaged?: number;
|
|
684
684
|
totalWorkloads: number;
|
|
685
|
+
// Workloads left out of totalWorkloads.
|
|
686
|
+
ignoredNamespaceWorkloads?: number;
|
|
687
|
+
hostNetworkWorkloads?: number;
|
|
685
688
|
}
|
|
686
689
|
|
|
687
690
|
export interface DashboardGitOpsControllers {
|
|
@@ -2616,6 +2619,9 @@ export interface CloudConnectSelf {
|
|
|
2616
2619
|
namespace?: string
|
|
2617
2620
|
name: string
|
|
2618
2621
|
}
|
|
2622
|
+
// 'nkp' when Nutanix NKP manages this install: wizardUrl then opens Radar
|
|
2623
|
+
// Cloud's NKP steps. Older Radar omits it.
|
|
2624
|
+
platform?: 'nkp'
|
|
2619
2625
|
wizardUrl?: string
|
|
2620
2626
|
}
|
|
2621
2627
|
|
package/src/api/radarFeatures.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface RadarFeatureSpec {
|
|
|
32
32
|
export const RADAR_FEATURES = {
|
|
33
33
|
datadogRightsizing: { label: 'Datadog-backed rightsizing', flag: 'datadogRightsizing', flagShippedWithEndpoint: true, requireAffirmativeSupport: true },
|
|
34
34
|
datadogAgentPresence: { label: 'Datadog Agent setup hints', flag: 'datadogAgentPresence', flagShippedWithEndpoint: true },
|
|
35
|
+
ownerAccessGrantReview: { label: 'Cloud Owner permission checks', flag: 'ownerAccessGrantReview', flagShippedWithEndpoint: true },
|
|
35
36
|
gitopsActionCapabilities: { label: 'GitOps action permission checks', flag: 'gitopsActionCapabilities', flagShippedWithEndpoint: true },
|
|
36
37
|
openobserveCollectorPresence: { label: 'OpenObserve collector setup hints', flag: 'openobserveCollectorPresence', flagShippedWithEndpoint: true },
|
|
37
38
|
openobserveLocalSetup: { label: 'OpenObserve connections in Settings', flag: 'openobserveLocalSetup', flagShippedWithEndpoint: true },
|
|
@@ -58,10 +59,13 @@ export const RADAR_FEATURES = {
|
|
|
58
59
|
substrateHealthMetrics: { label: 'Agent Substrate charts', flag: 'substrateHealthMetrics', flagShippedWithEndpoint: true, requireAffirmativeSupport: true },
|
|
59
60
|
cnpgWorkspace: { label: 'CloudNativePG views', flag: 'cnpgWorkspace', flagShippedWithEndpoint: true },
|
|
60
61
|
sealedSecretsController: { label: 'Sealed Secrets controller status', flag: 'sealedSecretsController', flagShippedWithEndpoint: true },
|
|
62
|
+
traefikRoutes: { label: 'Traefik routes', flag: 'traefikRoutes', flagShippedWithEndpoint: true },
|
|
61
63
|
sealedSecretsCert: { label: 'Sealed Secrets sealing certificate', flag: 'sealedSecretsCert', flagShippedWithEndpoint: true },
|
|
62
64
|
workflowStop: { label: 'Argo Workflow stop actions', flag: 'workflowStop', flagShippedWithEndpoint: true },
|
|
63
65
|
workflowTemplateSubmit: { label: 'Argo WorkflowTemplate submissions', flag: 'workflowTemplateSubmit', flagShippedWithEndpoint: true },
|
|
64
66
|
cnpgProtectionSetup: { label: 'CloudNativePG backup setup', flag: 'cnpgProtectionSetup', flagShippedWithEndpoint: true },
|
|
67
|
+
// Radars from v1.21.0 report these Checks in the workspace without advertising the flag.
|
|
68
|
+
cnpgPostureChecks: { label: 'CloudNativePG backup and availability counts', minimumVersion: 'v1.21.0', flag: 'cnpgPostureChecks' },
|
|
65
69
|
veleroWorkspace: { label: 'Velero views', flag: 'veleroWorkspace', flagShippedWithEndpoint: true },
|
|
66
70
|
veleroBackupNow: { label: 'Back up now', flag: 'veleroBackupNow', flagShippedWithEndpoint: true },
|
|
67
71
|
veleroSchedulePause: { label: 'Pause and resume Velero schedules', flag: 'veleroSchedulePause', flagShippedWithEndpoint: true },
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import type { TraefikRoutesResponse } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { fetchJSON, useRadarFeature } from './client'
|
|
4
|
+
import { shouldRetryRadarQuery } from './radarFeatures'
|
|
5
|
+
|
|
6
|
+
// One IngressRoute's rule facts, with usedBy for its middlewares.
|
|
7
|
+
// group tells the two Traefik API groups apart; an older Radar ignores it.
|
|
8
|
+
export function useTraefikRouteFacts(namespace: string, name: string, group: string) {
|
|
9
|
+
const { support, guard, gatedKey } = useRadarFeature('traefikRoutes')
|
|
10
|
+
const query = useQuery({
|
|
11
|
+
queryKey: ['traefik', 'routes', 'route', group, namespace, name, ...gatedKey],
|
|
12
|
+
queryFn: ({ signal }) => guard(() => fetchJSON<TraefikRoutesResponse>(`/traefik/routes?namespace=${encodeURIComponent(namespace)}&name=${encodeURIComponent(name)}&group=${encodeURIComponent(group)}`, signal)),
|
|
13
|
+
enabled: !!namespace && !!name && support !== 'unsupported',
|
|
14
|
+
staleTime: 30_000,
|
|
15
|
+
retry: shouldRetryRadarQuery,
|
|
16
|
+
})
|
|
17
|
+
return { ...query, support }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// The IngressRoute rules that use one Middleware (at most 200).
|
|
21
|
+
export function useTraefikMiddlewareUsers(namespace: string, name: string) {
|
|
22
|
+
const { support, guard, gatedKey } = useRadarFeature('traefikRoutes')
|
|
23
|
+
const query = useQuery({
|
|
24
|
+
queryKey: ['traefik', 'routes', 'middleware', namespace, name, ...gatedKey],
|
|
25
|
+
queryFn: ({ signal }) => guard(() => fetchJSON<TraefikRoutesResponse>(`/traefik/routes?middleware=${encodeURIComponent(`${namespace}/${name}`)}`, signal)),
|
|
26
|
+
enabled: !!namespace && !!name && support !== 'unsupported',
|
|
27
|
+
staleTime: 30_000,
|
|
28
|
+
// While IngressRoutes are still syncing the drawer shows nothing; ask again.
|
|
29
|
+
refetchInterval: (q) => (q.state.data?.coverage?.ingressroutes?.state === 'syncing' ? 3_000 : false),
|
|
30
|
+
retry: shouldRetryRadarQuery,
|
|
31
|
+
})
|
|
32
|
+
return { ...query, support }
|
|
33
|
+
}
|
package/src/api/traffic.ts
CHANGED
|
@@ -24,6 +24,8 @@ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
|
24
24
|
let root: Root
|
|
25
25
|
let client: QueryClient
|
|
26
26
|
let lane: 'driver' | 'wizard'
|
|
27
|
+
let deploymentMode: 'local' | 'in-cluster'
|
|
28
|
+
let selfBody: Record<string, unknown>
|
|
27
29
|
let discovery: { connected: { namespace: string; deployment: string; clusterUrl: string }[] }
|
|
28
30
|
let discoveryStatus: number
|
|
29
31
|
let flowState: 'idle' | 'awaiting_approval'
|
|
@@ -36,6 +38,8 @@ const requests: string[] = []
|
|
|
36
38
|
beforeEach(() => {
|
|
37
39
|
connection.state = 'connecting'
|
|
38
40
|
lane = 'driver'
|
|
41
|
+
deploymentMode = 'local'
|
|
42
|
+
selfBody = { ownership: 'unknown' }
|
|
39
43
|
discovery = { connected: [] }
|
|
40
44
|
discoveryStatus = 200
|
|
41
45
|
flowState = 'idle'
|
|
@@ -51,12 +55,13 @@ beforeEach(() => {
|
|
|
51
55
|
const url = new URL(input, 'http://localhost')
|
|
52
56
|
requests.push(url.pathname + url.search)
|
|
53
57
|
const bodies: Record<string, unknown> = {
|
|
54
|
-
'/api/capabilities': { cloudConnect: { lane, appUrl: 'https://cloud.example', apiUrl: 'https://cloud.example' }, deployment: { mode:
|
|
58
|
+
'/api/capabilities': { cloudConnect: { lane, appUrl: 'https://cloud.example', apiUrl: 'https://cloud.example' }, deployment: { mode: deploymentMode } },
|
|
55
59
|
'/api/cluster-info': { context: 'test-cluster' },
|
|
56
60
|
'/api/cloud/install/status': statusBody ?? { state: flowState },
|
|
57
61
|
'/api/cloud/install/discover': discoveryStatus === 200 ? discovery : { error: 'Discovery failed' },
|
|
58
62
|
'/api/cloud/install/prepare': { error: 'Not connected to cluster' },
|
|
59
63
|
'/api/connect/info': {},
|
|
64
|
+
'/api/cloud/connect/self': selfBody,
|
|
60
65
|
}
|
|
61
66
|
if (!(url.pathname in bodies)) throw new Error(`Unexpected request: ${input}`)
|
|
62
67
|
if (url.pathname.endsWith('/prepare') && prepareReply) return prepareReply.promise
|
|
@@ -178,6 +183,39 @@ describe('Cloud dialog connection availability', () => {
|
|
|
178
183
|
expect(requests).not.toContain('/api/cloud/install/discover')
|
|
179
184
|
})
|
|
180
185
|
|
|
186
|
+
it('shows the NKP steps on NKP even when Radar cannot tell how it was installed', async () => {
|
|
187
|
+
lane = 'wizard'
|
|
188
|
+
deploymentMode = 'in-cluster'
|
|
189
|
+
connection.state = 'connected'
|
|
190
|
+
const nkpUrl = 'https://cloud.example/install?clusters=many&platform=nkp&utm_content=wizard-install-link-nkp-install'
|
|
191
|
+
selfBody = { ownership: 'unknown', platform: 'nkp', wizardUrl: nkpUrl }
|
|
192
|
+
await openDialog()
|
|
193
|
+
await until(() => expect(document.body.textContent).toContain('NKP manages this Radar'))
|
|
194
|
+
const link = Array.from(document.querySelectorAll('a')).find(element => element.textContent === 'Connect your NKP workspace')!
|
|
195
|
+
expect(link.href).toBe(nkpUrl)
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('sends an NKP-managed install to the NKP steps without asking for a repository change', async () => {
|
|
199
|
+
lane = 'wizard'
|
|
200
|
+
deploymentMode = 'in-cluster'
|
|
201
|
+
connection.state = 'connected'
|
|
202
|
+
const nkpUrl = 'https://cloud.example/install?clusters=many&platform=nkp&utm_content=wizard-install-link-nkp-install'
|
|
203
|
+
selfBody = {
|
|
204
|
+
ownership: 'gitops',
|
|
205
|
+
namespace: 'ws',
|
|
206
|
+
release: 'ws-radar',
|
|
207
|
+
controller: 'HelmRelease ws/radar',
|
|
208
|
+
platform: 'nkp',
|
|
209
|
+
wizardUrl: nkpUrl,
|
|
210
|
+
}
|
|
211
|
+
await openDialog()
|
|
212
|
+
await until(() => expect(document.body.textContent).toContain('NKP manages this Radar'))
|
|
213
|
+
expect(document.body.textContent).toContain("paste into the Radar app's configuration in NKP")
|
|
214
|
+
expect(document.body.textContent).not.toContain('values change in your repository')
|
|
215
|
+
const link = Array.from(document.querySelectorAll('a')).find(element => element.textContent === 'Connect your NKP workspace')!
|
|
216
|
+
expect(link.href).toBe(nkpUrl)
|
|
217
|
+
})
|
|
218
|
+
|
|
181
219
|
it('keeps an active server-owned install visible even while disconnected', async () => {
|
|
182
220
|
connection.state = 'disconnected'
|
|
183
221
|
flowState = 'awaiting_approval'
|
|
@@ -525,15 +525,22 @@ function ModalFooter({
|
|
|
525
525
|
// evidence it could not verify). A GitOps install with a link goes to the
|
|
526
526
|
// wizard's Argo/Flux tab, which generates a values patch for the repo rather
|
|
527
527
|
// than an imperative command the controller would revert.
|
|
528
|
+
const nkp = self?.platform === 'nkp'
|
|
528
529
|
const cliOnly = (gitops || ambiguous) && !self?.wizardUrl
|
|
529
530
|
// Until classification resolves we cannot know which lane applies, and a
|
|
530
531
|
// fast click would escape to signup before we could route this install.
|
|
531
532
|
const selfPending = selfLoading === true
|
|
532
533
|
return (
|
|
533
534
|
<div className="shrink-0 px-8 py-6 bg-theme-base border-t border-theme-border">
|
|
534
|
-
{self && self.ownership !== 'unknown' && (
|
|
535
|
+
{self && (self.ownership !== 'unknown' || nkp) && (
|
|
535
536
|
<div className="mb-3.5 card-inner p-3 text-[12px] leading-relaxed text-theme-text-secondary">
|
|
536
|
-
{
|
|
537
|
+
{nkp ? (
|
|
538
|
+
<>
|
|
539
|
+
NKP manages this Radar, so a change made to it directly would be undone. Radar Cloud gives you
|
|
540
|
+
settings to paste into the Radar app's configuration in NKP. They apply to every cluster in the
|
|
541
|
+
workspace.
|
|
542
|
+
</>
|
|
543
|
+
) : ambiguous ? (
|
|
537
544
|
<>
|
|
538
545
|
Radar found conflicting management metadata on this install, so it can't say whether a Helm
|
|
539
546
|
upgrade or a repository change is the right move. Run{' '}
|
|
@@ -628,7 +635,7 @@ function ModalFooter({
|
|
|
628
635
|
onClick={(e) => { if (selfPending) e.preventDefault() }}
|
|
629
636
|
className={`px-5 py-2 rounded-[10px] bg-emerald-500 hover:bg-emerald-400 text-emerald-950 text-[13.5px] font-bold shadow-[0_0_22px_rgba(16,185,129,0.35)] hover:shadow-[0_0_30px_rgba(16,185,129,0.5)] hover:-translate-y-px transition-all ${selfPending ? 'opacity-60 pointer-events-none' : ''}`}
|
|
630
637
|
>
|
|
631
|
-
{lane === 'driver' ? 'Continue in Radar Cloud' : self?.ownership === 'helm' || gitops ? 'Connect this cluster' : 'Try Cloud free'}
|
|
638
|
+
{lane === 'driver' ? 'Continue in Radar Cloud' : nkp ? 'Connect your NKP workspace' : self?.ownership === 'helm' || gitops ? 'Connect this cluster' : 'Try Cloud free'}
|
|
632
639
|
</a>
|
|
633
640
|
)}
|
|
634
641
|
{/* Self-Managed is a paid product with its own trial, so it gets a real
|
|
@@ -7,7 +7,8 @@ const sidebar = vi.hoisted(() => ({ data: undefined as CNPGWorkspaceResponse | u
|
|
|
7
7
|
vi.mock('../../api/cnpg', () => ({ useCNPGWorkspace: () => ({ data: sidebar.data }) }))
|
|
8
8
|
vi.mock('../../api/cnpg-storage', () => ({ useCNPGFleetDisk: () => ({}) }))
|
|
9
9
|
vi.mock('../../api/cnpg-history', () => ({ useCNPGFleetMetrics: () => ({}) }))
|
|
10
|
-
vi.
|
|
10
|
+
const feature = vi.hoisted(() => ({ value: { support: 'supported', upgrade: null } as { support: string; upgrade: { feature: string; minimumVersion?: string } | null } }))
|
|
11
|
+
vi.mock('../../api/client', () => ({ useRadarFeature: () => feature.value }))
|
|
11
12
|
|
|
12
13
|
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: 'kind-test' } }) }))
|
|
13
14
|
vi.mock('./CNPGOperatorBanner', () => ({ CNPGOperatorBanner: () => null }))
|
|
@@ -23,8 +24,8 @@ const cluster = (namespace: string, name: string) => ({
|
|
|
23
24
|
status: { phase: 'Cluster in healthy state', readyInstances: 1 },
|
|
24
25
|
})
|
|
25
26
|
|
|
26
|
-
function response(clusters: ReturnType<typeof cluster>[], coverage: CNPGKindCoverage = { state: 'full' }): CNPGWorkspaceResponse {
|
|
27
|
-
return { installed: true, context: 'kind-test', namespaces: null, coverage: { clusters: coverage }, objects: { clusters }, issues: [], audit
|
|
27
|
+
function response(clusters: ReturnType<typeof cluster>[], coverage: CNPGKindCoverage = { state: 'full' }, audit: CNPGWorkspaceResponse['audit'] = []): CNPGWorkspaceResponse {
|
|
28
|
+
return { installed: true, context: 'kind-test', namespaces: null, coverage: { clusters: coverage }, objects: { clusters }, issues: [], audit, backupsOmitted: 0 }
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
function render(resp: CNPGWorkspaceResponse, query = '', opts: { attention?: string[]; onCreate?: () => void; namespaces?: string[] } = {}) {
|
|
@@ -169,3 +170,74 @@ it('uses an unknown sidebar count and tooltip for zero over partial coverage', (
|
|
|
169
170
|
expect(result.value!.CloudNativePG.destinations.find((d) => d.id === 'protection')!.count).toBe(0)
|
|
170
171
|
sidebar.data = undefined
|
|
171
172
|
})
|
|
173
|
+
|
|
174
|
+
describe('CNPGOverview posture summary', () => {
|
|
175
|
+
const withSpec = (name: string, spec: { instances: number } & Record<string, unknown>) => ({ ...cluster('pg', name), spec })
|
|
176
|
+
const finding = (name: string, checkId: string) => ({ checkId, severity: 'warning', kind: 'Cluster', namespace: 'pg', name, message: checkId })
|
|
177
|
+
const count = (html: string, label: string) => html.match(new RegExp(`${label}</span><span[^>]*>([^<]+)<`))?.[1]
|
|
178
|
+
const bareAndIntree = () => response(
|
|
179
|
+
[withSpec('bare', { instances: 1 }), withSpec('intree', { instances: 3, backup: { barmanObjectStore: { destinationPath: 's3://b' } } })],
|
|
180
|
+
{ state: 'full' },
|
|
181
|
+
[finding('bare', 'cnpgNoBackupDestination'), finding('bare', 'cnpgSingleInstance'), finding('intree', 'cnpgInTreeBackupDeprecated')],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
it("counts the Checks' findings above the table, in neutral text", () => {
|
|
185
|
+
const html = render(bareAndIntree())
|
|
186
|
+
expect(count(html, 'No backup destination')).toBe('1')
|
|
187
|
+
expect(count(html, 'Single instance')).toBe('1')
|
|
188
|
+
expect(count(html, 'In-tree backup')).toBe('1')
|
|
189
|
+
expect(count(html, 'No WAL archiving')).toBe('0')
|
|
190
|
+
expect(html).toMatch(/<div role="group"[^>]*aria-label="Backup and availability configuration"/)
|
|
191
|
+
expect(html).toMatch(/Single instance<\/span><span class="font-mono">1</)
|
|
192
|
+
expect(html).not.toContain('With a destination')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('does not count a single-instance spec that Checks reports nothing for', () => {
|
|
196
|
+
const html = render(response([withSpec('a', { instances: 1 }), withSpec('b', { instances: 1 })], { state: 'full' }, [finding('a', 'cnpgSingleInstance')]))
|
|
197
|
+
expect(count(html, 'Single instance')).toBe('1')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('narrows the table to one posture value, with a chip to clear it', () => {
|
|
201
|
+
const html = render(bareAndIntree(), 'protect=none')
|
|
202
|
+
expect(html).toContain('bare')
|
|
203
|
+
expect(html).not.toContain('>intree<')
|
|
204
|
+
expect(html).toContain('Posture: No backup destination')
|
|
205
|
+
expect(html).toMatch(/aria-pressed="true"[^>]*><span>No backup destination/)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('shows counts as lower bounds when Clusters were partly read', () => {
|
|
209
|
+
const html = render(response([withSpec('a', { instances: 1 }), withSpec('b', { instances: 1 })], { state: 'partial', allowedNamespaces: ['pg'] } as CNPGKindCoverage, [finding('a', 'cnpgSingleInstance'), finding('b', 'cnpgSingleInstance')]))
|
|
210
|
+
expect(count(html, 'Single instance')).toBe('≥2')
|
|
211
|
+
expect(count(html, 'No WAL archiving')).toBe('–')
|
|
212
|
+
expect(html).toContain('aria-label="No WAL archiving: unknown"')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('ignores an unknown protect value', () => {
|
|
216
|
+
const html = render(bareAndIntree(), 'protect=bogus')
|
|
217
|
+
expect(html).toContain('bare')
|
|
218
|
+
expect(html).toContain('intree')
|
|
219
|
+
expect(html).not.toContain('Posture:')
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('says the filters, not attention, emptied the table when posture narrows it to nothing', () => {
|
|
223
|
+
const html = render(response([withSpec('a', { instances: 3 })]), 'filter=attention&protect=intree', { attention: ['a'] })
|
|
224
|
+
expect(html).toContain('No clusters match these filters')
|
|
225
|
+
expect(html).not.toContain('No clusters need attention')
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('replaces the counts with an upgrade note on a Radar that predates them, never a zero', () => {
|
|
229
|
+
feature.value = { support: 'unsupported', upgrade: { feature: 'CloudNativePG backup and availability counts', minimumVersion: 'v1.21.0' } }
|
|
230
|
+
try {
|
|
231
|
+
const html = render(bareAndIntree())
|
|
232
|
+
expect(html).toContain('CloudNativePG backup and availability counts')
|
|
233
|
+
expect(html).toContain('need Radar v1.21 or newer')
|
|
234
|
+
expect(html).not.toContain('Backup and availability configuration')
|
|
235
|
+
expect(render(bareAndIntree(), 'protect=none')).toContain('>intree<')
|
|
236
|
+
const loading = (feature.value = { support: 'unknown', upgrade: null }, render(bareAndIntree()))
|
|
237
|
+
expect(loading).not.toContain('Backup and availability configuration')
|
|
238
|
+
expect(loading).not.toContain('need Radar')
|
|
239
|
+
} finally {
|
|
240
|
+
feature.value = { support: 'supported', upgrade: null }
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
})
|
|
@@ -4,19 +4,25 @@ import { ArrowRight, Database, FileText, Plus, Search } from 'lucide-react'
|
|
|
4
4
|
import {
|
|
5
5
|
CNPG_PROBLEM_CATEGORIES,
|
|
6
6
|
CNPG_PROBLEM_TONE,
|
|
7
|
+
CNPG_POSTURE_FILTERS,
|
|
7
8
|
cnpgDimensions,
|
|
9
|
+
cnpgMatchesPostureFilter,
|
|
8
10
|
cnpgReadyInstances,
|
|
9
11
|
FactValue,
|
|
12
|
+
RadarUpgradeNote,
|
|
10
13
|
StatusDot,
|
|
11
14
|
Tooltip,
|
|
12
15
|
toneTextClass,
|
|
13
16
|
usePhoneLayout,
|
|
17
|
+
type CNPGFleetPosture,
|
|
14
18
|
type CNPGFleetRow,
|
|
19
|
+
type CNPGPostureFilter,
|
|
15
20
|
type CNPGProblemCategory,
|
|
16
21
|
} from '@skyhook-io/k8s-ui'
|
|
17
22
|
import type { SelectedResource } from '../../types'
|
|
18
23
|
import { useConnection } from '../../context/ConnectionContext'
|
|
19
24
|
import { getApiBase } from '../../api/config'
|
|
25
|
+
import { useRadarFeature } from '../../api/client'
|
|
20
26
|
import { CNPGWorkspaceHeader, CoverageNotice, coverageEmpty, type CNPGScreenProps } from './shared'
|
|
21
27
|
import { cnpgClusterFullPath, cnpgClusterProblemsPath } from './paths'
|
|
22
28
|
import { currentPageLabel } from '../../utils/page-links'
|
|
@@ -189,6 +195,46 @@ function AttentionCell({ row, onOpenAll }: { row: CNPGFleetRow; onOpenAll: () =>
|
|
|
189
195
|
)
|
|
190
196
|
}
|
|
191
197
|
|
|
198
|
+
const POSTURE_LABELS: Record<CNPGPostureFilter, string> = {
|
|
199
|
+
none: 'No backup destination',
|
|
200
|
+
nowal: 'No WAL archiving',
|
|
201
|
+
single: 'Single instance',
|
|
202
|
+
intree: 'In-tree backup',
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Clusters with each posture Check's finding, as Checks reports them. Each count narrows the table.
|
|
206
|
+
function PostureSummary({ posture, lowerBound, active, onToggle }: {
|
|
207
|
+
posture: CNPGFleetPosture
|
|
208
|
+
lowerBound: boolean
|
|
209
|
+
active: CNPGPostureFilter | null
|
|
210
|
+
onToggle: (filter: CNPGPostureFilter) => void
|
|
211
|
+
}) {
|
|
212
|
+
// Posture is stated without a mark, as on every CNPG surface: no tone on the counts.
|
|
213
|
+
return (
|
|
214
|
+
<div role="group" className="flex flex-wrap items-center gap-2 text-xs" aria-label="Backup and availability configuration">
|
|
215
|
+
{CNPG_POSTURE_FILTERS.map((id) => {
|
|
216
|
+
const value = posture[id]
|
|
217
|
+
const text = lowerBound ? value === 0 ? '–' : `≥${value}` : String(value)
|
|
218
|
+
const on = active === id
|
|
219
|
+
return (
|
|
220
|
+
<button
|
|
221
|
+
key={id}
|
|
222
|
+
type="button"
|
|
223
|
+
aria-pressed={on}
|
|
224
|
+
aria-label={`${POSTURE_LABELS[id]}: ${lowerBound && value === 0 ? 'unknown' : text}`}
|
|
225
|
+
disabled={value === 0 && !on}
|
|
226
|
+
onClick={() => onToggle(id)}
|
|
227
|
+
className={clsx(
|
|
228
|
+
'inline-flex items-center gap-1.5 rounded-full border px-2.5 py-0.5 transition-colors',
|
|
229
|
+
on ? 'border-accent bg-accent-muted text-accent-text' : 'border-theme-border text-theme-text-secondary enabled:hover:bg-theme-hover disabled:opacity-60',
|
|
230
|
+
)}
|
|
231
|
+
><span>{POSTURE_LABELS[id]}</span><span className="font-mono">{text}</span></button>
|
|
232
|
+
)
|
|
233
|
+
})}
|
|
234
|
+
</div>
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
192
238
|
export function CNPGOverview({
|
|
193
239
|
data,
|
|
194
240
|
fleet,
|
|
@@ -209,23 +255,28 @@ export function CNPGOverview({
|
|
|
209
255
|
const rawFilter = searchParams.get('filter') as Filter | null
|
|
210
256
|
// The view is the list of clusters: all of them unless asked for less.
|
|
211
257
|
const filter: Filter = rawFilter === 'attention' ? 'attention' : 'all'
|
|
258
|
+
// An older Radar's findings lack the posture Checks: its counts would read 0.
|
|
259
|
+
const postureFeature = useRadarFeature('cnpgPostureChecks')
|
|
260
|
+
const rawProtect = searchParams.get('protect')
|
|
261
|
+
const protect = postureFeature.support === 'supported' && (CNPG_POSTURE_FILTERS as readonly string[]).includes(rawProtect ?? '') ? rawProtect as CNPGPostureFilter : null
|
|
212
262
|
|
|
213
263
|
const rows = useMemo(() => {
|
|
214
264
|
let list = fleet.rows
|
|
215
265
|
if (filter === 'attention') list = list.filter((r) => r.attention)
|
|
216
266
|
if (cat) list = list.filter((r) => r.categories.has(cat))
|
|
267
|
+
if (protect) list = list.filter((r) => cnpgMatchesPostureFilter(r, protect))
|
|
217
268
|
if (q) {
|
|
218
269
|
const needle = q.toLowerCase()
|
|
219
270
|
list = list.filter((r) => r.name.toLowerCase().includes(needle) || r.namespace.toLowerCase().includes(needle))
|
|
220
271
|
}
|
|
221
272
|
return list
|
|
222
|
-
}, [fleet, filter, cat, q])
|
|
273
|
+
}, [fleet, filter, cat, protect, q])
|
|
223
274
|
|
|
224
275
|
const clustersCov = data.coverage.clusters
|
|
225
276
|
const total = fleet.rows.length
|
|
226
277
|
const context = connection.context || data.context
|
|
227
278
|
// Some namespaces were not read: the count is a floor, not the cluster's total.
|
|
228
|
-
const totalText = `${
|
|
279
|
+
const totalText = `${fleet.incompleteKinds.includes('clusters') ? '≥' : ''}${total}`
|
|
229
280
|
// No cluster authoring on a phone (a YAML editor follows the dialog).
|
|
230
281
|
const isPhone = usePhoneLayout()
|
|
231
282
|
const createAction = onCreate && !isPhone ? (
|
|
@@ -270,6 +321,7 @@ export function CNPGOverview({
|
|
|
270
321
|
|
|
271
322
|
const chips: { label: string; onClear: () => void }[] = []
|
|
272
323
|
if (cat) chips.push({ label: `Problem: ${CNPG_PROBLEM_CATEGORIES.find((c) => c.id === cat)?.label ?? cat}`, onClear: () => onSetParams({ cat: null }) })
|
|
324
|
+
if (protect) chips.push({ label: `Posture: ${POSTURE_LABELS[protect]}`, onClear: () => onSetParams({ protect: null }) })
|
|
273
325
|
if (q) chips.push({ label: `Search: ${q}`, onClear: () => onSetParams({ q: null }) })
|
|
274
326
|
if (namespaces.length > 0) chips.push({ label: `Namespace: ${namespaces.join(', ')}`, onClear: onClearNamespaces })
|
|
275
327
|
|
|
@@ -314,6 +366,12 @@ export function CNPGOverview({
|
|
|
314
366
|
<CoverageNotice fleet={fleet} data={data} kinds={['clusters', 'pods', 'backups', 'scheduledBackups', 'objectStores', 'poolers', 'databases', 'databaseRoles', 'publications', 'subscriptions']} includeJobs />
|
|
315
367
|
<CNPGOperatorBanner namespaces={fleet.rows.map((r) => r.namespace)} className="" />
|
|
316
368
|
|
|
369
|
+
{postureFeature.upgrade ? (
|
|
370
|
+
<RadarUpgradeNote requirement={postureFeature.upgrade} />
|
|
371
|
+
) : postureFeature.support === 'supported' ? (
|
|
372
|
+
<PostureSummary posture={fleet.posture} lowerBound={fleet.incompleteKinds.includes('clusters')} active={protect} onToggle={(f) => onSetParams({ protect: protect === f ? null : f })} />
|
|
373
|
+
) : null}
|
|
374
|
+
|
|
317
375
|
<div className="flex flex-wrap items-center gap-2">
|
|
318
376
|
<div role="tablist" aria-label="Clusters" className="inline-flex rounded-lg bg-theme-elevated p-0.5">
|
|
319
377
|
{segment('all', 'All clusters', totalText)}
|
|
@@ -469,10 +527,10 @@ export function CNPGOverview({
|
|
|
469
527
|
</div>
|
|
470
528
|
{rows.length === 0 && (
|
|
471
529
|
<div className="px-4 py-6 text-sm text-theme-text-tertiary">
|
|
472
|
-
{filter === 'attention' && !cat && !q
|
|
530
|
+
{filter === 'attention' && !cat && !q && !protect
|
|
473
531
|
? lowerBound ? 'No attention findings in the readable data; other data was not read.' : 'No clusters need attention.'
|
|
474
532
|
: 'No clusters match these filters.'}{' '}
|
|
475
|
-
<button type="button" onClick={() => onSetParams({ filter: 'all', cat: null, q: null })} className="font-medium text-accent-text hover:underline">
|
|
533
|
+
<button type="button" onClick={() => onSetParams({ filter: 'all', cat: null, q: null, protect: null })} className="font-medium text-accent-text hover:underline">
|
|
476
534
|
Show all clusters
|
|
477
535
|
</button>
|
|
478
536
|
</div>
|
|
@@ -78,4 +78,41 @@ describe("NetworkPolicyCoverageCard", () => {
|
|
|
78
78
|
expect(html).not.toContain("if staged");
|
|
79
79
|
expect(html).not.toContain("repeating-linear-gradient");
|
|
80
80
|
});
|
|
81
|
+
|
|
82
|
+
it("says which workloads the totals leave out", () => {
|
|
83
|
+
const html = render(
|
|
84
|
+
<NetworkPolicyCoverageCard
|
|
85
|
+
data={{
|
|
86
|
+
totalPolicies: 1,
|
|
87
|
+
coveredWorkloads: 1,
|
|
88
|
+
totalWorkloads: 3,
|
|
89
|
+
ignoredNamespaceWorkloads: 6,
|
|
90
|
+
hostNetworkWorkloads: 1,
|
|
91
|
+
}}
|
|
92
|
+
onNavigate={() => {}}
|
|
93
|
+
/>,
|
|
94
|
+
);
|
|
95
|
+
expect(html).toContain("7 not counted");
|
|
96
|
+
|
|
97
|
+
const none = render(
|
|
98
|
+
<NetworkPolicyCoverageCard
|
|
99
|
+
data={{ totalPolicies: 1, coveredWorkloads: 1, totalWorkloads: 3 }}
|
|
100
|
+
onNavigate={() => {}}
|
|
101
|
+
/>,
|
|
102
|
+
);
|
|
103
|
+
expect(none).not.toContain("not counted");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("does not show 0% coverage when no workloads are counted", () => {
|
|
107
|
+
const html = render(
|
|
108
|
+
<NetworkPolicyCoverageCard
|
|
109
|
+
data={{ totalPolicies: 2, coveredWorkloads: 0, totalWorkloads: 0, ignoredNamespaceWorkloads: 3 }}
|
|
110
|
+
onNavigate={() => {}}
|
|
111
|
+
/>,
|
|
112
|
+
);
|
|
113
|
+
expect(html).toContain("No workloads counted");
|
|
114
|
+
expect(html).toContain("3 not counted");
|
|
115
|
+
expect(html).not.toContain("0%");
|
|
116
|
+
expect(html).not.toContain("text-red-500");
|
|
117
|
+
});
|
|
81
118
|
});
|
|
@@ -27,7 +27,16 @@ export function NetworkPolicyCoverageCard({ data, onNavigate }: NetworkPolicyCov
|
|
|
27
27
|
// projection without any staged policies.
|
|
28
28
|
const stagedDeltaPercentage = hasStagedPolicies ? Math.abs(percentageIfStaged - percentage) : 0
|
|
29
29
|
const hasPolicies = data.totalPolicies > 0
|
|
30
|
-
const
|
|
30
|
+
const ignoredNamespaceWorkloads = data.ignoredNamespaceWorkloads ?? 0
|
|
31
|
+
const hostNetworkWorkloads = data.hostNetworkWorkloads ?? 0
|
|
32
|
+
const notCounted = ignoredNamespaceWorkloads + hostNetworkWorkloads
|
|
33
|
+
const notCountedReasons = [
|
|
34
|
+
ignoredNamespaceWorkloads > 0 && `${ignoredNamespaceWorkloads} in namespaces ignored in Checks settings.`,
|
|
35
|
+
hostNetworkWorkloads > 0 && `${hostNetworkWorkloads} on the host network, where network policies may not apply.`,
|
|
36
|
+
].filter(Boolean).join(' ')
|
|
37
|
+
// With nothing to count, 0% would read as a coverage failure.
|
|
38
|
+
const hasWorkloads = data.totalWorkloads > 0
|
|
39
|
+
const accentColor = !hasPolicies || !hasWorkloads
|
|
31
40
|
? 'text-theme-text-tertiary'
|
|
32
41
|
: percentage >= 75
|
|
33
42
|
? 'text-green-500'
|
|
@@ -59,6 +68,11 @@ export function NetworkPolicyCoverageCard({ data, onNavigate }: NetworkPolicyCov
|
|
|
59
68
|
<ShieldCheck className="w-8 h-8 text-theme-text-tertiary/40" />
|
|
60
69
|
<span className="text-xs text-theme-text-tertiary">No network policies configured</span>
|
|
61
70
|
</div>
|
|
71
|
+
) : !hasWorkloads ? (
|
|
72
|
+
<div className="flex flex-col items-center justify-center text-center gap-2">
|
|
73
|
+
<ShieldCheck className="w-8 h-8 text-theme-text-tertiary/40" />
|
|
74
|
+
<span className="text-xs text-theme-text-tertiary">No workloads counted</span>
|
|
75
|
+
</div>
|
|
62
76
|
) : (
|
|
63
77
|
<>
|
|
64
78
|
<div className="flex items-center gap-3 w-full">
|
|
@@ -118,7 +132,17 @@ export function NetworkPolicyCoverageCard({ data, onNavigate }: NetworkPolicyCov
|
|
|
118
132
|
)}
|
|
119
133
|
</div>
|
|
120
134
|
|
|
121
|
-
<div className=
|
|
135
|
+
<div className={clsx(
|
|
136
|
+
'px-4 py-1.5 border-t border-theme-border/50 flex items-center',
|
|
137
|
+
notCounted > 0 ? 'justify-between' : 'justify-end',
|
|
138
|
+
)}>
|
|
139
|
+
{notCounted > 0 && (
|
|
140
|
+
<Tooltip content={`Workloads not counted: ${notCountedReasons}`}>
|
|
141
|
+
<span className="text-[10px] text-theme-text-tertiary">
|
|
142
|
+
{notCounted} not counted
|
|
143
|
+
</span>
|
|
144
|
+
</Tooltip>
|
|
145
|
+
)}
|
|
122
146
|
<span className={clsx(
|
|
123
147
|
'flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider transition-colors',
|
|
124
148
|
accentColor,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expect, it } from 'vitest'
|
|
2
|
+
import { RadarFeatureUnsupportedError } from '../../../api/radarFeatures'
|
|
3
|
+
import { routeFactsProps } from './TraefikIngressRouteRenderer'
|
|
4
|
+
|
|
5
|
+
const answer = { installed: true, coverage: {}, truncated: false, routes: [{ rule: 0 } as any], middlewares: [{ namespace: 'shop', name: 'redirect', usedBy: 12 }] }
|
|
6
|
+
|
|
7
|
+
it('passes rule facts and middleware use to the drawer', () => {
|
|
8
|
+
expect(routeFactsProps({ data: answer, isError: false, support: 'supported' })).toMatchObject({ routeFacts: answer.routes, middlewareUse: { 'shop/redirect': 12 } })
|
|
9
|
+
})
|
|
10
|
+
it('keeps the drawer unchanged on an older Radar and while loading', () => {
|
|
11
|
+
expect(routeFactsProps({ isError: true, support: 'unsupported' }).routeFacts).toBeUndefined()
|
|
12
|
+
expect(routeFactsProps({ isError: false, support: 'supported' }).routeFacts).toBeUndefined()
|
|
13
|
+
})
|
|
14
|
+
it('says the facts could not be loaded when the request fails', () => {
|
|
15
|
+
expect(routeFactsProps({ isError: true, support: 'supported' }).routeFacts).toBeNull()
|
|
16
|
+
})
|
|
17
|
+
it('hides the section when a Radar of unknown version turns out not to have the route', () => {
|
|
18
|
+
expect(routeFactsProps({ isError: true, error: new RadarFeatureUnsupportedError('traefikRoutes', {}), support: 'unknown' }).routeFacts).toBeUndefined()
|
|
19
|
+
})
|
|
20
|
+
it('marks middleware counts partial unless the routes were read in full', () => {
|
|
21
|
+
expect(routeFactsProps({ data: { ...answer, coverage: { ingressroutes: { state: 'full' } } } as any, isError: false, support: 'supported' }).middlewareUsePartial).toBe(false)
|
|
22
|
+
expect(routeFactsProps({ data: { ...answer, coverage: { ingressroutes: { state: 'partial' } } } as any, isError: false, support: 'supported' }).middlewareUsePartial).toBe(true)
|
|
23
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { TraefikIngressRouteRenderer as BaseTraefikIngressRouteRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/TraefikIngressRouteRenderer'
|
|
3
|
+
import type { ResourceRef, TraefikRoutesResponse } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { isRadarFeatureUnsupported } from '../../../api/radarFeatures'
|
|
5
|
+
import { useTraefikRouteFacts } from '../../../api/traefik'
|
|
6
|
+
|
|
7
|
+
// The answer as the drawer takes it: undefined on an older Radar or while
|
|
8
|
+
// loading (the drawer looks as before), null when the request failed.
|
|
9
|
+
export function routeFactsProps(query: { data?: TraefikRoutesResponse; isError: boolean; error?: unknown; support: string }) {
|
|
10
|
+
if (query.support === 'unsupported' || isRadarFeatureUnsupported(query.error, 'traefikRoutes')) return { routeFacts: undefined, middlewareUse: undefined }
|
|
11
|
+
if (query.isError) return { routeFacts: null, middlewareUse: undefined }
|
|
12
|
+
if (!query.data) return { routeFacts: undefined, middlewareUse: undefined }
|
|
13
|
+
const middlewareUse: Record<string, number> = {}
|
|
14
|
+
for (const m of query.data.middlewares) middlewareUse[`${m.namespace}/${m.name}`] = m.usedBy
|
|
15
|
+
return { routeFacts: query.data.routes, middlewareUse, middlewareUsePartial: query.data.coverage?.ingressroutes?.state !== 'full' }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Host wrapper: adds each rule's request path to the IngressRoute drawer. */
|
|
19
|
+
export function TraefikIngressRouteRenderer({ data, onNavigate }: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
20
|
+
const { data: facts, isError, error, support } = useTraefikRouteFacts(data?.metadata?.namespace ?? '', data?.metadata?.name ?? '', String(data?.apiVersion ?? '').split('/')[0])
|
|
21
|
+
const props = useMemo(() => routeFactsProps({ data: facts, isError, error, support }), [facts, isError, error, support])
|
|
22
|
+
return <BaseTraefikIngressRouteRenderer data={data} onNavigate={onNavigate} {...props} />
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { expect, it } from 'vitest'
|
|
2
|
+
import { RadarFeatureUnsupportedError } from '../../../api/radarFeatures'
|
|
3
|
+
import { middlewareUsers } from './TraefikMiddlewareRenderer'
|
|
4
|
+
|
|
5
|
+
const answer = (state: string) => ({ installed: true, truncated: false, middlewares: [], coverage: { ingressroutes: { state } }, routes: [{ ref: { group: 'traefik.io', namespace: 'shop', name: 'ui' } } as any] })
|
|
6
|
+
|
|
7
|
+
it('maps rows to routes and reads partial coverage', () => {
|
|
8
|
+
expect(middlewareUsers({ data: answer('full'), isError: false, support: 'supported' })).toEqual({ routes: [{ group: 'traefik.io', namespace: 'shop', name: 'ui' }], truncated: false, partial: false })
|
|
9
|
+
expect(middlewareUsers({ data: answer('partial'), isError: false, support: 'supported' })?.partial).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
it('keeps the drawer unchanged on an older Radar and says when the request failed', () => {
|
|
12
|
+
expect(middlewareUsers({ isError: true, support: 'unsupported' })).toBeUndefined()
|
|
13
|
+
expect(middlewareUsers({ isError: true, support: 'supported' })).toBeNull()
|
|
14
|
+
})
|
|
15
|
+
it('hides the section when a Radar of unknown version turns out not to have the route', () => {
|
|
16
|
+
expect(middlewareUsers({ isError: true, error: new RadarFeatureUnsupportedError('traefikRoutes', {}), support: 'unknown' })).toBeUndefined()
|
|
17
|
+
})
|
|
18
|
+
it('never reads an unread IngressRoute answer as no route', () => {
|
|
19
|
+
expect(middlewareUsers({ data: answer('syncing'), isError: false, support: 'supported' })).toBeUndefined()
|
|
20
|
+
for (const state of ['denied', 'uncached', 'error', 'notInstalled']) {
|
|
21
|
+
expect(middlewareUsers({ data: answer(state), isError: false, support: 'supported' })).toBeNull()
|
|
22
|
+
}
|
|
23
|
+
})
|