@skyhook-io/radar-app 1.22.2 → 1.23.1
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 +8 -8
- package/src/App.tsx +49 -13
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +151 -27
- package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/poll.ts +78 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +16 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +315 -0
- package/src/api/workloadSource.ts +128 -12
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +128 -32
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
- package/src/components/helm/HelmView.tsx +4 -3
- package/src/components/helm/ObservedHelmNotice.tsx +39 -17
- package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +3 -3
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +4 -4
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/issues/uncheckedSources.test.ts +8 -0
- package/src/components/issues/uncheckedSources.ts +3 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/nudges/activeNudges.test.ts +39 -0
- package/src/components/nudges/activeNudges.ts +76 -0
- package/src/components/poll/OssPoll.tsx +871 -0
- package/src/components/poll/mount.test.ts +12 -0
- package/src/components/poll/pollCloud.test.ts +23 -0
- package/src/components/poll/pollCloud.ts +6 -0
- package/src/components/poll/pollDefinition.ts +93 -0
- package/src/components/poll/pollFlow.test.ts +140 -0
- package/src/components/poll/pollFlow.ts +137 -0
- package/src/components/poll/pollSender.test.ts +137 -0
- package/src/components/poll/pollSender.ts +76 -0
- package/src/components/poll/pollStorage.test.ts +53 -0
- package/src/components/poll/pollStorage.ts +77 -0
- package/src/components/poll/round.json +350 -0
- package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
- package/src/components/resources/ImageFilesystemModal.tsx +42 -3
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +24 -11
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/ui/UpdateNotification.tsx +2 -0
- package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/whats-new/WhatsNew.tsx +2 -0
- package/src/components/whats-new/releaseNotes.ts +75 -1
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +52 -13
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { WorkspaceScreenProps } from '../../integrations/workspaceRoute'
|
|
2
|
+
import { useAPIResources } from '../../api/apiResources'
|
|
3
|
+
import { useMediaQuery } from '../../hooks/useMediaQuery'
|
|
4
|
+
import { useIntegrationSidebars } from '../../integrations/sidebarWorkspaces'
|
|
5
|
+
import { WorkspaceFrame } from '../workspace/WorkspaceFrame'
|
|
6
|
+
import { useWorkspaceDrawer } from '../workspace/useWorkspaceDrawer'
|
|
7
|
+
import { useAgentSandboxWorkspace } from '../../api/agentSandbox'
|
|
8
|
+
import { AgentSandboxOverview } from './AgentSandboxOverview'
|
|
9
|
+
import { agentSandboxDiscovered } from './data'
|
|
10
|
+
import { AgentSandboxWorkspaceGate } from './workspace'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The Agent Sandbox Overview, from the server's summary, inside Resources
|
|
14
|
+
* with the same sidebar. The namespace filter applies: Sandboxes, claims and
|
|
15
|
+
* warm pools live in the namespaces of the apps that use them. The controller
|
|
16
|
+
* is read in its own namespace whatever the filter.
|
|
17
|
+
*/
|
|
18
|
+
export function AgentSandboxView({ namespaces, selectedResource, onOpenResource, onCloseResource, onClearNamespaces }: WorkspaceScreenProps) {
|
|
19
|
+
const compactNavigation = useMediaQuery('(max-width: 1100px)')
|
|
20
|
+
const { data: apiResources, isPending: discoveryPending, isError: discoveryFailed } = useAPIResources()
|
|
21
|
+
// Discovery that could not be read does not say Agent Sandbox is absent; the server is asked then.
|
|
22
|
+
const discovered = agentSandboxDiscovered(apiResources) || discoveryFailed
|
|
23
|
+
const query = useAgentSandboxWorkspace(namespaces, { enabled: discovered })
|
|
24
|
+
const sidebarWorkspace = useIntegrationSidebars({ apiResources, namespaces, agentSandbox: { active: true } })
|
|
25
|
+
const { drawerTarget, inspect } = useWorkspaceDrawer({ selectedResource, onOpenResource, onCloseResource })
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<WorkspaceFrame namespaces={namespaces} categoryWorkspaces={sidebarWorkspace} compactNavigation={compactNavigation}>
|
|
29
|
+
<AgentSandboxWorkspaceGate query={query} discoveryPending={discoveryPending} discovered={discovered}>
|
|
30
|
+
{(data) => <AgentSandboxOverview data={data} onClearNamespaces={onClearNamespaces} onInspect={inspect} inspected={drawerTarget} />}
|
|
31
|
+
</AgentSandboxWorkspaceGate>
|
|
32
|
+
</WorkspaceFrame>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Shaped from the objects a real agent-sandbox controller (v1.0.11) wrote on a
|
|
2
|
+
// test cluster: nine Sandboxes in mixed states, two claims, one template and
|
|
3
|
+
// one warm pool short of ready. Times are relative to now.
|
|
4
|
+
import type { ResourceCoverage } from '@skyhook-io/k8s-ui/types/resource-coverage'
|
|
5
|
+
import type { AgentSandboxLists, KindRead } from './data'
|
|
6
|
+
|
|
7
|
+
export const NS = 'radar-agents-live'
|
|
8
|
+
|
|
9
|
+
export const minutesAgo = (m: number) => new Date(Date.now() - m * 60_000).toISOString()
|
|
10
|
+
export const hoursAgo = (h: number) => minutesAgo(h * 60)
|
|
11
|
+
|
|
12
|
+
export const COMPLETE: ResourceCoverage = { status: 'complete', scope: { type: 'all_namespaces' }, read: { type: 'all_namespaces' }, gaps: [] }
|
|
13
|
+
export const PARTIAL: ResourceCoverage = {
|
|
14
|
+
status: 'partial',
|
|
15
|
+
scope: { type: 'all_namespaces' },
|
|
16
|
+
read: { type: 'namespaces', namespaces: { count: 1, names: [NS] } },
|
|
17
|
+
gaps: [{ code: 'user_forbidden', namespaces: { count: 1, names: ['team-b'] } }],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const cond = (type: string, status: string, reason: string, message = '', at = hoursAgo(40)) => ({ type, status, reason, message, lastTransitionTime: at, observedGeneration: 1 })
|
|
21
|
+
const notSuspended = (at = hoursAgo(40)) => cond('Suspended', 'False', 'NotSuspended', 'Sandbox is not suspended', at)
|
|
22
|
+
|
|
23
|
+
export function sandbox(name: string, opts: { conditions?: any[]; spec?: any; annotations?: any; ownerReferences?: any[]; labels?: any; created?: string; nodeName?: string; namespace?: string } = {}): any {
|
|
24
|
+
return {
|
|
25
|
+
apiVersion: 'agents.x-k8s.io/v1beta1',
|
|
26
|
+
kind: 'Sandbox',
|
|
27
|
+
metadata: {
|
|
28
|
+
name,
|
|
29
|
+
namespace: opts.namespace ?? NS,
|
|
30
|
+
generation: 1,
|
|
31
|
+
creationTimestamp: opts.created ?? hoursAgo(40),
|
|
32
|
+
...(opts.annotations ? { annotations: opts.annotations } : {}),
|
|
33
|
+
...(opts.labels ? { labels: opts.labels } : {}),
|
|
34
|
+
...(opts.ownerReferences ? { ownerReferences: opts.ownerReferences } : {}),
|
|
35
|
+
},
|
|
36
|
+
spec: { failedPodPolicy: 'Retain', operatingMode: 'Running', shutdownPolicy: 'Retain', ...opts.spec },
|
|
37
|
+
status: { conditions: opts.conditions ?? [], ...(opts.nodeName ? { nodeName: opts.nodeName } : {}) },
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const POOL_UID = '26a86a25-f249-44ca-9cbc-2139d29b66ba'
|
|
42
|
+
const poolOwner = [{ apiVersion: 'extensions.agents.x-k8s.io/v1beta1', kind: 'SandboxWarmPool', name: 'warm', uid: POOL_UID, controller: true, blockOwnerDeletion: true }]
|
|
43
|
+
const UNSCHEDULABLE = '0/4 nodes are available: 4 Too many pods. no new claims to deallocate, preemption: 0/4 nodes are available: 4 No preemption victims found for incoming pod.'
|
|
44
|
+
|
|
45
|
+
export const ready = (name: string, opts: Parameters<typeof sandbox>[1] = {}) =>
|
|
46
|
+
sandbox(name, { ...opts, conditions: [notSuspended(), cond('PodScheduled', 'True', 'PodScheduled'), cond('Ready', 'True', 'DependenciesReady', 'Pod is Ready; Service Exists')], nodeName: 'node-a' })
|
|
47
|
+
|
|
48
|
+
export function warmMember(name: string, sinceMinutes: number): any {
|
|
49
|
+
const at = minutesAgo(sinceMinutes)
|
|
50
|
+
return sandbox(name, {
|
|
51
|
+
created: at,
|
|
52
|
+
annotations: { 'agents.x-k8s.io/sandbox-template-ref': 'tmpl' },
|
|
53
|
+
labels: { 'agents.x-k8s.io/launch-type': 'warm' },
|
|
54
|
+
ownerReferences: poolOwner,
|
|
55
|
+
conditions: [notSuspended(at), cond('PodScheduled', 'False', 'Unschedulable', UNSCHEDULABLE, at), cond('Ready', 'False', 'DependenciesNotReady', 'Pod exists with phase: Pending', at)],
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function liveSandboxes(): any[] {
|
|
60
|
+
return [
|
|
61
|
+
sandbox('bad-image', {
|
|
62
|
+
nodeName: 'node-a',
|
|
63
|
+
conditions: [notSuspended(), cond('PodScheduled', 'True', 'PodScheduled'), cond('Ready', 'False', 'DependenciesNotReady', 'Pod exists with phase: Pending; container "agent" is waiting: ImagePullBackOff')],
|
|
64
|
+
}),
|
|
65
|
+
sandbox('expired', { spec: { shutdownTime: hoursAgo(41) }, conditions: [cond('Ready', 'False', 'SandboxExpired', 'Sandbox has expired')] }),
|
|
66
|
+
sandbox('failed', {
|
|
67
|
+
nodeName: 'node-a',
|
|
68
|
+
conditions: [notSuspended(), cond('PodScheduled', 'True', 'PodScheduled'), cond('Ready', 'False', 'PodFailed', 'Pod failed'), cond('Finished', 'True', 'PodFailed', 'Pod failed')],
|
|
69
|
+
}),
|
|
70
|
+
sandbox('finished', { conditions: [notSuspended(), cond('Ready', 'False', 'PodSucceeded', 'Pod completed successfully'), cond('Finished', 'True', 'PodSucceeded', 'Pod completed successfully')] }),
|
|
71
|
+
sandbox('foreign', {
|
|
72
|
+
spec: { operatingMode: 'Suspended' },
|
|
73
|
+
conditions: [cond('Suspended', 'False', 'PodNotOwned', 'Refused to delete pod because it is not owned by this sandbox'), cond('Ready', 'False', 'SandboxSuspended', 'Sandbox is suspending')],
|
|
74
|
+
}),
|
|
75
|
+
sandbox('running', { spec: { shutdownTime: hoursAgo(38) }, conditions: [notSuspended(), cond('Ready', 'False', 'SandboxExpired', 'Sandbox has expired', hoursAgo(38))] }),
|
|
76
|
+
sandbox('suspended', {
|
|
77
|
+
spec: { operatingMode: 'Suspended' },
|
|
78
|
+
conditions: [cond('Suspended', 'True', 'PodTerminated', 'Pod has been terminated. Sandbox is suspended'), cond('Ready', 'False', 'SandboxSuspended', 'Sandbox is suspended')],
|
|
79
|
+
}),
|
|
80
|
+
warmMember('warm-4xmkm', 9 * 60),
|
|
81
|
+
warmMember('warm-nd2zw', 4 * 60),
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function claim(name: string, opts: { pool?: string; reason?: string; message?: string; sandbox?: string; shutdownTime?: string; status?: string; namespace?: string } = {}): any {
|
|
86
|
+
return {
|
|
87
|
+
apiVersion: 'extensions.agents.x-k8s.io/v1beta1',
|
|
88
|
+
kind: 'SandboxClaim',
|
|
89
|
+
metadata: { name, namespace: opts.namespace ?? NS, generation: 1, creationTimestamp: hoursAgo(40) },
|
|
90
|
+
spec: { warmPoolRef: { name: opts.pool ?? 'warm' }, ...(opts.shutdownTime ? { lifecycle: { shutdownPolicy: 'Retain', shutdownTime: opts.shutdownTime } } : {}) },
|
|
91
|
+
status: {
|
|
92
|
+
conditions: [cond('Ready', opts.status ?? 'False', opts.reason ?? 'SandboxNotReady', opts.message ?? '')],
|
|
93
|
+
sandbox: opts.sandbox ? { name: opts.sandbox } : {},
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function liveClaims(): any[] {
|
|
99
|
+
return [
|
|
100
|
+
claim('claim-missing-pool', { pool: 'no-such-pool', reason: 'WarmPoolNotFound', message: 'SandboxWarmPool "no-such-pool" not found' }),
|
|
101
|
+
claim('claim-ok', { reason: 'ClaimExpired', message: 'Claim expired. Sandbox cleanup initiated.', shutdownTime: hoursAgo(38) }),
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function warmPool(name = 'warm', opts: { replicas?: number; readyReplicas?: number; current?: number; template?: string; created?: string; uid?: string; namespace?: string } = {}): any {
|
|
106
|
+
return {
|
|
107
|
+
apiVersion: 'extensions.agents.x-k8s.io/v1beta1',
|
|
108
|
+
kind: 'SandboxWarmPool',
|
|
109
|
+
metadata: { name, namespace: opts.namespace ?? NS, generation: 1, uid: opts.uid ?? POOL_UID, creationTimestamp: opts.created ?? hoursAgo(40) },
|
|
110
|
+
spec: { replicas: opts.replicas ?? 2, sandboxTemplateRef: { name: opts.template ?? 'tmpl' } },
|
|
111
|
+
status: { observedGeneration: 1, replicas: opts.current ?? 2, ...(opts.readyReplicas !== undefined ? { readyReplicas: opts.readyReplicas } : {}) },
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
export const read = (items: any[], coverage: ResourceCoverage = COMPLETE): KindRead => ({ state: 'read', items, coverage })
|
|
117
|
+
|
|
118
|
+
type Overrides = { [K in keyof AgentSandboxLists]?: KindRead | any[] }
|
|
119
|
+
|
|
120
|
+
/** The live cluster's objects as the kind lists read them, any kind replaced by a list or a read state. */
|
|
121
|
+
export function liveData(overrides: Overrides = {}): AgentSandboxLists {
|
|
122
|
+
const pick = (k: keyof AgentSandboxLists, fallback: any[]): KindRead => {
|
|
123
|
+
const v = overrides[k]
|
|
124
|
+
return Array.isArray(v) ? read(v) : (v as KindRead | undefined) ?? read(fallback)
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
sandboxes: pick('sandboxes', liveSandboxes()),
|
|
128
|
+
claims: pick('claims', liveClaims()),
|
|
129
|
+
warmPools: pick('warmPools', [warmPool()]),
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function emptyData(overrides: Overrides = {}): AgentSandboxLists {
|
|
134
|
+
return liveData({ sandboxes: [], claims: [], warmPools: [], ...overrides })
|
|
135
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useQueries } from '@tanstack/react-query'
|
|
3
|
+
import type { ResourceCoverage } from '@skyhook-io/k8s-ui/types/resource-coverage'
|
|
4
|
+
import { isLowerBound } from '@skyhook-io/k8s-ui/utils/resource-coverage'
|
|
5
|
+
import type { APIResource } from '../../types'
|
|
6
|
+
import { ApiError, fetchResourceList, isKindSyncFailed, isStillLoadingError, isUnretryableReadError } from '../../api/client'
|
|
7
|
+
import { createListRefetchInterval } from '../../api/resourceLists'
|
|
8
|
+
import { AGENT_SANDBOX_EXTENSIONS_GROUP, AGENT_SANDBOX_GROUP, SANDBOX_CLAIM_KIND, SANDBOX_KIND, SANDBOX_WARM_POOL_KIND } from './routes'
|
|
9
|
+
|
|
10
|
+
// The kind lists (Radar's tables for Sandboxes, claims and warm pools) read
|
|
11
|
+
// Radar's resource list endpoint, with its coverage. The Overview, Needs
|
|
12
|
+
// attention and the sidebar's badges come from /api/agentsandbox/workspace.
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* One kind as Radar's list endpoint answered it. `failed` keeps why, so a
|
|
16
|
+
* denied or unread kind is named and never counted as empty.
|
|
17
|
+
*/
|
|
18
|
+
export type KindRead =
|
|
19
|
+
| { state: 'loading' }
|
|
20
|
+
| { state: 'read'; items: any[]; coverage: ResourceCoverage }
|
|
21
|
+
| { state: 'failed'; message: string; denied: boolean }
|
|
22
|
+
/** Discovery does not serve the kind: its CRD is not installed. */
|
|
23
|
+
| { state: 'notServed' }
|
|
24
|
+
|
|
25
|
+
export interface AgentSandboxLists {
|
|
26
|
+
sandboxes: KindRead
|
|
27
|
+
claims: KindRead
|
|
28
|
+
warmPools: KindRead
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type AgentSandboxListKey = keyof AgentSandboxLists
|
|
32
|
+
|
|
33
|
+
export function agentSandboxDiscovered(apiResources: APIResource[] | undefined): boolean {
|
|
34
|
+
return !!apiResources?.some((r) => r.group === AGENT_SANDBOX_GROUP || r.group === AGENT_SANDBOX_EXTENSIONS_GROUP)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function readItems(read: KindRead): any[] {
|
|
38
|
+
return read.state === 'read' ? read.items : []
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether Radar read the kind in full in one namespace, so an object missing
|
|
43
|
+
* from it there is absent rather than unread. A Radar that predates coverage
|
|
44
|
+
* says nothing about it.
|
|
45
|
+
*/
|
|
46
|
+
export function readInNamespace(read: KindRead, namespace: string): boolean {
|
|
47
|
+
if (read.state === 'notServed') return true
|
|
48
|
+
if (read.state !== 'read') return false
|
|
49
|
+
const c = read.coverage
|
|
50
|
+
if (c.status === 'unknown') return false
|
|
51
|
+
if (c.status === 'partial') return !!c.read?.namespaces?.names?.includes(namespace)
|
|
52
|
+
if (c.scope.type === 'namespaces' || isLowerBound(c)) return !!c.scope.namespaces?.names?.includes(namespace)
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const KINDS = [
|
|
57
|
+
['sandboxes', SANDBOX_KIND],
|
|
58
|
+
['claims', SANDBOX_CLAIM_KIND],
|
|
59
|
+
['warmPools', SANDBOX_WARM_POOL_KIND],
|
|
60
|
+
] as const
|
|
61
|
+
|
|
62
|
+
function served(apiResources: APIResource[] | undefined, kind: { name: string; group: string }): boolean {
|
|
63
|
+
// Discovery not answered (or failed) is not "not installed": the list endpoint is asked.
|
|
64
|
+
return !apiResources || apiResources.some((r) => r.group === kind.group && r.name === kind.name)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function errorMessage(error: unknown): string {
|
|
68
|
+
return error instanceof Error ? error.message : 'request failed'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isDenied(error: unknown): boolean {
|
|
72
|
+
return error instanceof ApiError && (error.status === 403 || error.data?.error_code === 'user_forbidden')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const REFRESH_MS = 30_000
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Under the `['resources', plural]` prefix that writes and live events
|
|
79
|
+
* invalidate. The 'agent-sandbox' segment sits where the standard list keys
|
|
80
|
+
* hold the group, which is never that, so neither reads the other's entry.
|
|
81
|
+
*/
|
|
82
|
+
export function agentSandboxListKey(kind: { name: string; group: string }, nsKey: string) {
|
|
83
|
+
return ['resources', kind.name, 'agent-sandbox', kind.group, nsKey] as const
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The three listed kinds, read with the namespace filter applied. */
|
|
87
|
+
export function useAgentSandboxLists({
|
|
88
|
+
namespaces,
|
|
89
|
+
apiResources,
|
|
90
|
+
enabled = true,
|
|
91
|
+
}: {
|
|
92
|
+
namespaces: string[]
|
|
93
|
+
apiResources: APIResource[] | undefined
|
|
94
|
+
enabled?: boolean
|
|
95
|
+
}) {
|
|
96
|
+
const nsKey = [...namespaces].sort().join(',')
|
|
97
|
+
const intervals = useMemo(() => KINDS.map(() => createListRefetchInterval(REFRESH_MS)), [])
|
|
98
|
+
const queries = useQueries({
|
|
99
|
+
queries: KINDS.map(([, kind], i) => ({
|
|
100
|
+
queryKey: agentSandboxListKey(kind, nsKey),
|
|
101
|
+
queryFn: ({ signal }: { signal: AbortSignal }) => fetchResourceList<any>(kind.name, { namespaces: nsKey ? nsKey.split(',') : [], group: kind.group, signal }),
|
|
102
|
+
enabled: enabled && served(apiResources, kind),
|
|
103
|
+
staleTime: REFRESH_MS,
|
|
104
|
+
refetchInterval: intervals[i],
|
|
105
|
+
retry: (failureCount: number, error: unknown) => {
|
|
106
|
+
if (isStillLoadingError(error)) return true
|
|
107
|
+
if (isKindSyncFailed(error) || isUnretryableReadError(error) || isDenied(error)) return false
|
|
108
|
+
return failureCount < 1
|
|
109
|
+
},
|
|
110
|
+
retryDelay: (failureCount: number, error: unknown) => (isStillLoadingError(error) ? 2000 : Math.min(1000 * 2 ** failureCount, 30000)),
|
|
111
|
+
})),
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const [s, c, w] = queries
|
|
115
|
+
const data: AgentSandboxLists = useMemo(() => {
|
|
116
|
+
const read = (i: number, q: (typeof queries)[number]): KindRead => {
|
|
117
|
+
if (apiResources && !served(apiResources, KINDS[i][1])) return { state: 'notServed' }
|
|
118
|
+
if (q.data) return { state: 'read', items: q.data.items ?? [], coverage: q.data.coverage }
|
|
119
|
+
if (q.error) return { state: 'failed', message: errorMessage(q.error), denied: isDenied(q.error) }
|
|
120
|
+
return { state: 'loading' }
|
|
121
|
+
}
|
|
122
|
+
return { sandboxes: read(0, s), claims: read(1, c), warmPools: read(2, w) }
|
|
123
|
+
// The query results are new objects each render; their data and errors are stable.
|
|
124
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
125
|
+
}, [s.data, s.error, c.data, c.error, w.data, w.error, apiResources])
|
|
126
|
+
const refetch = () => {
|
|
127
|
+
for (const q of queries) void q.refetch()
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
data,
|
|
131
|
+
isFetching: queries.some((q) => q.isFetching),
|
|
132
|
+
refetch,
|
|
133
|
+
refreshQueries: queries.map((q) => ({ isRefetchError: q.isRefetchError, error: q.error, dataUpdatedAt: q.dataUpdatedAt })),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { composeResourceHosts } from '../../integrations/resourceHost'
|
|
3
|
+
import { resourceHosts } from '../../integrations/resourceHosts'
|
|
4
|
+
import { agentSandboxResourceHost } from './host'
|
|
5
|
+
import { agentSandboxWorkspaceRoute } from './workspaceRoute'
|
|
6
|
+
|
|
7
|
+
describe('Agent Sandbox registration', () => {
|
|
8
|
+
it('owns the three kind lists without colliding with another host', () => {
|
|
9
|
+
expect(resourceHosts).toContain(agentSandboxResourceHost)
|
|
10
|
+
expect(() => composeResourceHosts(resourceHosts)).not.toThrow()
|
|
11
|
+
expect(agentSandboxResourceHost.kindLists?.map((l) => `${l.kind.group}/${l.kind.name}`)).toEqual([
|
|
12
|
+
'agents.x-k8s.io/sandboxes',
|
|
13
|
+
'extensions.agents.x-k8s.io/sandboxclaims',
|
|
14
|
+
'extensions.agents.x-k8s.io/sandboxwarmpools',
|
|
15
|
+
])
|
|
16
|
+
// Read from the generic lists every Radar serves: no capability decides them.
|
|
17
|
+
for (const list of agentSandboxResourceHost.kindLists ?? []) expect(list.mode('unsupported', false)).toBe('view')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('applies the namespace filter and owns only its own path', () => {
|
|
21
|
+
expect(agentSandboxWorkspaceRoute.namespaceScope).toBe('view')
|
|
22
|
+
expect(agentSandboxWorkspaceRoute.namespaceFilterTooltip).toBeUndefined()
|
|
23
|
+
expect(agentSandboxWorkspaceRoute.pageTitle('/agent-sandbox')).toBe('Agent Sandbox overview')
|
|
24
|
+
expect(agentSandboxResourceHost.drawerNavigation?.ownsPath('/agent-sandbox')).toBe(true)
|
|
25
|
+
expect(agentSandboxResourceHost.drawerNavigation?.ownsPath('/agent-sandbox-other')).toBe(false)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Link, useLocation } from 'react-router-dom'
|
|
2
|
+
import type { DetailSlots, HostResource, ResourceHost } from '../../integrations/resourceHost'
|
|
3
|
+
import type { SelectedResource } from '../../types'
|
|
4
|
+
import { kindToPluralWithGroup, withCrossViewParams } from '../../utils/navigation'
|
|
5
|
+
import { DrawerTrailBack } from '../workspace/DrawerTrailBack'
|
|
6
|
+
import { AgentSandboxStatusBadge, AgentSandboxSummary, type AgentSandboxSummaryKind } from './AgentSandboxSummary'
|
|
7
|
+
import { SandboxClaimsKindList, SandboxWarmPoolsKindList, SandboxesKindList } from './AgentSandboxKindLists'
|
|
8
|
+
import { AGENT_SANDBOX_OVERVIEW, SANDBOX_CLAIM_KIND, SANDBOX_KIND, SANDBOX_TEMPLATE_KIND, SANDBOX_WARM_POOL_KIND, SANDBOXES_PATH, SANDBOX_CLAIMS_PATH, SANDBOX_WARM_POOLS_PATH, ownsAgentSandboxPath } from './routes'
|
|
9
|
+
|
|
10
|
+
// Read client-side from the generic list endpoint every Radar serves, so no
|
|
11
|
+
// capability gates them.
|
|
12
|
+
const always = () => 'view' as const
|
|
13
|
+
|
|
14
|
+
const KIND_BY_PLURAL: Record<string, string> = Object.fromEntries(
|
|
15
|
+
[SANDBOX_KIND, SANDBOX_CLAIM_KIND, SANDBOX_WARM_POOL_KIND, SANDBOX_TEMPLATE_KIND].map((k) => [k.name, k.kind]),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
function AgentSandboxDrawerTrailBack({ resource }: { resource: SelectedResource }) {
|
|
19
|
+
return <DrawerTrailBack resource={resource} pathPrefix={AGENT_SANDBOX_OVERVIEW.path} kindLabel={(plural) => KIND_BY_PLURAL[plural]} />
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DETAIL_LISTS = {
|
|
23
|
+
Sandbox: { label: 'Sandboxes', path: SANDBOXES_PATH },
|
|
24
|
+
SandboxClaim: { label: 'Claims', path: SANDBOX_CLAIMS_PATH },
|
|
25
|
+
SandboxWarmPool: { label: 'Warm pools', path: SANDBOX_WARM_POOLS_PATH },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function AgentSandboxBreadcrumb({ kind }: { kind: AgentSandboxSummaryKind }) {
|
|
29
|
+
const { search } = useLocation()
|
|
30
|
+
const list = DETAIL_LISTS[kind]
|
|
31
|
+
return (
|
|
32
|
+
<nav aria-label="Breadcrumb" className="flex items-center gap-2 text-sm text-theme-text-tertiary">
|
|
33
|
+
<Link className="hover:underline" to={withCrossViewParams(AGENT_SANDBOX_OVERVIEW.path, search)}>Agent Sandbox</Link>
|
|
34
|
+
<span aria-hidden="true">/</span>
|
|
35
|
+
<Link className="hover:underline" to={withCrossViewParams(list.path, search)}>{list.label}</Link>
|
|
36
|
+
</nav>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const SUMMARY_KINDS = [SANDBOX_KIND, SANDBOX_CLAIM_KIND, SANDBOX_WARM_POOL_KIND]
|
|
41
|
+
|
|
42
|
+
function summaryKind(resource: HostResource): AgentSandboxSummaryKind | undefined {
|
|
43
|
+
const plural = kindToPluralWithGroup(resource.kind, resource.group ?? '')
|
|
44
|
+
return SUMMARY_KINDS.find((k) => k.name === plural && k.group === resource.group)?.kind as AgentSandboxSummaryKind | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Agent Sandbox's Sandbox, SandboxClaim and SandboxWarmPool lists are Radar's
|
|
49
|
+
* own tables. Their drawers lead with the reading the workspace and Issues
|
|
50
|
+
* give, wherever they open; the standard renderer is "Spec & status". The
|
|
51
|
+
* header chip is the lists' plain-words reading, the raw reason on hover.
|
|
52
|
+
*/
|
|
53
|
+
export const agentSandboxResourceHost: ResourceHost = {
|
|
54
|
+
id: 'agent-sandbox',
|
|
55
|
+
drawerNavigation: { ownsPath: ownsAgentSandboxPath, Component: AgentSandboxDrawerTrailBack },
|
|
56
|
+
resources: SUMMARY_KINDS.map((k) => ({ name: k.name, group: k.group })),
|
|
57
|
+
detailOwnership: ['summary'],
|
|
58
|
+
detailSlots: (resource): DetailSlots => {
|
|
59
|
+
const kind = summaryKind(resource)
|
|
60
|
+
if (!kind) return {}
|
|
61
|
+
return {
|
|
62
|
+
breadcrumb: <AgentSandboxBreadcrumb kind={kind} />,
|
|
63
|
+
renderSummary: ({ apiKind, group, namespace, name, resource: data, context, onNavigate, leadContent }) =>
|
|
64
|
+
data?.kind === kind ? (
|
|
65
|
+
<AgentSandboxSummary
|
|
66
|
+
kind={kind}
|
|
67
|
+
apiKind={apiKind}
|
|
68
|
+
group={group}
|
|
69
|
+
namespace={namespace}
|
|
70
|
+
name={name}
|
|
71
|
+
resource={data}
|
|
72
|
+
framed={context === 'expanded'}
|
|
73
|
+
onNavigate={onNavigate}
|
|
74
|
+
leadContent={leadContent}
|
|
75
|
+
/>
|
|
76
|
+
) : null,
|
|
77
|
+
renderStatusBadge: (data: any) => <AgentSandboxStatusBadge data={data} />,
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
kindLists: [
|
|
81
|
+
{ kind: SANDBOX_KIND, title: 'Sandboxes', mode: always, Component: SandboxesKindList },
|
|
82
|
+
{ kind: SANDBOX_CLAIM_KIND, title: 'Sandbox claims', mode: always, Component: SandboxClaimsKindList },
|
|
83
|
+
{ kind: SANDBOX_WARM_POOL_KIND, title: 'Sandbox warm pools', mode: always, Component: SandboxWarmPoolsKindList },
|
|
84
|
+
],
|
|
85
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { getSandboxClaimStatus, getSandboxStatus } from '@skyhook-io/k8s-ui/components/resources/resource-utils-agent-runtimes'
|
|
3
|
+
import { RESERVE_BELOW_TARGET, readingLabel, serverReadings, unschedulablePools, warmPoolBadge } from './labels'
|
|
4
|
+
import { claim, liveSandboxes, warmPool } from './agentsandbox.fixtures'
|
|
5
|
+
import { liveAttention, liveWorkspace } from './workspace.fixtures'
|
|
6
|
+
|
|
7
|
+
describe('Agent Sandbox reading labels', () => {
|
|
8
|
+
it('put the controller’s codes in plain words and keep the code', () => {
|
|
9
|
+
const by = Object.fromEntries(liveSandboxes().map((s) => [s.metadata.name, readingLabel(getSandboxStatus(s))]))
|
|
10
|
+
expect(by['bad-image']).toEqual({ label: 'Image can’t be pulled', reason: 'ImagePullBackOff' })
|
|
11
|
+
expect(by.failed).toEqual({ label: 'Pod failed', reason: 'PodFailed' })
|
|
12
|
+
expect(by['warm-4xmkm']).toEqual({ label: 'Can’t schedule', reason: 'Unschedulable' })
|
|
13
|
+
expect(readingLabel(getSandboxClaimStatus(claim('c', { reason: 'WarmPoolNotFound' })))).toEqual({ label: 'Warm pool not found', reason: 'WarmPoolNotFound' })
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('leave readings that are already words alone', () => {
|
|
17
|
+
const by = Object.fromEntries(liveSandboxes().map((s) => [s.metadata.name, readingLabel(getSandboxStatus(s))]))
|
|
18
|
+
expect(by.expired).toEqual({ label: 'Expired' })
|
|
19
|
+
expect(by.foreign).toEqual({ label: 'Suspension blocked' })
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('warm pools that can’t schedule', () => {
|
|
24
|
+
it('come from the server’s reserve rows whose source is the scheduler', () => {
|
|
25
|
+
expect([...unschedulablePools(liveWorkspace())]).toEqual(['radar-agents-live/warm'])
|
|
26
|
+
const controller = liveAttention().map((a) => (a.rule === 'reserveBelowTarget' ? { ...a, rawDetailSource: 'controller' as const } : a))
|
|
27
|
+
expect(unschedulablePools(liveWorkspace({ attention: controller })).size).toBe(0)
|
|
28
|
+
expect(unschedulablePools(undefined).size).toBe(0)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('produces one canonical Reserve below target verdict for warm pools with a reserve row', () => {
|
|
32
|
+
const server = serverReadings(liveWorkspace())
|
|
33
|
+
const b = warmPoolBadge(warmPool('warm', { readyReplicas: 0 }), server)
|
|
34
|
+
expect(b.label).toBe(RESERVE_BELOW_TARGET)
|
|
35
|
+
expect(b.level).toBe('alert')
|
|
36
|
+
expect(b.title).toContain('scheduler')
|
|
37
|
+
// Without a server reserve row, a refilling pool stays Warming.
|
|
38
|
+
const refilling = warmPoolBadge(warmPool('warm', { readyReplicas: 0 }), undefined)
|
|
39
|
+
expect(refilling.label).toBeUndefined()
|
|
40
|
+
expect(refilling.status.text).toBe('Warming')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { HealthLevel, StatusBadge } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { summarizeSchedulerMessage } from '@skyhook-io/k8s-ui/components/resources/resource-utils'
|
|
3
|
+
import { getSandboxWarmPoolStatus } from '@skyhook-io/k8s-ui/components/resources/resource-utils-agent-runtimes'
|
|
4
|
+
import type { AgentSandboxAttention, AgentSandboxWorkspaceResponse } from '../../api/agentSandbox'
|
|
5
|
+
|
|
6
|
+
// Plain words for the controller's and Kubernetes' reasons a reading names.
|
|
7
|
+
// The readings keep the raw reason as their text, which stays the filter and
|
|
8
|
+
// sort value; the lists show these labels with the reason on hover. They
|
|
9
|
+
// mirror pkg/agentsandbox's failureTitles and claimTitles, so a row's badge
|
|
10
|
+
// and its Needs attention title agree.
|
|
11
|
+
const REASON_LABELS: Record<string, string> = {
|
|
12
|
+
ImagePullBackOff: 'Image can’t be pulled',
|
|
13
|
+
ErrImagePull: 'Image can’t be pulled',
|
|
14
|
+
InvalidImageName: 'Image name is invalid',
|
|
15
|
+
CrashLoopBackOff: 'Container keeps crashing',
|
|
16
|
+
CreateContainerConfigError: 'Container can’t be configured',
|
|
17
|
+
PodFailed: 'Pod failed',
|
|
18
|
+
InvalidConfiguration: 'Invalid configuration',
|
|
19
|
+
MultiplePods: 'More than one Pod matches',
|
|
20
|
+
WarmPoolNotFound: 'Warm pool not found',
|
|
21
|
+
TemplateNotFound: 'Template not found',
|
|
22
|
+
InvalidMetadata: 'Invalid Pod metadata',
|
|
23
|
+
EnvVarsInjectionRejected: 'Environment variables rejected',
|
|
24
|
+
VolumeClaimTemplatesError: 'Volume claim templates rejected',
|
|
25
|
+
SandboxMissing: 'Its Sandbox is gone',
|
|
26
|
+
ReconcilerError: 'Controller can’t reconcile it',
|
|
27
|
+
Unschedulable: 'Can’t schedule',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A reading's label for a list: plain words, and the raw reason when they differ from it. */
|
|
31
|
+
export function readingLabel(status: StatusBadge): { label: string; reason?: string } {
|
|
32
|
+
const label = REASON_LABELS[status.text]
|
|
33
|
+
return label ? { label, reason: status.text } : { label: status.text }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The warm pools whose reserve is short because the scheduler can't place
|
|
38
|
+
* their sandboxes, as the server's Needs attention says it: a
|
|
39
|
+
* reserveBelowTarget row whose source is the scheduler. Keys are
|
|
40
|
+
* "namespace/name". A pool refilling normally has no such row.
|
|
41
|
+
*/
|
|
42
|
+
export function unschedulablePools(workspace: AgentSandboxWorkspaceResponse | undefined): Set<string> {
|
|
43
|
+
const out = new Set<string>()
|
|
44
|
+
for (const a of workspace?.attention ?? []) {
|
|
45
|
+
if (a.rule === 'reserveBelowTarget' && a.rawDetailSource === 'scheduler') out.add(`${a.subject.namespace ?? ''}/${a.subject.name}`)
|
|
46
|
+
}
|
|
47
|
+
return out
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const CANT_SCHEDULE = 'Can’t schedule'
|
|
51
|
+
export const RESERVE_BELOW_TARGET = 'Reserve below target'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* One canonical badge reading for a SandboxWarmPool, shared by the Warm pools
|
|
55
|
+
* list, the drawer/page header pill, and the Overview summary so every surface
|
|
56
|
+
* shows the same verdict and severity tone.
|
|
57
|
+
*/
|
|
58
|
+
export function warmPoolBadge(
|
|
59
|
+
pool: any,
|
|
60
|
+
server?: ServerReadings,
|
|
61
|
+
): { status: StatusBadge; label?: string; level?: HealthLevel; title?: string } {
|
|
62
|
+
const status = getSandboxWarmPoolStatus(pool)
|
|
63
|
+
const namespace = pool?.metadata?.namespace ?? ''
|
|
64
|
+
const name = pool?.metadata?.name ?? ''
|
|
65
|
+
const key = objectKey('SandboxWarmPool', namespace, name)
|
|
66
|
+
const row = server?.rows.get(key)
|
|
67
|
+
const level = server?.tones.get(key)
|
|
68
|
+
if (row?.rule === 'templateMissing') {
|
|
69
|
+
return {
|
|
70
|
+
status,
|
|
71
|
+
label: 'Template not found',
|
|
72
|
+
level,
|
|
73
|
+
title: row.reading || 'The SandboxTemplate this warm pool names does not exist',
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (row?.rule === 'reserveBelowTarget') {
|
|
77
|
+
const unschedulable = server?.unschedulable.has(`${namespace}/${name}`)
|
|
78
|
+
return {
|
|
79
|
+
status,
|
|
80
|
+
label: RESERVE_BELOW_TARGET,
|
|
81
|
+
level,
|
|
82
|
+
title: unschedulable
|
|
83
|
+
? 'Warm reserve is below target because the scheduler can’t place its sandboxes'
|
|
84
|
+
: row.reading || 'Warm reserve is below target',
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { status, level }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type RowTone = Extract<HealthLevel, 'unhealthy' | 'alert' | 'degraded'>
|
|
91
|
+
|
|
92
|
+
/** What the server's summary says about the objects the lists show. */
|
|
93
|
+
export interface ServerReadings {
|
|
94
|
+
attentionObjects?: { sandboxes: Set<string>; claims: Set<string>; warmPools: Set<string> }
|
|
95
|
+
sidebar?: AgentSandboxWorkspaceResponse['sidebar']
|
|
96
|
+
/** Warm pools short because the scheduler can't place their sandboxes. */
|
|
97
|
+
unschedulable: Set<string>
|
|
98
|
+
/**
|
|
99
|
+
* The severity of the Needs attention row about an object, as a health tone,
|
|
100
|
+
* keyed by objectKey. A list colors that object's badge with it, so one
|
|
101
|
+
* state reads the same color on the Overview and in the lists.
|
|
102
|
+
*/
|
|
103
|
+
tones: Map<string, RowTone>
|
|
104
|
+
/** Template presence from the pool inventory is available even for healthy pools. */
|
|
105
|
+
warmPools: Map<string, AgentSandboxWorkspaceResponse['warmPools'][number]>
|
|
106
|
+
/** The Needs attention row about an object, keyed by objectKey. */
|
|
107
|
+
rows: Map<string, AgentSandboxAttention>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const objectKey = (kind: string, namespace: string, name: string) => `${kind}/${namespace}/${name}`
|
|
111
|
+
|
|
112
|
+
const TONE: Record<'critical' | 'alert' | 'warning', RowTone> = { critical: 'unhealthy', alert: 'alert', warning: 'degraded' }
|
|
113
|
+
|
|
114
|
+
export function serverReadings(workspace: AgentSandboxWorkspaceResponse | undefined): ServerReadings {
|
|
115
|
+
const tones = new Map<string, RowTone>()
|
|
116
|
+
const rows = new Map<string, AgentSandboxAttention>()
|
|
117
|
+
for (const a of workspace?.attention ?? []) {
|
|
118
|
+
const k = objectKey(a.subject.kind, a.subject.namespace ?? '', a.subject.name)
|
|
119
|
+
tones.set(k, TONE[a.severity])
|
|
120
|
+
rows.set(k, a)
|
|
121
|
+
}
|
|
122
|
+
const warmPools = new Map(workspace?.warmPools.map((w) => [objectKey("SandboxWarmPool", w.namespace, w.name), w]))
|
|
123
|
+
const objects = workspace?.attentionObjects
|
|
124
|
+
const attentionObjects = objects && {
|
|
125
|
+
sandboxes: new Set(objects.sandboxes),
|
|
126
|
+
claims: new Set(objects.claims),
|
|
127
|
+
warmPools: new Set(objects.warmPools),
|
|
128
|
+
}
|
|
129
|
+
return { attentionObjects, sidebar: workspace?.sidebar, unschedulable: unschedulablePools(workspace), tones, rows, warmPools }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The scheduler's verdict on a row, in the plain words the Overview's reading
|
|
134
|
+
* gives it ("All nodes have reached their Pod limit"), with its own message
|
|
135
|
+
* for a hover; nothing when the scheduler isn't the row's source.
|
|
136
|
+
*/
|
|
137
|
+
export function schedulerReason(a: AgentSandboxAttention | undefined): { plain: string; raw: string } | undefined {
|
|
138
|
+
if (a?.rawDetailSource !== 'scheduler' || !a.rawDetail) return undefined
|
|
139
|
+
const plain = summarizeSchedulerMessage(a.rawDetail, { plain: true })
|
|
140
|
+
return plain ? { plain: `${plain[0].toUpperCase()}${plain.slice(1)}`, raw: a.rawDetail } : undefined
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The sandboxes a warm pool's reserve row names as not ready. */
|
|
144
|
+
export function notReadyMembers(a: AgentSandboxAttention | undefined) {
|
|
145
|
+
return a?.rule === 'reserveBelowTarget' ? a.related?.refs.filter((r) => r.kind === 'Sandbox') ?? [] : []
|
|
146
|
+
}
|