@skyhook-io/radar-app 1.18.2 → 1.20.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/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -6
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +97 -3
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +41 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/diagnose/AIMarkdown.tsx +4 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
- package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
- package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
- package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
- package/src/components/diagnose/AnalysisStory.tsx +17 -4
- package/src/components/diagnose/AssessmentCard.tsx +39 -8
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +272 -10
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +208 -5
- package/src/components/diagnose/Home.tsx +187 -36
- package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
- package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
- package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
- package/src/components/diagnose/InvestigationView.tsx +249 -54
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +495 -0
- package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
- package/src/components/diagnose/QuestionFocus.tsx +123 -0
- package/src/components/diagnose/ResourcePicker.tsx +206 -0
- package/src/components/diagnose/StoryExcerpt.tsx +12 -3
- package/src/components/diagnose/assessmentCopy.ts +5 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
- package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
- package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
- package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
- package/src/components/diagnose/investigationEvidence/index.ts +1 -1
- package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +7 -0
- package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
- package/src/components/diagnose/investigationFocus.test.ts +271 -0
- package/src/components/diagnose/investigationFocus.ts +132 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/parts.test.tsx +20 -0
- package/src/components/diagnose/questionSuggestions.test.ts +111 -0
- package/src/components/diagnose/questionSuggestions.ts +150 -0
- package/src/components/diagnose/storyParts.test.tsx +13 -0
- package/src/components/diagnose/target.test.ts +143 -2
- package/src/components/diagnose/target.ts +109 -7
- package/src/components/diagnose/testdata/story-runs.json +474 -0
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/diagnose/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +141 -0
- package/src/components/home/HomeAgentBlock.tsx +103 -0
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +86 -47
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
- package/src/components/ui/Omnibar.tsx +47 -3
- package/src/components/ui/RadarOmnibar.test.tsx +1 -0
- package/src/components/ui/RadarOmnibar.tsx +11 -0
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
- package/src/components/whats-new/releaseNotes.ts +136 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +6 -4
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
- package/src/hooks/useElementSize.ts +30 -0
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type PrometheusMetricCategory,
|
|
14
14
|
type PrometheusTimeRange,
|
|
15
15
|
} from '../../api/client'
|
|
16
|
+
import { parseQuantity } from '@skyhook-io/k8s-ui/utils/format'
|
|
16
17
|
|
|
17
18
|
// ============================================================================
|
|
18
19
|
// Radar-specific category config (lives here, not in k8s-ui, so consumers
|
|
@@ -164,8 +165,8 @@ export function computeRequestLimitLines(
|
|
|
164
165
|
let reqSum = 0, reqAny = false
|
|
165
166
|
let limSum = 0, limAll = true
|
|
166
167
|
for (const c of runtimeContainers) {
|
|
167
|
-
const req =
|
|
168
|
-
const lim =
|
|
168
|
+
const req = parseQuantity(c.resources?.requests?.[category])
|
|
169
|
+
const lim = parseQuantity(c.resources?.limits?.[category])
|
|
169
170
|
if (req != null) { reqSum += req; reqAny = true }
|
|
170
171
|
if (lim != null && lim > 0) { limSum += lim } else { limAll = false }
|
|
171
172
|
}
|
|
@@ -206,44 +207,6 @@ function collectRuntimeContainers(podSpec: any): any[] {
|
|
|
206
207
|
return out
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
const CPU_SUFFIXES: Record<string, number> = { n: 1e-9, u: 1e-6, m: 1e-3 }
|
|
210
|
-
const MEMORY_SUFFIXES: Record<string, number> = {
|
|
211
|
-
Ki: 1024, Mi: 1024 ** 2, Gi: 1024 ** 3, Ti: 1024 ** 4, Pi: 1024 ** 5, Ei: 1024 ** 6,
|
|
212
|
-
n: 1e-9, u: 1e-6, m: 1e-3, k: 1e3, K: 1e3, M: 1e6, G: 1e9, T: 1e12, P: 1e15, E: 1e18,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// NOT a duplicate of @skyhook-io/k8s-ui/utils/format's parseCPUToNanocores /
|
|
216
|
-
// parseMemoryToBytes — those return 0 on invalid input. We need null so that
|
|
217
|
-
// "abcMi" doesn't silently poison the caller's running sum and produce a
|
|
218
|
-
// missing/zeroed reference line on the chart (real garbage data must be
|
|
219
|
-
// distinguishable from a legit 0).
|
|
220
|
-
function readQuantity(raw: unknown, category: 'cpu' | 'memory'): number | null {
|
|
221
|
-
if (raw == null) return null
|
|
222
|
-
const s = String(raw).trim()
|
|
223
|
-
if (s === '') return null
|
|
224
|
-
if (category === 'cpu') {
|
|
225
|
-
if (s.endsWith('m')) return scaleOrNull(s, CPU_SUFFIXES.m)
|
|
226
|
-
if (s.endsWith('n')) return scaleOrNull(s, CPU_SUFFIXES.n)
|
|
227
|
-
if (s.endsWith('u')) return scaleOrNull(s, CPU_SUFFIXES.u)
|
|
228
|
-
const v = parseFloat(s)
|
|
229
|
-
return isNaN(v) ? null : v
|
|
230
|
-
}
|
|
231
|
-
// Memory: try two-character then one-character suffixes (Mi before M).
|
|
232
|
-
for (const suffix of ['Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei']) {
|
|
233
|
-
if (s.endsWith(suffix)) return scaleOrNull(s, MEMORY_SUFFIXES[suffix])
|
|
234
|
-
}
|
|
235
|
-
for (const suffix of ['n', 'u', 'm', 'k', 'K', 'M', 'G', 'T', 'P', 'E']) {
|
|
236
|
-
if (s.endsWith(suffix)) return scaleOrNull(s, MEMORY_SUFFIXES[suffix])
|
|
237
|
-
}
|
|
238
|
-
const v = parseFloat(s)
|
|
239
|
-
return isNaN(v) ? null : v
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function scaleOrNull(s: string, scale: number): number | null {
|
|
243
|
-
const v = parseFloat(s)
|
|
244
|
-
return isNaN(v) ? null : v * scale
|
|
245
|
-
}
|
|
246
|
-
|
|
247
210
|
function formatRequestLimitLabel(value: number, category: 'cpu' | 'memory'): string {
|
|
248
211
|
if (category === 'cpu') {
|
|
249
212
|
if (value < 1) return `${Math.round(value * 1000)}m`
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
5
|
+
import { CRDSchemaTab } from './CRDSchemaTab'
|
|
6
|
+
|
|
7
|
+
const { read, browser } = vi.hoisted(() => ({ read: vi.fn(), browser: vi.fn() }))
|
|
8
|
+
vi.mock('../../../api/client', () => ({ useResource: read }))
|
|
9
|
+
vi.mock('../../../context/ThemeContext', () => ({ useTheme: () => ({ theme: 'light' }) }))
|
|
10
|
+
vi.mock('@skyhook-io/k8s-ui/components/resources/renderers/CRDSchemaBrowser', () => ({ CRDSchemaBrowser: (props: unknown) => { browser(props); return <div>Schema browser</div> } }))
|
|
11
|
+
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
|
|
12
|
+
let root: ReturnType<typeof createRoot>
|
|
13
|
+
let host: HTMLDivElement
|
|
14
|
+
afterEach(() => { act(() => root?.unmount()); host?.remove(); vi.clearAllMocks() })
|
|
15
|
+
it('matches the full-view resource key and passes data and theme to the browser', () => {
|
|
16
|
+
host = document.createElement('div'); document.body.append(host); root = createRoot(host)
|
|
17
|
+
const data = { spec: { versions: [] } }
|
|
18
|
+
read.mockReturnValue({ data, isLoading: false, error: null })
|
|
19
|
+
act(() => root.render(<CRDSchemaTab name="widgets.example.io" />))
|
|
20
|
+
expect(read).toHaveBeenCalledWith('customresourcedefinitions', '', 'widgets.example.io', 'apiextensions.k8s.io')
|
|
21
|
+
expect(browser).toHaveBeenCalledWith({ data, theme: 'light' })
|
|
22
|
+
read.mockReturnValue({ isLoading: true })
|
|
23
|
+
act(() => root.render(<CRDSchemaTab name="widgets.example.io" />))
|
|
24
|
+
expect(host.textContent).toContain('Loading schema')
|
|
25
|
+
read.mockReturnValue({ isLoading: false, error: new Error('Access denied') })
|
|
26
|
+
act(() => root.render(<CRDSchemaTab name="widgets.example.io" />))
|
|
27
|
+
expect(host.textContent).toContain('Access denied')
|
|
28
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PaneLoader } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { AlertBanner } from '@skyhook-io/k8s-ui/components/ui/drawer-components'
|
|
3
|
+
import { CRDSchemaBrowser } from '@skyhook-io/k8s-ui/components/resources/renderers/CRDSchemaBrowser'
|
|
4
|
+
import { useResource } from '../../../api/client'
|
|
5
|
+
import { useTheme } from '../../../context/ThemeContext'
|
|
6
|
+
|
|
7
|
+
export function CRDSchemaTab({ name }: { name: string }) {
|
|
8
|
+
const { data, isLoading, error } = useResource<any>('customresourcedefinitions', '', name, 'apiextensions.k8s.io')
|
|
9
|
+
const { theme } = useTheme()
|
|
10
|
+
if (isLoading) return <PaneLoader label="Loading schema…" />
|
|
11
|
+
if (error) return <AlertBanner variant="error" title="Couldn't load schema" message={error.message} />
|
|
12
|
+
return data ? <CRDSchemaBrowser data={data} theme={theme} /> : null
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Braces } from 'lucide-react'
|
|
2
|
+
import type { ResourceHost } from '../../../integrations/resourceHost'
|
|
3
|
+
import { CustomResourceDefinitionRenderer } from '../renderers/CustomResourceDefinitionRenderer'
|
|
4
|
+
import { CRDSchemaTab } from './CRDSchemaTab'
|
|
5
|
+
|
|
6
|
+
export const crdResourceHost: ResourceHost = {
|
|
7
|
+
id: 'crd',
|
|
8
|
+
resources: [{ name: 'customresourcedefinitions', group: 'apiextensions.k8s.io' }],
|
|
9
|
+
renderers: { CustomResourceDefinitionRenderer },
|
|
10
|
+
detailSlots: resource => ({ extraTabs: [{
|
|
11
|
+
id: 'schema', label: 'Schema', icon: <Braces className="h-4 w-4" />, after: 'overview',
|
|
12
|
+
render: () => <CRDSchemaTab name={resource.name} />,
|
|
13
|
+
}] }),
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
5
|
+
import { MemoryRouter, useLocation } from 'react-router-dom'
|
|
6
|
+
import { CustomResourceDefinitionRenderer } from './CustomResourceDefinitionRenderer'
|
|
7
|
+
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
|
|
8
|
+
window.matchMedia = vi.fn().mockReturnValue({ matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() })
|
|
9
|
+
let root: ReturnType<typeof createRoot>
|
|
10
|
+
let host: HTMLDivElement
|
|
11
|
+
afterEach(() => { act(() => root?.unmount()); host?.remove() })
|
|
12
|
+
function Location() { const location = useLocation(); return <output>{location.pathname}{location.search}</output> }
|
|
13
|
+
it('navigates to instances within the router basename', () => {
|
|
14
|
+
host = document.createElement('div'); document.body.append(host); root = createRoot(host)
|
|
15
|
+
act(() => root.render(<MemoryRouter basename="/c/test" initialEntries={['/c/test/resources/customresourcedefinitions']}><CustomResourceDefinitionRenderer data={{ spec: { group: 'example.io', names: { kind: 'Widget', plural: 'widgets' }, versions: [{ name: 'v1', served: true }] } }} /><Location /></MemoryRouter>))
|
|
16
|
+
act(() => Array.from(host.querySelectorAll('button')).find(b => b.textContent?.includes('View Widget resources'))!.click())
|
|
17
|
+
expect(host.querySelector('output')?.textContent).toBe('/resources/widgets?apiGroup=example.io')
|
|
18
|
+
})
|
|
19
|
+
it('keeps the namespace selection when opening instances', () => {
|
|
20
|
+
host = document.createElement('div'); document.body.append(host); root = createRoot(host)
|
|
21
|
+
act(() => root.render(<MemoryRouter initialEntries={['/resources/customresourcedefinitions?namespaces=team-a,team-b']}><CustomResourceDefinitionRenderer data={{ spec: { group: 'example.io', names: { kind: 'Widget', plural: 'widgets' }, versions: [{ name: 'v1', served: true }] } }} /><Location /></MemoryRouter>))
|
|
22
|
+
act(() => Array.from(host.querySelectorAll('button')).find(b => b.textContent?.includes('View Widget resources'))!.click())
|
|
23
|
+
const url = new URL(host.querySelector('output')!.textContent!, 'http://x')
|
|
24
|
+
expect(url.pathname).toBe('/resources/widgets')
|
|
25
|
+
expect(url.searchParams.get('apiGroup')).toBe('example.io')
|
|
26
|
+
expect(url.searchParams.get('namespaces')).toBe('team-a,team-b')
|
|
27
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useLocation, useNavigate } from 'react-router-dom'
|
|
2
|
+
import { CustomResourceDefinitionRenderer as BaseRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/CustomResourceDefinitionRenderer'
|
|
3
|
+
import type { ResourceRef } from '@skyhook-io/k8s-ui/types'
|
|
4
|
+
import { withCrossViewParams } from '../../../utils/navigation'
|
|
5
|
+
|
|
6
|
+
export function CustomResourceDefinitionRenderer({ data, onNavigate }: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
7
|
+
const navigate = useNavigate()
|
|
8
|
+
const { search } = useLocation()
|
|
9
|
+
return <BaseRenderer data={data} onNavigate={onNavigate} onViewInstances={() => {
|
|
10
|
+
navigate(withCrossViewParams(`/resources/${encodeURIComponent(data.spec.names.plural)}?apiGroup=${encodeURIComponent(data.spec.group)}`, search))
|
|
11
|
+
}} />
|
|
12
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
import { JobRenderer, JobSetRenderer } from './JobAdmissionRenderers'
|
|
4
|
-
vi.mock('../../execution/JobSetAdmission', () => ({ KueueAdmission: ({ presentation }: { presentation?: string
|
|
4
|
+
vi.mock('../../execution/JobSetAdmission', () => ({ KueueAdmission: ({ presentation, children }: { presentation?: string; children?: (content: React.ReactNode, managed: boolean) => React.ReactNode }) => {
|
|
5
|
+
const content = <div data-presentation={presentation}>admission evidence</div>
|
|
6
|
+
return children ? children(content, false) : content
|
|
7
|
+
} }))
|
|
5
8
|
const job = { apiVersion: 'batch/v1', kind: 'Job', metadata: { name: 'training', namespace: 'ml' }, status: { conditions: [{ type: 'Failed', status: 'True', reason: 'BackoffLimitExceeded' }] } }
|
|
6
9
|
describe('admission renderer composition', () => {
|
|
7
10
|
it('keeps Job failure above admission evidence', () => {
|
|
@@ -6,9 +6,10 @@ import { KueueAdmission } from '../../execution/JobSetAdmission'
|
|
|
6
6
|
type Props = { data: any; onNavigate?: (ref: ResourceRef) => void }
|
|
7
7
|
|
|
8
8
|
export function JobRenderer({ data, onNavigate }: Props) {
|
|
9
|
-
return <BaseJobRenderer data={data}
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (data.apiVersion !== 'batch/v1' || data.kind !== 'Job') return <BaseJobRenderer data={data} />
|
|
10
|
+
return <KueueAdmission presentation="drawer" resource={data} namespace={data.metadata.namespace} name={data.metadata.name} onNavigate={onNavigate}>
|
|
11
|
+
{(admissionContent, kueueManaged) => <BaseJobRenderer data={data} admissionContent={admissionContent} kueueManaged={kueueManaged} />}
|
|
12
|
+
</KueueAdmission>
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export function JobSetRenderer({ data, onNavigate }: Props) {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { ClusterQueueRenderer, LocalQueueRenderer, LocalQueueStatusBadge } from './KueueQueueRenderers'
|
|
7
|
+
import { KueueWorkloadRenderer } from './KueueWorkloadRenderer'
|
|
8
|
+
|
|
9
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
10
|
+
const v = 'kueue.x-k8s.io/v1beta2'
|
|
11
|
+
const active = (status: string, reason: string) => ({ type: 'Active', status, reason, observedGeneration: 1 })
|
|
12
|
+
const cq = (name: string, cohortName: string | undefined, condition: any, spec: any = {}) => ({ apiVersion: v, kind: 'ClusterQueue', metadata: { name, generation: 1 }, spec: { cohortName, ...spec }, status: { conditions: [condition] } })
|
|
13
|
+
|
|
14
|
+
let root: Root
|
|
15
|
+
let element: HTMLElement
|
|
16
|
+
let client: QueryClient
|
|
17
|
+
let queues: any[]
|
|
18
|
+
const requests: string[] = []
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
requests.length = 0
|
|
22
|
+
queues = []
|
|
23
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
24
|
+
element = document.createElement('div')
|
|
25
|
+
document.body.appendChild(element)
|
|
26
|
+
root = createRoot(element)
|
|
27
|
+
const complete = { status: 'complete', scope: { type: 'cluster' }, read: {}, gaps: [] }
|
|
28
|
+
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
|
29
|
+
const url = new URL(input, 'http://localhost')
|
|
30
|
+
requests.push(url.pathname)
|
|
31
|
+
if (url.pathname === '/api/resources/clusterqueues') return new Response(JSON.stringify({ items: queues, coverage: complete }))
|
|
32
|
+
if (url.pathname === '/api/resources/resourceflavors' || url.pathname === '/api/resources/admissionchecks') return new Response(JSON.stringify({ items: [], coverage: complete }))
|
|
33
|
+
if (url.pathname === '/api/resources/localqueues') return new Response(JSON.stringify({ items: [{ apiVersion: v, metadata: { name: 'lq', namespace: 'team', generation: 1 }, spec: { clusterQueue: 'parent' }, status: { conditions: [active('True', 'Ready')] } }], coverage: complete }))
|
|
34
|
+
if (url.pathname === '/api/resources/namespaces/_/team') return new Response(JSON.stringify({ resource: { metadata: { name: 'team', labels: { team: 'a' } } } }))
|
|
35
|
+
if (url.pathname.startsWith('/api/kueue/provisioning/')) return new Response(JSON.stringify({ uid: 'u', installed: true, requests: [], total: 0, truncated: false }))
|
|
36
|
+
throw new Error(`Unexpected request: ${input}`)
|
|
37
|
+
}))
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
afterEach(async () => {
|
|
41
|
+
await act(async () => root.unmount())
|
|
42
|
+
client.clear()
|
|
43
|
+
document.body.replaceChildren()
|
|
44
|
+
vi.unstubAllGlobals()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
async function render(node: React.ReactNode, until: () => void) {
|
|
48
|
+
await act(async () => root.render(<QueryClientProvider client={client}>{node}</QueryClientProvider>))
|
|
49
|
+
await vi.waitFor(until, { timeout: 4000 })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
it('lists the other ClusterQueues naming the cohort, never the queue itself', async () => {
|
|
53
|
+
queues = [cq('me', 'pool', active('True', 'Ready')), cq('lender', 'pool', active('True', 'Ready')), cq('stranger', 'other', active('True', 'Ready'))]
|
|
54
|
+
await render(<ClusterQueueRenderer data={queues[0]} />, () => expect(element.textContent).toContain('Other ClusterQueues naming this cohort'))
|
|
55
|
+
expect(element.textContent).toContain('lender')
|
|
56
|
+
expect(element.textContent).not.toContain('stranger')
|
|
57
|
+
const line = [...element.querySelectorAll('p')].find(p => p.textContent?.startsWith('Other ClusterQueues naming this cohort'))
|
|
58
|
+
expect(line?.textContent).toBe('Other ClusterQueues naming this cohort: lender')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('reads the namespace only when the ClusterQueue selector has terms', async () => {
|
|
62
|
+
queues = [cq('parent', undefined, active('True', 'Ready'), { namespaceSelector: {} })]
|
|
63
|
+
const lq = { apiVersion: v, metadata: { name: 'lq', namespace: 'team', generation: 1 }, spec: { clusterQueue: 'parent' }, status: { conditions: [active('True', 'Ready')] } }
|
|
64
|
+
await render(<LocalQueueRenderer data={lq} />, () => expect(element.textContent).toContain('every namespace matches'))
|
|
65
|
+
expect(requests).not.toContain('/api/resources/namespaces/_/team')
|
|
66
|
+
await act(async () => root.unmount())
|
|
67
|
+
root = createRoot(element)
|
|
68
|
+
client.clear()
|
|
69
|
+
queues = [cq('parent', undefined, active('True', 'Ready'), { namespaceSelector: { matchLabels: { team: 'a' } } })]
|
|
70
|
+
await render(<LocalQueueRenderer data={lq} />, () => expect(element.textContent).toContain('labels match the selector'))
|
|
71
|
+
expect(requests).toContain('/api/resources/namespaces/_/team')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('tones the header badge like the detail when the ClusterQueue reports Stopped', async () => {
|
|
75
|
+
queues = [cq('parent', undefined, { ...active('False', 'Stopped'), message: "Can't admit new workloads: is stopped." }, { stopPolicy: 'Hold' })]
|
|
76
|
+
const lq = { apiVersion: v, metadata: { name: 'lq', namespace: 'team', generation: 1 }, spec: { clusterQueue: 'parent' }, status: { conditions: [active('False', 'ClusterQueueIsInactive')] } }
|
|
77
|
+
await render(<LocalQueueStatusBadge data={lq} />, () => expect(element.querySelector('.badge')?.className).toContain('status-neutral'))
|
|
78
|
+
expect(requests).toContain('/api/resources/clusterqueues')
|
|
79
|
+
expect(element.textContent).toBe('ClusterQueueIsInactive')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('keeps the header badge alert when the stopped ClusterQueue reports other causes too', async () => {
|
|
83
|
+
queues = [cq('parent', undefined, { ...active('False', 'Stopped'), message: "Can't admit new workloads: is stopped, references missing ResourceFlavor(s): x." }, { stopPolicy: 'Hold' })]
|
|
84
|
+
const lq = { apiVersion: v, metadata: { name: 'lq', namespace: 'team', generation: 1 }, spec: { clusterQueue: 'parent' }, status: { conditions: [active('False', 'ClusterQueueIsInactive')] } }
|
|
85
|
+
await render(<LocalQueueStatusBadge data={lq} />, () => expect(element.querySelector('.badge')?.className).toContain('status-alert'))
|
|
86
|
+
expect(requests).toContain('/api/resources/clusterqueues')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('follows a Workload to its LocalQueue and that LocalQueue’s ClusterQueue through list reads', async () => {
|
|
90
|
+
queues = [cq('parent', undefined, active('True', 'Ready'), { namespaceSelector: {} })]
|
|
91
|
+
const workload = { apiVersion: v, kind: 'Workload', metadata: { name: 'w', namespace: 'team', generation: 1, uid: 'u' }, spec: { queueName: 'lq' }, status: {} }
|
|
92
|
+
await render(<KueueWorkloadRenderer data={workload} />, () => expect(element.textContent).toContain('Configured by LocalQueue lq'))
|
|
93
|
+
expect(requests).toEqual(expect.arrayContaining(['/api/resources/localqueues', '/api/resources/clusterqueues']))
|
|
94
|
+
expect(requests.filter(path => path.startsWith('/api/resources/') && path.split('/').length > 4)).toEqual([])
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
for (const kind of ['LocalQueue', 'Workload'] as const) {
|
|
98
|
+
it(`holds Namespace labels until a new read settles after ${kind} state changes`, async () => {
|
|
99
|
+
queues = [cq('parent', undefined, active('True', 'Ready'), { namespaceSelector: { matchLabels: { team: 'a' } } })]
|
|
100
|
+
const data = { apiVersion: v, kind, metadata: { name: 'lq', namespace: 'team', generation: 1, uid: 'subject' }, spec: { queueName: 'lq', clusterQueue: 'parent' }, status: { conditions: [active('True', 'Ready')] } }
|
|
101
|
+
const node = (value: any) => kind === 'LocalQueue' ? <LocalQueueRenderer data={value} /> : <KueueWorkloadRenderer data={value} />
|
|
102
|
+
await render(node(data), () => expect(element.textContent).toContain('labels match the selector'))
|
|
103
|
+
const original = vi.mocked(fetch).getMockImplementation()!
|
|
104
|
+
const pending: (() => void)[] = []
|
|
105
|
+
vi.mocked(fetch).mockImplementation((input: any, init?: any) => {
|
|
106
|
+
if (String(input).includes('/namespaces/_/team')) return new Promise<Response>(resolve => {
|
|
107
|
+
pending.push(() => resolve(new Response(JSON.stringify({ resource: { metadata: { name: 'team', labels: { team: 'b' } } } }))))
|
|
108
|
+
})
|
|
109
|
+
return original(input, init)
|
|
110
|
+
})
|
|
111
|
+
const changed = { ...data, status: { conditions: [kind === 'LocalQueue' ? active('False', 'ClusterQueueIsInactive') : { type: 'QuotaReserved', status: 'False', reason: 'Pending', observedGeneration: 1 }] } }
|
|
112
|
+
await render(node(changed), () => expect(pending.length).toBeGreaterThan(0))
|
|
113
|
+
expect(element.textContent).not.toContain('labels match the selector')
|
|
114
|
+
await act(async () => pending[0]())
|
|
115
|
+
await vi.waitFor(() => expect(element.textContent).toContain('labels don’t match the selector'))
|
|
116
|
+
})
|
|
117
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { ClusterQueueRenderer } from './KueueQueueRenderers'
|
|
7
|
+
|
|
8
|
+
const queue = { apiVersion: 'kueue.x-k8s.io/v1beta2', kind: 'ClusterQueue', metadata: { name: 'cq', uid: 'cq-uid' }, spec: {} }
|
|
9
|
+
|
|
10
|
+
const json = (body: unknown, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } })
|
|
11
|
+
const page = (names: string[], next?: string, uid = 'cq-uid') => ({
|
|
12
|
+
queue: { kind: 'ClusterQueue', name: 'cq', uid },
|
|
13
|
+
workloads: {
|
|
14
|
+
items: names.map(name => ({ namespace: 'team-a', name, uid: name, apiVersion: 'kueue.x-k8s.io/v1beta2', createdAt: null, deleting: false, membership: ['reservation'] })),
|
|
15
|
+
matching: 3, counts: { members: 3, submission: 0, reservation: 3 }, next,
|
|
16
|
+
coverage: { status: 'complete', scope: { type: 'all_namespaces' }, read: { type: 'all_namespaces' }, gaps: [] },
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
let requests: string[]
|
|
21
|
+
let host: HTMLDivElement
|
|
22
|
+
let root: Root
|
|
23
|
+
|
|
24
|
+
function serve(answer: (cursor: string | null) => Response) {
|
|
25
|
+
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
|
26
|
+
const url = new URL(input, 'http://localhost')
|
|
27
|
+
if (url.pathname.endsWith('/capabilities')) return json({ features: { kueueQueueWorkloads: true } })
|
|
28
|
+
if (url.pathname.endsWith('/version')) return json({ currentVersion: 'v1.20.0' })
|
|
29
|
+
requests.push(url.search)
|
|
30
|
+
return answer(url.searchParams.get('cursor'))
|
|
31
|
+
}))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const mount = async (client: QueryClient) => {
|
|
35
|
+
root = createRoot(host)
|
|
36
|
+
await act(async () => { root.render(<QueryClientProvider client={client}><ClusterQueueRenderer data={queue} /></QueryClientProvider>) })
|
|
37
|
+
}
|
|
38
|
+
const text = () => host.textContent ?? ''
|
|
39
|
+
const loadMore = async () => {
|
|
40
|
+
const button = [...host.querySelectorAll('button')].find(b => b.textContent === 'Load more')
|
|
41
|
+
expect(button).toBeDefined()
|
|
42
|
+
await act(async () => { button!.click() })
|
|
43
|
+
}
|
|
44
|
+
const firstPageReads = () => requests.filter(search => !search.includes('cursor=')).length
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
48
|
+
requests = []
|
|
49
|
+
host = document.createElement('div')
|
|
50
|
+
})
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
act(() => root?.unmount())
|
|
53
|
+
vi.unstubAllGlobals()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('reads the list again from its first page when the next page\'s cursor is refused', async () => {
|
|
57
|
+
serve(cursor => cursor
|
|
58
|
+
? json({ error: 'the cursor belongs to another list', error_code: 'kueue_cursor_invalid' }, 400)
|
|
59
|
+
: json(page(['wl-a', 'wl-b'], 'next-1')))
|
|
60
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
61
|
+
await mount(client)
|
|
62
|
+
await vi.waitFor(() => expect(text()).toContain('wl-a'))
|
|
63
|
+
const before = firstPageReads()
|
|
64
|
+
await loadMore()
|
|
65
|
+
await vi.waitFor(() => expect(text()).toContain('The list restarted from its first page.'))
|
|
66
|
+
await vi.waitFor(() => expect(firstPageReads()).toBe(before + 1))
|
|
67
|
+
expect(text()).toContain('wl-b')
|
|
68
|
+
expect(text()).not.toContain('Could not read the next page')
|
|
69
|
+
client.clear()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('keeps reading rather than reporting an empty list while the answer is for another queue with the same name', async () => {
|
|
73
|
+
serve(() => json(page([], undefined, 'earlier-uid')))
|
|
74
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
75
|
+
await mount(client)
|
|
76
|
+
await vi.waitFor(() => expect(requests.length).toBeGreaterThan(0))
|
|
77
|
+
await act(async () => {})
|
|
78
|
+
expect(text()).toContain('Reading Workloads…')
|
|
79
|
+
expect(text()).not.toMatch(/No Workloads/)
|
|
80
|
+
client.clear()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('reopening a paged list reads its first page once instead of replaying every page', async () => {
|
|
84
|
+
serve(cursor => json(cursor ? page(['wl-c']) : page(['wl-a', 'wl-b'], 'next-1')))
|
|
85
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
86
|
+
await mount(client)
|
|
87
|
+
await vi.waitFor(() => expect(text()).toContain('wl-a'))
|
|
88
|
+
await loadMore()
|
|
89
|
+
await vi.waitFor(() => expect(text()).toContain('wl-c'))
|
|
90
|
+
act(() => root.unmount())
|
|
91
|
+
const before = requests.length
|
|
92
|
+
await mount(client)
|
|
93
|
+
await vi.waitFor(() => expect(text()).toContain('wl-a'))
|
|
94
|
+
await vi.waitFor(() => expect(text()).not.toContain('wl-c'))
|
|
95
|
+
expect(requests.slice(before)).toEqual([''])
|
|
96
|
+
client.clear()
|
|
97
|
+
})
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import type { ResourceRef } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import {
|
|
5
|
+
ClusterQueueRenderer as BaseClusterQueueRenderer,
|
|
6
|
+
LocalQueueRenderer as BaseLocalQueueRenderer,
|
|
7
|
+
clusterQueueRelatedNames,
|
|
8
|
+
type ClusterQueueReads,
|
|
9
|
+
} from '@skyhook-io/k8s-ui/components/resources/renderers/KueueQueueRenderers'
|
|
10
|
+
import { getClusterQueueCohort, isKueueQueueResource } from '@skyhook-io/k8s-ui/components/resources/resource-utils-kueue'
|
|
11
|
+
import { needsNamespaceLabels } from '@skyhook-io/k8s-ui/components/kueue/eligibility'
|
|
12
|
+
import { localQueueStatusWithParent } from '@skyhook-io/k8s-ui/components/kueue/queue-status'
|
|
13
|
+
import type { RelatedRead } from '@skyhook-io/k8s-ui/components/kueue/related-read'
|
|
14
|
+
import { KUEUE_GROUP } from '@skyhook-io/k8s-ui/components/kueue/constants'
|
|
15
|
+
import { relatedReadKey, useRelatedObjects, useRelatedReads } from '../../kueue/useRelatedReads'
|
|
16
|
+
import { KueueQueueWorkloads } from '@skyhook-io/k8s-ui/components/resources/renderers/KueueQueueWorkloads'
|
|
17
|
+
import type { KueueQueueMembership } from '@skyhook-io/k8s-ui/types/kueue-queues'
|
|
18
|
+
import { useKueueQueueWorkloads } from '../../../api/client'
|
|
19
|
+
|
|
20
|
+
type Navigate = (ref: ResourceRef) => void
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
data: any
|
|
24
|
+
onNavigate?: (ref: ResourceRef) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function QueueWorkloads({ kind, data, onNavigate }: Props & { kind: 'ClusterQueue' | 'LocalQueue' }) {
|
|
28
|
+
const [membership, setMembership] = useState<KueueQueueMembership | undefined>()
|
|
29
|
+
const [state, setState] = useState<string | undefined>()
|
|
30
|
+
const [restarted, setRestarted] = useState<string | null>(null)
|
|
31
|
+
const query = useKueueQueueWorkloads(
|
|
32
|
+
{ kind, namespace: data.metadata?.namespace, name: data.metadata?.name ?? '', uid: data.metadata?.uid },
|
|
33
|
+
{ membership, state },
|
|
34
|
+
)
|
|
35
|
+
// A cached list of an earlier queue with the same name is never shown.
|
|
36
|
+
const pages = query.data?.pages.filter(page => page.queue.uid === data.metadata?.uid)
|
|
37
|
+
const cursorRejected = (query.error as { data?: { error_code?: string } } | null)?.data?.error_code === 'kueue_cursor_invalid'
|
|
38
|
+
const { refetch } = query
|
|
39
|
+
const queryClient = useQueryClient()
|
|
40
|
+
// Refresh reads the list again from its first page, dropping the pages
|
|
41
|
+
// loaded since: replaying them all would reread the queue once per page.
|
|
42
|
+
const restart = () => void queryClient.resetQueries({ queryKey: ['kueue-queue-workloads', kind, data.metadata?.namespace ?? '', data.metadata?.name ?? '', data.metadata?.uid ?? ''] })
|
|
43
|
+
// Reopening a queue whose list was paged reads it again from the first
|
|
44
|
+
// page: the loaded pages aren't polled, so they could be stale.
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if ((query.data?.pages.length ?? 0) > 1) restart()
|
|
47
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- on mount only
|
|
48
|
+
}, [])
|
|
49
|
+
// A cursor issued for another list (a re-created queue, another cluster
|
|
50
|
+
// context) is refused: read the list again from its first page.
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (cursorRejected) setRestarted('restarted')
|
|
53
|
+
if (cursorRejected) void queryClient.resetQueries({ queryKey: ['kueue-queue-workloads', kind, data.metadata?.namespace ?? '', data.metadata?.name ?? '', data.metadata?.uid ?? ''] })
|
|
54
|
+
}, [cursorRejected, queryClient, kind, data.metadata?.namespace, data.metadata?.name, data.metadata?.uid])
|
|
55
|
+
return (
|
|
56
|
+
<KueueQueueWorkloads
|
|
57
|
+
kind={kind}
|
|
58
|
+
queue={data}
|
|
59
|
+
pages={pages?.length ? pages : undefined}
|
|
60
|
+
// A response for a re-created queue's predecessor (or successor) is
|
|
61
|
+
// still being replaced: keep reading rather than claim nothing was read.
|
|
62
|
+
loading={query.isPending || (!!query.data && !pages?.length)}
|
|
63
|
+
error={query.error ? query.error.message : null}
|
|
64
|
+
nextPageError={query.isFetchNextPageError ? query.error?.message ?? null : null}
|
|
65
|
+
stale={query.isPlaceholderData}
|
|
66
|
+
notice={restarted ? 'The list restarted from its first page.' : null}
|
|
67
|
+
upgrade={query.upgrade}
|
|
68
|
+
membership={membership}
|
|
69
|
+
onMembershipChange={next => { setRestarted(null); setMembership(next) }}
|
|
70
|
+
state={state}
|
|
71
|
+
onStateChange={next => { setRestarted(null); setState(next) }}
|
|
72
|
+
hasMore={query.hasNextPage}
|
|
73
|
+
loadingMore={query.isFetchingNextPage}
|
|
74
|
+
onLoadMore={() => { setRestarted(null); void query.fetchNextPage() }}
|
|
75
|
+
onRetry={() => { setRestarted(null); if (pages && pages.length > 1) restart(); else void refetch() }}
|
|
76
|
+
onNavigate={onNavigate}
|
|
77
|
+
/>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Keyed by UID so moving the drawer to another queue starts its reads (and their mount time) afresh.
|
|
82
|
+
export function LocalQueueRenderer({ data, onNavigate }: { data: any; onNavigate?: Navigate }) {
|
|
83
|
+
return <LocalQueueReads key={data.metadata?.uid} data={data} onNavigate={onNavigate} />
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function LocalQueueReads({ data, onNavigate }: { data: any; onNavigate?: Navigate }) {
|
|
87
|
+
const parentName: string = data.spec?.clusterQueue ?? ''
|
|
88
|
+
const namespace: string = data.metadata?.namespace ?? ''
|
|
89
|
+
const subjectKey = relatedReadKey(data, [parentName], ['Active'])
|
|
90
|
+
const parentRead = useRelatedObjects('clusterqueues', KUEUE_GROUP, undefined, [parentName], !!parentName, subjectKey).byName[parentName]
|
|
91
|
+
const clusterQueue = parentName ? parentRead : undefined
|
|
92
|
+
const needsLabels = clusterQueue?.state === 'found' && needsNamespaceLabels(clusterQueue.object?.spec?.namespaceSelector)
|
|
93
|
+
const namespaceState = JSON.stringify([subjectKey, needsLabels, clusterQueue?.state === 'found' ? clusterQueue.object?.spec?.namespaceSelector : null])
|
|
94
|
+
const [namespaceRead] = useRelatedReads([{ kind: 'namespaces', name: namespace }], needsLabels && !!namespace, namespaceState)
|
|
95
|
+
return <BaseLocalQueueRenderer data={data} onNavigate={onNavigate} reads={{ clusterQueue, namespace: needsLabels ? namespaceRead : undefined }} workloads={<QueueWorkloads kind="LocalQueue" data={data} onNavigate={onNavigate} />} />
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function ClusterQueueRenderer({ data, onNavigate }: { data: any; onNavigate?: Navigate }) {
|
|
99
|
+
return <ClusterQueueReads key={data.metadata?.uid} data={data} onNavigate={onNavigate} />
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function ClusterQueueReads({ data, onNavigate }: { data: any; onNavigate?: Navigate }) {
|
|
103
|
+
const names = useMemo(() => clusterQueueRelatedNames(data), [data])
|
|
104
|
+
const cohort = getClusterQueueCohort(data)
|
|
105
|
+
const subjectKey = relatedReadKey(data, [...names.flavors, ...names.admissionChecks], ['Active'])
|
|
106
|
+
const flavors = useRelatedObjects('resourceflavors', KUEUE_GROUP, undefined, names.flavors, names.flavors.length > 0, subjectKey)
|
|
107
|
+
const checks = useRelatedObjects('admissionchecks', KUEUE_GROUP, undefined, names.admissionChecks, names.admissionChecks.length > 0, subjectKey)
|
|
108
|
+
const queues = useRelatedObjects('clusterqueues', KUEUE_GROUP, undefined, [], cohort !== '-', relatedReadKey(data, [cohort], ['Active']))
|
|
109
|
+
const members: RelatedRead<string[]> | undefined = cohort === '-' ? undefined
|
|
110
|
+
: queues.all.state !== 'found' ? queues.all as RelatedRead<string[]>
|
|
111
|
+
: {
|
|
112
|
+
state: 'found',
|
|
113
|
+
object: queues.all.object
|
|
114
|
+
.filter(queue => queue?.metadata?.name !== data.metadata?.name && getClusterQueueCohort(queue) === cohort)
|
|
115
|
+
.map(queue => String(queue.metadata.name))
|
|
116
|
+
.sort(),
|
|
117
|
+
}
|
|
118
|
+
const reads: ClusterQueueReads = {
|
|
119
|
+
flavors: flavors.byName,
|
|
120
|
+
admissionChecks: checks.byName,
|
|
121
|
+
cohortMembers: members,
|
|
122
|
+
cohortMembersCompleteness: queues.completeness,
|
|
123
|
+
}
|
|
124
|
+
return <BaseClusterQueueRenderer data={data} onNavigate={onNavigate} reads={reads} workloads={<QueueWorkloads kind="ClusterQueue" data={data} onNavigate={onNavigate} />} />
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The header badge: the LocalQueue's own report, toned like its detail by the ClusterQueue it names. */
|
|
128
|
+
export function LocalQueueStatusBadge({ data }: { data: any }) {
|
|
129
|
+
return <LocalQueueBadgeReads key={data?.metadata?.uid} data={data} />
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function LocalQueueBadgeReads({ data }: { data: any }) {
|
|
133
|
+
const parentName: string = data?.spec?.clusterQueue ?? ''
|
|
134
|
+
const supported = isKueueQueueResource(data)
|
|
135
|
+
const parentRead = useRelatedObjects('clusterqueues', KUEUE_GROUP, undefined, [parentName], supported && !!parentName, relatedReadKey(data, [parentName], ['Active'])).byName[parentName]
|
|
136
|
+
const parent = parentName ? parentRead : undefined
|
|
137
|
+
const status = localQueueStatusWithParent(data, supported ? parent : undefined)
|
|
138
|
+
return <span className={`badge whitespace-nowrap ${status.color}`}>{status.text}</span>
|
|
139
|
+
}
|
|
@@ -3,7 +3,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
3
3
|
import { KueueWorkloadRenderer } from './KueueWorkloadRenderer'
|
|
4
4
|
|
|
5
5
|
const mock = vi.hoisted(() => ({ query: {} as any }))
|
|
6
|
-
vi.mock('../../../api/client', () => ({ useKueueProvisioning: () => mock.query }))
|
|
6
|
+
vi.mock('../../../api/client', () => ({ useKueueProvisioning: () => mock.query, useKueuePendingPosition: () => ({ isPending: false, refetch: vi.fn() }) }))
|
|
7
|
+
// The admission-path reads have their own tests; here they stay unread.
|
|
8
|
+
vi.mock('../../kueue/useRelatedReads', () => ({
|
|
9
|
+
relatedReadKey: () => '',
|
|
10
|
+
useRelatedObjects: () => ({ byName: {}, all: { state: 'loading' }, completeness: 'unknown' }),
|
|
11
|
+
useRelatedReads: (refs: unknown[]) => refs.map(() => ({ state: 'loading' })),
|
|
12
|
+
}))
|
|
7
13
|
const data = { metadata: { name: 'work', namespace: 'ml', uid: 'new' }, status: { admissionChecks: [{ name: 'capacity', state: 'Rejected', message: 'Capacity unavailable' }] } }
|
|
8
14
|
const render = () => renderToStaticMarkup(<KueueWorkloadRenderer data={data} />)
|
|
9
15
|
|