@skyhook-io/radar-app 1.22.1 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/App.tsx +131 -38
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/RadarApp.tsx +5 -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 +128 -25
- 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/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +13 -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 +1172 -0
- package/src/api/workloadSource.ts +408 -0
- package/src/components/APIUnreachableBanner.test.tsx +19 -0
- package/src/components/APIUnreachableBanner.tsx +20 -0
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +127 -32
- package/src/components/ConnectionErrorView.test.tsx +63 -2
- package/src/components/ConnectionErrorView.tsx +88 -68
- 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/ActivityTurn.tsx +6 -4
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/AssessmentCard.tsx +1 -2
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -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/diagnose/Home.test.tsx +6 -0
- package/src/components/diagnose/Home.tsx +10 -3
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
- package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
- package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
- package/src/components/diagnose/InvestigationView.tsx +120 -23
- package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
- package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
- package/src/components/diagnose/investigationState.ts +9 -0
- package/src/components/diagnose/parts.test.tsx +11 -3
- package/src/components/diagnose/toolCallLabel.ts +3 -0
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/home/ActivitySummary.tsx +3 -8
- package/src/components/home/ClusterHealthCard.tsx +91 -17
- package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +9 -29
- 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/TopologyPreview.test.tsx +31 -30
- package/src/components/home/TopologyPreview.tsx +19 -28
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +7 -7
- 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/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/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/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +2 -6
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
- package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
- 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/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/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +119 -14
- package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
- 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/context/ConnectionContext.tsx +24 -5
- package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
- package/src/context/ConnectionProvider.handover.test.tsx +94 -0
- package/src/context/DiagnoseCustomization.tsx +20 -2
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/hooks/useEventSource.test.tsx +275 -4
- package/src/hooks/useEventSource.ts +278 -51
- package/src/index.ts +1 -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
- package/src/utils/navigation.test.ts +1 -6
- package/src/utils/navigation.ts +9 -44
- package/src/utils/network-policy-navigation.test.ts +21 -36
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { RadarFeatureSupport } from '../../api/radarFeatures'
|
|
2
|
+
import type { SubstratePoolRef, SubstrateRef } from '../../api/substrateWorkspace'
|
|
3
|
+
|
|
4
|
+
export const SUBSTRATE_GROUP = 'ate.dev'
|
|
5
|
+
|
|
6
|
+
export const SUBSTRATE_PATH = '/substrate'
|
|
7
|
+
|
|
8
|
+
/** The namespace picker's tooltip on every Substrate screen: actors live in atespaces, which are not namespaces. */
|
|
9
|
+
export const SUBSTRATE_NAMESPACE_FILTER_TOOLTIP = 'Agent Substrate keeps actors in atespaces, not namespaces — the namespace filter doesn’t apply here. Use the Atespace filter instead.'
|
|
10
|
+
|
|
11
|
+
export const SUBSTRATE_WORKERPOOL_KIND = { name: 'workerpools', kind: 'WorkerPool', group: SUBSTRATE_GROUP }
|
|
12
|
+
export const SUBSTRATE_POOLS_PATH = `/resources/workerpools?apiGroup=${SUBSTRATE_GROUP}`
|
|
13
|
+
|
|
14
|
+
export type SubstrateScreen = 'overview' | 'actors' | 'templates' | 'workers'
|
|
15
|
+
|
|
16
|
+
export const SUBSTRATE_SCREENS: Record<SubstrateScreen, { label: string; title: string; path: string }> = {
|
|
17
|
+
overview: { label: 'Overview', title: 'Agent Substrate overview', path: SUBSTRATE_PATH },
|
|
18
|
+
actors: { label: 'Actors', title: 'Agent Substrate actors', path: `${SUBSTRATE_PATH}/actors` },
|
|
19
|
+
templates: { label: 'Templates', title: 'Agent Substrate templates', path: `${SUBSTRATE_PATH}/templates` },
|
|
20
|
+
workers: { label: 'Workers', title: 'Agent Substrate workers', path: `${SUBSTRATE_PATH}/workers` },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SubstrateRoute {
|
|
24
|
+
screen: SubstrateScreen
|
|
25
|
+
/** An actor's page: /substrate/actors/<atespace>/<name>. */
|
|
26
|
+
actor?: SubstrateRef
|
|
27
|
+
/** A template's page: /substrate/templates/<atespace>/<name>. */
|
|
28
|
+
template?: SubstrateRef
|
|
29
|
+
/** A WorkerPool's page: /substrate/workerpools/<namespace>/<name>. */
|
|
30
|
+
pool?: SubstratePoolRef
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function segments(pathname: string): string[] {
|
|
34
|
+
return pathname.replace(/^\/+/, '').replace(/\/+$/, '').split('/').map((s) => {
|
|
35
|
+
try {
|
|
36
|
+
return decodeURIComponent(s)
|
|
37
|
+
} catch {
|
|
38
|
+
return s
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function parseSubstrateRoute(pathname: string): SubstrateRoute {
|
|
44
|
+
const seg = segments(pathname)
|
|
45
|
+
if (seg[0] !== 'substrate') return { screen: 'overview' }
|
|
46
|
+
const [, screen, a, b] = seg
|
|
47
|
+
if (screen === 'actors') return a && b ? { screen: 'actors', actor: { atespace: a, name: b } } : { screen: 'actors' }
|
|
48
|
+
if (screen === 'templates') return a && b ? { screen: 'templates', template: { atespace: a, name: b } } : { screen: 'templates' }
|
|
49
|
+
if (screen === 'workers') return { screen: 'workers' }
|
|
50
|
+
if (screen === 'workerpools' && a && b) return { screen: 'overview', pool: { namespace: a, name: b } }
|
|
51
|
+
return { screen: 'overview' }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function withParams(path: string, params: Record<string, string | undefined>): string {
|
|
55
|
+
const qs = new URLSearchParams()
|
|
56
|
+
for (const [k, v] of Object.entries(params)) if (v) qs.set(k, v)
|
|
57
|
+
const s = qs.toString()
|
|
58
|
+
return s ? `${path}?${s}` : path
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const enc = encodeURIComponent
|
|
62
|
+
|
|
63
|
+
/** An actor's page; `ctx` pins the Kubernetes context it was read through. */
|
|
64
|
+
export function substrateActorPath(ref: SubstrateRef, ctx?: string, tab?: string): string {
|
|
65
|
+
return withParams(`${SUBSTRATE_PATH}/actors/${enc(ref.atespace)}/${enc(ref.name)}`, { ctx, tab })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function substrateTemplatePath(ref: SubstrateRef, ctx?: string): string {
|
|
69
|
+
return withParams(`${SUBSTRATE_PATH}/templates/${enc(ref.atespace)}/${enc(ref.name)}`, { ctx })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function substratePoolPath(ref: SubstratePoolRef, ctx?: string, tab?: string): string {
|
|
73
|
+
return withParams(`${SUBSTRATE_PATH}/workerpools/${enc(ref.namespace)}/${enc(ref.name)}`, { ctx, tab })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The Actors screen narrowed by the /actors query parameters (state, atespace, template, pool, worker, q). */
|
|
77
|
+
export function substrateActorsPath(filter: Record<string, string | undefined> = {}): string {
|
|
78
|
+
return withParams(SUBSTRATE_SCREENS.actors.path, filter)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* What the WorkerPool kind's Resources route shows: Radar's pool table when
|
|
83
|
+
* this Radar serves the Substrate views; a loader while capabilities load for
|
|
84
|
+
* the first time; otherwise the generic table.
|
|
85
|
+
*/
|
|
86
|
+
export function substrateKindListMode(support: RadarFeatureSupport, capabilitiesPending: boolean): 'view' | 'wait' | 'table' {
|
|
87
|
+
if (support === 'supported') return 'view'
|
|
88
|
+
return support === 'unknown' && capabilitiesPending ? 'wait' : 'table'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The drawer's search parameter for an actor: `<atespace>/<name>`. Actors are not Kubernetes objects, so they have their own drawer. */
|
|
92
|
+
export const ACTOR_DRAWER_PARAM = 'actor'
|
|
93
|
+
|
|
94
|
+
export function encodeActorParam(ref: SubstrateRef): string {
|
|
95
|
+
return `${ref.atespace}/${ref.name}`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function decodeActorParam(value: string | null): SubstrateRef | null {
|
|
99
|
+
if (!value) return null
|
|
100
|
+
const i = value.indexOf('/')
|
|
101
|
+
if (i <= 0 || i === value.length - 1) return null
|
|
102
|
+
return { atespace: value.slice(0, i), name: value.slice(i + 1) }
|
|
103
|
+
}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode } from 'react'
|
|
2
|
+
import { shellWord } from '@skyhook-io/k8s-ui/utils/shell'
|
|
3
|
+
import type { UseQueryResult } from '@tanstack/react-query'
|
|
4
|
+
import { Bot, Info } from 'lucide-react'
|
|
5
|
+
import {
|
|
6
|
+
Badge,
|
|
7
|
+
PaneLoader,
|
|
8
|
+
RadarUpgradeAction,
|
|
9
|
+
StatusDot,
|
|
10
|
+
Tooltip,
|
|
11
|
+
formatAge,
|
|
12
|
+
getRadarUpgradeRequirement,
|
|
13
|
+
radarUpgradeDetail,
|
|
14
|
+
radarUpgradeHeadline,
|
|
15
|
+
toneTextClass,
|
|
16
|
+
type StatusTone,
|
|
17
|
+
} from '@skyhook-io/k8s-ui'
|
|
18
|
+
import type {
|
|
19
|
+
SubstrateAPITier,
|
|
20
|
+
SubstrateConnection,
|
|
21
|
+
SubstratePoolRef,
|
|
22
|
+
SubstrateWorkspace,
|
|
23
|
+
SubstrateActorState,
|
|
24
|
+
SubstrateSnapshotCoverage,
|
|
25
|
+
SubstratePoolsCoverage,
|
|
26
|
+
SubstrateStatus,
|
|
27
|
+
SubstrateWorkerImpact,
|
|
28
|
+
SubstrateWorkerRow,
|
|
29
|
+
} from '../../api/substrateWorkspace'
|
|
30
|
+
import { useConnection } from '../../context/ConnectionContext'
|
|
31
|
+
import { CopyButton } from '../diagnose/AgentSetupNotice'
|
|
32
|
+
import { usePrometheusStatus } from '../../api/client'
|
|
33
|
+
import { BreakText, Notice, RefreshFailedNotice, ScreenEmptyState } from '../workspace/layout'
|
|
34
|
+
import { INCOMPLETE_COVERAGE_STATES, coverageLabel } from '../workspace/coverage'
|
|
35
|
+
import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
|
|
36
|
+
import { IMPACT_LABEL, actorStateReading, coverageInPart, coverageReason, localTime, poolReading, relativeTime, tierReading, workerStateReading } from './readings'
|
|
37
|
+
import { SUBSTRATE_PATH, SUBSTRATE_SCREENS, substratePoolPath } from './routes'
|
|
38
|
+
|
|
39
|
+
/** Substrate's terms, defined where they first appear on a screen. */
|
|
40
|
+
export const SUBSTRATE_TERMS = {
|
|
41
|
+
atespace: 'Substrate’s own scope for actors and templates; not a Kubernetes namespace.',
|
|
42
|
+
golden: 'The prepared starting snapshot a template builds for new actors. Without it, they boot cold.',
|
|
43
|
+
slot: 'A place for one actor on a worker; a worker’s actor limit is its number of slots. A free slot takes an actor only when the worker also has the CPU and memory the actor’s template asks.',
|
|
44
|
+
} as const
|
|
45
|
+
|
|
46
|
+
export type SubstrateTerm = keyof typeof SUBSTRATE_TERMS
|
|
47
|
+
|
|
48
|
+
/** A Substrate term with its definition on hover. */
|
|
49
|
+
export function Term({ term, children }: { term: SubstrateTerm; children: ReactNode }) {
|
|
50
|
+
return (
|
|
51
|
+
<Tooltip content={SUBSTRATE_TERMS[term]}>
|
|
52
|
+
<span tabIndex={0} className="cursor-help underline decoration-dotted underline-offset-2">{children}</span>
|
|
53
|
+
</Tooltip>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { IMPACT_LABEL }
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An actor's state chip (actorStateReading). Pass `updateTime` wherever the
|
|
61
|
+
* actor's last change is known: a transition held past the stuck threshold
|
|
62
|
+
* then says "stuck" in amber, and one in flight stays quiet.
|
|
63
|
+
*/
|
|
64
|
+
export function ActorStateBadge({ state, impact, updateTime, wrap = false }: { state: SubstrateActorState; impact?: SubstrateWorkerImpact; updateTime?: string; wrap?: boolean }) {
|
|
65
|
+
const r = actorStateReading(state, { impact, updateTime })
|
|
66
|
+
const badge = <Badge severity={r.severity} size="sm" className={wrap ? 'whitespace-normal' : 'whitespace-nowrap'}>{r.label}</Badge>
|
|
67
|
+
return r.title ? <Tooltip content={r.title}><span className="min-w-0">{badge}</span></Tooltip> : badge
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What the workspace is, in one line, at the top of its Overview. */
|
|
71
|
+
|
|
72
|
+
/** The crumb and title every Substrate screen starts with; `intro` is a line under it, `children` sit below (filters). */
|
|
73
|
+
export function SubstrateHeader({ title, intro, children }: { title: string; intro?: ReactNode; children?: ReactNode }) {
|
|
74
|
+
const navigate = useWorkspaceNavigate()
|
|
75
|
+
return (
|
|
76
|
+
<div className="px-5 pt-4 xl:px-7">
|
|
77
|
+
<div className="flex flex-wrap items-center gap-x-2">
|
|
78
|
+
<nav aria-label="Location" className="flex items-center gap-1.5 text-sm text-theme-text-tertiary">
|
|
79
|
+
<Bot className="h-3.5 w-3.5" />
|
|
80
|
+
{title === 'Overview' ? 'Agent Substrate' : <button type="button" onClick={() => navigate(SUBSTRATE_PATH)} className="hover:text-theme-text-primary hover:underline">Agent Substrate</button>}
|
|
81
|
+
<span>/</span>
|
|
82
|
+
</nav>
|
|
83
|
+
<h1 className="text-lg font-semibold text-theme-text-primary">{title}</h1>
|
|
84
|
+
</div>
|
|
85
|
+
{intro && <p className="mt-0.5 text-sm text-theme-text-secondary">{intro}</p>}
|
|
86
|
+
{children && <div className="mt-2.5 flex flex-wrap items-center gap-2">{children}</div>}
|
|
87
|
+
</div>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function SourcePart({ tone, label, children }: { tone: StatusTone; label: string; children: ReactNode }) {
|
|
92
|
+
return (
|
|
93
|
+
<span className="inline-flex items-center gap-1.5">
|
|
94
|
+
<StatusDot tone={tone} />
|
|
95
|
+
<span className="text-theme-text-tertiary">{label}</span>
|
|
96
|
+
<span className="text-theme-text-secondary">{children}</span>
|
|
97
|
+
</span>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Who Radar reads Substrate as, and the endpoint, in a few words. */
|
|
102
|
+
export function identityText(tier: SubstrateAPITier): string {
|
|
103
|
+
return tier.identity?.mode === 'tokenFile' ? 'a token file' : tier.identity?.principal ?? 'the shared identity'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* In-cluster Radar with sign-in and Radar Hub: Radar reads as Substrate's
|
|
108
|
+
* shared client identity, with a token minted with the signed-in person's own
|
|
109
|
+
* Kubernetes access, and there is nothing to connect.
|
|
110
|
+
*/
|
|
111
|
+
function SharedAsCallerIdentity() {
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
as Substrate’s shared client identity (<span className="font-mono">ate-system/ate-client</span>), minted with your Kubernetes access
|
|
115
|
+
<Tooltip
|
|
116
|
+
content="ate-client is usually one of Substrate’s global owners, so it can see every atespace. Radar only reads with it: it lists actors, templates and workers and never changes them. The token is minted with your own Kubernetes access, so it works only while you may create tokens for ate-system/ate-client. This may change to reading with your own Substrate access."
|
|
117
|
+
wrapperClassName="ml-1 align-middle"
|
|
118
|
+
>
|
|
119
|
+
<span tabIndex={0} aria-label="About this identity" className="inline-flex text-theme-text-tertiary hover:text-theme-text-secondary">
|
|
120
|
+
<Info className="h-3.5 w-3.5" />
|
|
121
|
+
</span>
|
|
122
|
+
</Tooltip>
|
|
123
|
+
</>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Where the screen's values come from: Substrate's API (endpoint, identity,
|
|
129
|
+
* read age), Prometheus, and Kubernetes, which Radar always reads.
|
|
130
|
+
*/
|
|
131
|
+
export function SubstrateSourceLine({ tier, status, showRefreshFailure = true }: { tier: SubstrateAPITier; status?: SubstrateStatus; showRefreshFailure?: boolean }) {
|
|
132
|
+
const { data: prometheus } = usePrometheusStatus()
|
|
133
|
+
const service = status?.apiService
|
|
134
|
+
const endpoint = tier.endpoint ?? (service ? `${service.namespace}/${service.name}:${service.port}` : undefined)
|
|
135
|
+
const reading = tierReading(tier)
|
|
136
|
+
return (
|
|
137
|
+
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs" aria-label="Sources">
|
|
138
|
+
{tier.state === 'connected' ? (
|
|
139
|
+
<SourcePart tone="healthy" label="Substrate API">
|
|
140
|
+
{tier.identity?.mode === 'sharedAsCaller' ? (
|
|
141
|
+
<>
|
|
142
|
+
{endpoint && <><span className="font-mono">{endpoint}</span> </>}
|
|
143
|
+
<SharedAsCallerIdentity />
|
|
144
|
+
</>
|
|
145
|
+
) : (
|
|
146
|
+
<>
|
|
147
|
+
{endpoint && <span className="font-mono">{endpoint}</span>} as{' '}
|
|
148
|
+
<span className={tier.identity?.mode === 'tokenFile' ? undefined : 'font-mono'}>{identityText(tier)}</span>
|
|
149
|
+
</>
|
|
150
|
+
)}
|
|
151
|
+
{tier.readAt && (
|
|
152
|
+
<>
|
|
153
|
+
{' · '}
|
|
154
|
+
<Tooltip content={tier.readStartedAt ? `Read from ${localTime(tier.readStartedAt)} to ${localTime(tier.readAt)}: the counts were observed over that interval, not at one instant.` : `The read finished ${localTime(tier.readAt)}.`}>
|
|
155
|
+
<span>read {relativeTime(tier.readAt)}</span>
|
|
156
|
+
</Tooltip>
|
|
157
|
+
</>
|
|
158
|
+
)}
|
|
159
|
+
{tier.refreshing && !tier.lastError && <> · refreshing…</>}
|
|
160
|
+
</SourcePart>
|
|
161
|
+
) : tier.state === 'connecting' ? (
|
|
162
|
+
<SourcePart tone="unknown" label="Substrate API">connecting…</SourcePart>
|
|
163
|
+
) : (
|
|
164
|
+
<SourcePart tone={reading.tone} label="Substrate API">{reading.title.toLowerCase()}</SourcePart>
|
|
165
|
+
)}
|
|
166
|
+
{showRefreshFailure && <SubstrateRefreshFailure tier={tier} />}
|
|
167
|
+
<SourcePart tone={prometheus?.connected ? 'healthy' : 'unknown'} label="Prometheus">
|
|
168
|
+
{prometheus === undefined ? 'unknown' : prometheus.connected ? 'connected' : 'not connected'}
|
|
169
|
+
</SourcePart>
|
|
170
|
+
<SourcePart tone="healthy" label="Kubernetes">WorkerPools and worker Pods</SourcePart>
|
|
171
|
+
</div>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function SubstrateRefreshFailure({ tier, notice = false }: { tier: SubstrateAPITier; notice?: boolean }) {
|
|
176
|
+
if (!tier.lastError) return null
|
|
177
|
+
const summary = `Last Substrate API read failed ${relativeTime(tier.lastError.at)}. Showing the previous read.`
|
|
178
|
+
if (notice) return <Notice><div role="status">{summary} {tier.lastError.message}</div></Notice>
|
|
179
|
+
return (
|
|
180
|
+
<Tooltip content={tier.lastError.message}>
|
|
181
|
+
<span role="status" className={`text-xs ${toneTextClass('degraded')}`}>{summary}</span>
|
|
182
|
+
</Tooltip>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function PoolMatchLinks({ pools, workspace }: { pools: SubstratePoolRef[]; workspace?: SubstrateWorkspace }) {
|
|
187
|
+
const navigate = useWorkspaceNavigate()
|
|
188
|
+
const { connection } = useConnection()
|
|
189
|
+
return (
|
|
190
|
+
<div className="mt-1 flex flex-wrap gap-1.5">
|
|
191
|
+
{pools.map((p) => {
|
|
192
|
+
const key = `${p.namespace}/${p.name}`
|
|
193
|
+
const row = workspace?.pools.find((q) => q.name === p.name && q.namespace === p.namespace)
|
|
194
|
+
const finding = workspace?.needsAttention.find((f) => f.subject.kind === 'WorkerPool' && f.subject.name === p.name && f.subject.namespace === p.namespace)
|
|
195
|
+
const reading = row && poolReading(row, finding)
|
|
196
|
+
const tone = reading?.severity === 'error' ? 'unhealthy' : reading?.severity === 'alert' ? 'alert'
|
|
197
|
+
: reading?.severity === 'warning' ? 'degraded' : reading?.severity === 'success' ? 'healthy' : 'unknown'
|
|
198
|
+
const open = () => navigate(row && !row.kubernetes
|
|
199
|
+
? `${SUBSTRATE_SCREENS.workers.path}?${new URLSearchParams({ pool: key })}`
|
|
200
|
+
: substratePoolPath(p, connection.context || undefined))
|
|
201
|
+
const verdict = `${key} · ${reading?.label ?? 'Capacity unknown'}`
|
|
202
|
+
return (
|
|
203
|
+
<Tooltip key={key} content={verdict}>
|
|
204
|
+
<button type="button" aria-label={verdict} onClick={open} className="btn-secondary inline-flex items-center gap-1.5 px-2 py-0.5 text-xs font-mono"><StatusDot tone={tone} />{p.name}</button>
|
|
205
|
+
</Tooltip>
|
|
206
|
+
)
|
|
207
|
+
})}
|
|
208
|
+
</div>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const COVERAGE_NOUN: Record<keyof SubstrateSnapshotCoverage, string> = {
|
|
213
|
+
actors: 'actors',
|
|
214
|
+
templates: 'templates',
|
|
215
|
+
workers: 'workers',
|
|
216
|
+
atespaces: 'atespaces',
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Says which kinds this screen reads were not read in full, and why. */
|
|
220
|
+
export function SubstrateCoverageNotice({
|
|
221
|
+
coverage,
|
|
222
|
+
kinds,
|
|
223
|
+
}: {
|
|
224
|
+
coverage: Partial<SubstrateSnapshotCoverage> & { pools?: SubstratePoolsCoverage }
|
|
225
|
+
kinds: readonly (keyof SubstrateSnapshotCoverage)[]
|
|
226
|
+
}) {
|
|
227
|
+
const parts: string[] = []
|
|
228
|
+
// An absent API-tier kind was not read because the tier is down; the tier banner says that.
|
|
229
|
+
for (const k of kinds) {
|
|
230
|
+
const cov = coverage[k]
|
|
231
|
+
if (cov && coverageInPart(cov)) parts.push(`${COVERAGE_NOUN[k]}: ${coverageReason(cov, COVERAGE_NOUN[k])}`)
|
|
232
|
+
}
|
|
233
|
+
const pools = coverage.pools
|
|
234
|
+
if (pools && INCOMPLETE_COVERAGE_STATES.has(pools.state)) parts.push(`WorkerPools: ${coverageLabel(pools)}`)
|
|
235
|
+
if (parts.length === 0) return null
|
|
236
|
+
return <Notice>Radar couldn’t read all of what this screen shows — {parts.join('; ')}. Counts over it are lower bounds, and what it couldn’t read shows as unknown.</Notice>
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
type GateQuery<T> = Pick<UseQueryResult<T>, 'data' | 'error' | 'isLoading' | 'isFetching' | 'refetch' | 'isRefetchError' | 'dataUpdatedAt'>
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Loading, error, needs-newer-Radar and not-installed states every Substrate
|
|
243
|
+
* screen shares. Renders the screen only once its data is there.
|
|
244
|
+
*/
|
|
245
|
+
export function SubstrateScreenGate<T>({
|
|
246
|
+
query,
|
|
247
|
+
discoveryPending,
|
|
248
|
+
discovered,
|
|
249
|
+
label = 'Agent Substrate',
|
|
250
|
+
children,
|
|
251
|
+
}: {
|
|
252
|
+
query: GateQuery<T>
|
|
253
|
+
discoveryPending: boolean
|
|
254
|
+
/** Discovery serves ate.dev, or could not be read (the server is asked then). */
|
|
255
|
+
discovered: boolean
|
|
256
|
+
label?: string
|
|
257
|
+
children: (data: T) => ReactNode
|
|
258
|
+
}) {
|
|
259
|
+
const { connection } = useConnection()
|
|
260
|
+
const data = query.data
|
|
261
|
+
if (!data && (query.isLoading || discoveryPending)) return <PaneLoader label={`Loading ${label}…`} className="flex-1" />
|
|
262
|
+
if (!data && !discovered) {
|
|
263
|
+
return <ScreenEmptyState icon={Bot} title="Agent Substrate is not installed" detail={`No ate.dev resources are served in ${connection.context || 'this cluster'}.`} />
|
|
264
|
+
}
|
|
265
|
+
if (!data) {
|
|
266
|
+
const upgrade = getRadarUpgradeRequirement(query.error)
|
|
267
|
+
if (upgrade) {
|
|
268
|
+
return (
|
|
269
|
+
<ScreenEmptyState
|
|
270
|
+
icon={Bot}
|
|
271
|
+
title={radarUpgradeHeadline('Agent Substrate')}
|
|
272
|
+
detail={radarUpgradeDetail(upgrade)}
|
|
273
|
+
action={<div className="mt-3 text-sm"><RadarUpgradeAction requirement={upgrade} /></div>}
|
|
274
|
+
/>
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
return (
|
|
278
|
+
<ScreenEmptyState
|
|
279
|
+
icon={Bot}
|
|
280
|
+
title={`${label} unavailable`}
|
|
281
|
+
detail={query.error instanceof Error ? query.error.message : `Radar could not load ${label}.`}
|
|
282
|
+
action={
|
|
283
|
+
<button type="button" onClick={() => void query.refetch()} disabled={query.isFetching} className="btn-secondary mt-3 px-3 py-1.5 text-sm">
|
|
284
|
+
{query.isFetching ? 'Retrying…' : 'Retry'}
|
|
285
|
+
</button>
|
|
286
|
+
}
|
|
287
|
+
/>
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
return <><RefreshFailedNotice queries={[query]} className="px-5 pt-3 xl:px-7" />{children(data)}</>
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A value Radar could not read: its reason, never a zero. */
|
|
294
|
+
export function Unread({ children = 'Not connected', title }: { children?: ReactNode; title?: string }) {
|
|
295
|
+
const body = <span className="text-theme-text-tertiary">{children}</span>
|
|
296
|
+
return title ? <Tooltip content={title}><span>{body}</span></Tooltip> : body
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The window width every Substrate table shows all its columns at: the
|
|
301
|
+
* Resources sidebar leaves the table about 1000px there. Below it each table
|
|
302
|
+
* folds its secondary columns into the cell they qualify, so names keep their
|
|
303
|
+
* room.
|
|
304
|
+
*/
|
|
305
|
+
export const SUBSTRATE_WIDE = '(min-width: 1400px)'
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* An object's name in a table or card: mono and whole. Columns are sized so
|
|
309
|
+
* names fit on one line; a longer one wraps after a hyphen, and only a single
|
|
310
|
+
* segment wider than the column is cut (whole on hover).
|
|
311
|
+
*/
|
|
312
|
+
export function Name({ name, className }: { name: string; className?: string }) {
|
|
313
|
+
// Wraps only after a hyphen, never mid-word: a generated name (a UUID) stays readable.
|
|
314
|
+
return <BreakText value={name} after="-" className={`font-mono ${className ?? 'text-sm'}`} />
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export { WholeNames } from '../velero/shared'
|
|
318
|
+
|
|
319
|
+
export const NOT_CONNECTED_TITLE = 'Kept in Substrate’s API, not Kubernetes. Radar reads it once it is connected to that API.'
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* A time as this workspace shows every time: relative ("12m ago", "in 4m"),
|
|
323
|
+
* with the local date and time on hover, after `hint` when there is one.
|
|
324
|
+
*/
|
|
325
|
+
export function When({ iso, hint, prefix, held }: { iso: string; hint?: string; prefix?: string; held?: boolean }) {
|
|
326
|
+
// Held: how long since then ("for at least 1h"), never a time with "since" ("since 1h ago" says it twice).
|
|
327
|
+
return (
|
|
328
|
+
<Tooltip content={hint ? `${hint} ${localTime(iso)}.` : localTime(iso)}>
|
|
329
|
+
<span className="whitespace-nowrap">{prefix ? `${prefix} ` : ''}{held ? formatAge(iso) : relativeTime(iso)}</span>
|
|
330
|
+
</Tooltip>
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
type KubectlTarget =
|
|
335
|
+
| { context: string; kubeconfig: string; endpoint?: string; tokenFile?: string }
|
|
336
|
+
| { guidance: string }
|
|
337
|
+
|
|
338
|
+
export const KubectlTargetContext = createContext<KubectlTarget | undefined>(undefined)
|
|
339
|
+
|
|
340
|
+
export function substrateKubectlTarget(view: SubstrateConnection | undefined, activeContext: string): KubectlTarget | undefined {
|
|
341
|
+
if (!view) return undefined
|
|
342
|
+
if (view.view === 'managed') {
|
|
343
|
+
const { endpoint, trust, serverName } = view.managed
|
|
344
|
+
if (endpoint && (endpoint !== 'api.ate-system.svc:443' || trust === 'caFile' || serverName !== 'api.ate-system.svc')) {
|
|
345
|
+
return { guidance: `Use a Substrate client configured for ${endpoint} from a machine that can reach it, with the installation’s TLS settings.` }
|
|
346
|
+
}
|
|
347
|
+
return { guidance: 'Use kubectl ate with a kubeconfig for this cluster. It port-forwards to the ate-system/api Service.' }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const { target, settings } = view
|
|
351
|
+
if (target.context !== activeContext) return undefined
|
|
352
|
+
if (!settings || view.targetChanged) {
|
|
353
|
+
return { guidance: 'Use a client configured for the Substrate instance on this cluster. Check the connection target in Settings → Agent Substrate.' }
|
|
354
|
+
}
|
|
355
|
+
if (settings.caFile || settings.serverName) {
|
|
356
|
+
return { guidance: `Use a Substrate client configured for ${settings.endpoint} with the CA and server name from Settings → Agent Substrate.` }
|
|
357
|
+
}
|
|
358
|
+
if (settings.endpoint && /\.svc(?:\.|:)/i.test(settings.endpoint)) {
|
|
359
|
+
return { guidance: `Use a Substrate client from a machine that can resolve and reach ${settings.endpoint}.` }
|
|
360
|
+
}
|
|
361
|
+
if (!target.inFileName || !target.source || !/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(target.source)) {
|
|
362
|
+
return { guidance: 'Use kubectl ate with a kubeconfig and context for the cluster shown here.' }
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
context: target.inFileName,
|
|
366
|
+
kubeconfig: target.source,
|
|
367
|
+
endpoint: settings.endpoint,
|
|
368
|
+
tokenFile: settings.identity === 'tokenFile' ? settings.tokenFile : undefined,
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const KUBECTL_ATE = /^kubectl ate /
|
|
373
|
+
|
|
374
|
+
function withKubectlTarget(command: string, target: Extract<KubectlTarget, { context: string }>): string {
|
|
375
|
+
const flags = [
|
|
376
|
+
`--kubeconfig ${shellWord(target.kubeconfig)}`,
|
|
377
|
+
`--context ${shellWord(target.context)}`,
|
|
378
|
+
...(target.endpoint ? [`--endpoint ${shellWord(target.endpoint)}`] : []),
|
|
379
|
+
...(target.tokenFile ? [`--token-file ${shellWord(target.tokenFile)}`] : []),
|
|
380
|
+
]
|
|
381
|
+
return `${command} ${flags.join(' ')}`
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* A shell command a next step names, as a code chip with a copy button, on a
|
|
386
|
+
* line of its own under the step: it never wraps, inside itself or into the
|
|
387
|
+
* sentence; a command wider than its container scrolls. A command with
|
|
388
|
+
* <placeholders> is a template to fill in, and says so after it.
|
|
389
|
+
*/
|
|
390
|
+
export function CommandChip({ command: written }: { command: string }) {
|
|
391
|
+
const target = useContext(KubectlTargetContext)
|
|
392
|
+
const isAte = KUBECTL_ATE.test(written)
|
|
393
|
+
if (isAte && !target) return null
|
|
394
|
+
if (isAte && target && 'guidance' in target) {
|
|
395
|
+
return <p className="mt-1 text-xs text-theme-text-secondary">{target.guidance}</p>
|
|
396
|
+
}
|
|
397
|
+
const command = isAte && target && 'context' in target ? withKubectlTarget(written, target) : written
|
|
398
|
+
const holes = [...new Set(command.match(/<[^<>\s]+>/g) ?? [])]
|
|
399
|
+
return (
|
|
400
|
+
<div className="mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5" data-command-line>
|
|
401
|
+
<span className="flex min-w-0 max-w-full items-center gap-1 rounded-md border border-theme-border bg-theme-elevated py-px pl-2 pr-0.5">
|
|
402
|
+
<code className="min-w-0 select-all overflow-x-auto whitespace-pre font-mono text-[11.5px] text-theme-text-primary">{command}</code>
|
|
403
|
+
<CopyButton text={command} label="Copy command" />
|
|
404
|
+
</span>
|
|
405
|
+
{holes.length > 0 && <span className="text-[11px] text-theme-text-tertiary">fill in {holes.join(', ')}</span>}
|
|
406
|
+
</div>
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** A worker's state chip, the same on Workers and on a pool's placement cards. */
|
|
411
|
+
export function WorkerStateChip({ w }: { w: Pick<SubstrateWorkerRow, 'state' | 'workerState' | 'attentionSeverity'> }) {
|
|
412
|
+
const r = workerStateReading(w)
|
|
413
|
+
return (
|
|
414
|
+
<Tooltip content={r.title}>
|
|
415
|
+
<span className="max-w-full"><Badge severity={r.severity} size="sm" className="whitespace-nowrap">{r.label}</Badge></span>
|
|
416
|
+
</Tooltip>
|
|
417
|
+
)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Text whose words are identifiers (a command, a node or Pod name, "atespace /
|
|
422
|
+
* name"): it wraps between words, never inside one, not even at a hyphen.
|
|
423
|
+
*/
|
|
424
|
+
export function Tokens({ text }: { text: string }) {
|
|
425
|
+
return <>{text.split(/(\s+)/).map((part, i) => (/\s+/.test(part) ? part : <span key={i} className="inline-block whitespace-nowrap">{part}</span>))}</>
|
|
426
|
+
}
|