@skyhook-io/radar-app 1.21.4 → 1.21.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api/client.ts +42 -2
- package/src/api/radarFeatures.ts +1 -0
- package/src/components/applications/ApplicationsView.tsx +38 -8
- package/src/components/applications/ArgoSyncDetails.tsx +32 -0
- package/src/components/applications/RenderedChanges.test.tsx +179 -0
- package/src/components/applications/RenderedChanges.tsx +233 -0
- package/src/components/audit/AuditView.tsx +2 -1
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +30 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +21 -1
- package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +9 -0
- package/src/components/diagnose/investigationEvidence/types.ts +12 -0
- package/src/components/helm/HelmReleaseDrawer.test.ts +27 -0
- package/src/components/helm/HelmReleaseDrawer.tsx +24 -3
- package/src/components/helm/HelmView.tsx +16 -6
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +3 -0
- package/src/components/helm/releaseController.test.tsx +26 -0
- package/src/components/helm/releaseController.tsx +98 -0
- package/src/components/resources/renderers/K3sHelmChartRenderer.tsx +18 -0
- package/src/components/traffic/TrafficGraph.export.test.tsx +1 -1
- package/src/components/traffic/TrafficGraph.tsx +3 -17
- package/src/components/traffic/traffic-export.test.ts +51 -0
- package/src/components/traffic/traffic-export.ts +114 -0
- package/src/components/traffic/trafficFilters.ts +16 -0
- package/src/components/workload/WorkloadRevisionsButton.test.tsx +34 -0
- package/src/components/workload/WorkloadRevisionsButton.tsx +31 -0
- package/src/components/workload/WorkloadView.tsx +11 -3
- package/src/integrations/resourceHosts.test.tsx +1 -1
- package/src/integrations/resourceHosts.tsx +2 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { GitBranch, Server } from 'lucide-react'
|
|
2
|
+
import type { HelmReleaseController } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { Tooltip } from '../ui/Tooltip'
|
|
4
|
+
import { kindToPluralWithGroup, type NavigateToResource } from '../../utils/navigation'
|
|
5
|
+
|
|
6
|
+
// The controller of a release. An older Radar sends only the Flux field.
|
|
7
|
+
export function releaseControllerOf(r: { controller?: HelmReleaseController; managedByFluxHelmRelease?: string }): HelmReleaseController | undefined {
|
|
8
|
+
if (r.controller) return r.controller
|
|
9
|
+
if (!r.managedByFluxHelmRelease) return undefined
|
|
10
|
+
const [namespace = '', name = ''] = r.managedByFluxHelmRelease.split('/')
|
|
11
|
+
return { tool: 'flux', kind: 'HelmRelease', group: 'helm.toolkit.fluxcd.io', namespace, name }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// A controller other than Flux. Flux keeps its own routing (GitOps link,
|
|
15
|
+
// route-only upgrade hint); any other gets the generic note, and its upgrade
|
|
16
|
+
// hints are hidden because Radar has no view to route an upgrade to.
|
|
17
|
+
export function otherController(r: { controller?: HelmReleaseController; managedByFluxHelmRelease?: string }): HelmReleaseController | undefined {
|
|
18
|
+
const c = releaseControllerOf(r)
|
|
19
|
+
return c && c.tool !== 'flux' ? c : undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Upgrade hints are hidden for any controller other than Flux, including a k3s
|
|
23
|
+
// HelmChart the caller can't read.
|
|
24
|
+
export function managedByOtherController(r: { controller?: HelmReleaseController; managedByFluxHelmRelease?: string; managedByK3s?: boolean }): boolean {
|
|
25
|
+
return !!otherController(r) || !!r.managedByK3s
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const HIDDEN_K3S_TEXT = "Managed by the k3s/RKE2 helm-controller. The owning HelmChart's namespace isn't available in this view, or Radar couldn't check your access. An upgrade or rollback here is overwritten when its install Job reruns; change the release through its HelmChart."
|
|
29
|
+
|
|
30
|
+
export function HiddenK3sBadge() {
|
|
31
|
+
return (
|
|
32
|
+
<Tooltip content={HIDDEN_K3S_TEXT}>
|
|
33
|
+
<span className="badge-sm shrink-0 border border-theme-border bg-theme-elevated text-theme-text-secondary">
|
|
34
|
+
<Server className="w-3 h-3" />
|
|
35
|
+
k3s
|
|
36
|
+
</span>
|
|
37
|
+
</Tooltip>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const TOOL_LABELS: Record<string, string> = { flux: 'Flux', k3s: 'k3s' }
|
|
42
|
+
|
|
43
|
+
function controllerLabel(c: HelmReleaseController): string {
|
|
44
|
+
return TOOL_LABELS[c.tool] ?? c.tool
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const refOf = (o: { namespace: string; name: string }) => `${o.namespace}/${o.name}`
|
|
48
|
+
|
|
49
|
+
export function controllerManagedText(c: HelmReleaseController): string {
|
|
50
|
+
// helm-controller re-runs its install Job only when the Job's config hash changes.
|
|
51
|
+
const effect = c.tool === 'k3s'
|
|
52
|
+
? 'an upgrade or rollback here is overwritten the next time helm-controller runs the install Job (when the HelmChart or its HelmChartConfig changes).'
|
|
53
|
+
: `an upgrade or rollback here can be overwritten by that ${c.kind}.`
|
|
54
|
+
const head = `Managed by ${controllerLabel(c)}. ${c.kind} ${refOf(c)} installs this release from its own definition, so ${effect}`
|
|
55
|
+
const v = c.valuesRef
|
|
56
|
+
if (!v) return `${head} Change it through that ${c.kind}.`
|
|
57
|
+
if (v.exists === true) return `${head} Change values in ${v.kind} ${refOf(v)}.`
|
|
58
|
+
if (v.exists === false) return `${head} Create a ${v.kind} ${refOf(v)} to change its values.`
|
|
59
|
+
// Unknown: the read failed, or the caller may not see it.
|
|
60
|
+
return `${head} Change values in ${v.kind} ${refOf(v)} (create it if it does not exist).`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ReleaseControllerBadge({ controller }: { controller: HelmReleaseController }) {
|
|
64
|
+
const flux = controller.tool === 'flux'
|
|
65
|
+
const tip = flux
|
|
66
|
+
? `Installed by Flux helm-controller via HelmRelease ${refOf(controller)}. Manage its source in GitOps.`
|
|
67
|
+
: controllerManagedText(controller)
|
|
68
|
+
return (
|
|
69
|
+
<Tooltip content={tip}>
|
|
70
|
+
<span className="badge-sm shrink-0 border border-theme-border bg-theme-elevated text-theme-text-secondary">
|
|
71
|
+
{flux ? <GitBranch className="w-3 h-3" /> : <Server className="w-3 h-3" />}
|
|
72
|
+
{controllerLabel(controller)}
|
|
73
|
+
</span>
|
|
74
|
+
</Tooltip>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function target(o: { kind: string; group: string; namespace: string; name: string }) {
|
|
79
|
+
return { kind: kindToPluralWithGroup(o.kind, o.group), group: o.group, namespace: o.namespace, name: o.name }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The drawer note for a controller other than Flux (Flux keeps its GitOps link).
|
|
83
|
+
export function ReleaseControllerNote({ controller, onNavigateToResource }: { controller: HelmReleaseController; onNavigateToResource?: NavigateToResource }) {
|
|
84
|
+
const v = controller.valuesRef
|
|
85
|
+
return (
|
|
86
|
+
<Tooltip content={controllerManagedText(controller)} wrapperClassName="mt-1">
|
|
87
|
+
<span className="inline-flex flex-wrap items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-1.5 py-0.5 text-[11px] text-amber-700 dark:text-amber-400">
|
|
88
|
+
<Server className="w-3 h-3" />
|
|
89
|
+
Managed by {controllerLabel(controller)} ·
|
|
90
|
+
<button type="button" className="hover:underline" onClick={() => onNavigateToResource?.(target(controller))}>{controller.kind} {refOf(controller)}</button>
|
|
91
|
+
{v?.exists === true && <>
|
|
92
|
+
·
|
|
93
|
+
<button type="button" className="hover:underline" onClick={() => onNavigateToResource?.(target(v))}>{v.kind} {refOf(v)}</button>
|
|
94
|
+
</>}
|
|
95
|
+
</span>
|
|
96
|
+
</Tooltip>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback } from 'react'
|
|
2
|
+
import { useNavigate, useSearchParams } from 'react-router-dom'
|
|
3
|
+
import { K3sHelmChartRenderer as BaseK3sHelmChartRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/K3sHelmRenderers'
|
|
4
|
+
import type { ResourceRef } from '@skyhook-io/k8s-ui'
|
|
5
|
+
|
|
6
|
+
/** Host wrapper: the HelmChart drawer's "Open Helm release" goes to the Helm view, keeping the namespace pick. */
|
|
7
|
+
export function K3sHelmChartRenderer({ data, onNavigate }: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
8
|
+
const navigate = useNavigate()
|
|
9
|
+
const [searchParams] = useSearchParams()
|
|
10
|
+
const openRelease = useCallback((ref: { namespace: string; name: string }) => {
|
|
11
|
+
const params = new URLSearchParams()
|
|
12
|
+
const namespaces = searchParams.get('namespaces')
|
|
13
|
+
if (namespaces) params.set('namespaces', namespaces)
|
|
14
|
+
params.set('release', `${ref.namespace}/${ref.name}`)
|
|
15
|
+
navigate({ pathname: '/helm', search: params.toString() })
|
|
16
|
+
}, [navigate, searchParams])
|
|
17
|
+
return <BaseK3sHelmChartRenderer data={data} onNavigate={onNavigate} onOpenHelmRelease={openRelease} />
|
|
18
|
+
}
|
|
@@ -53,5 +53,5 @@ it('offers image export in the graph controls', async () => {
|
|
|
53
53
|
</ToastProvider>,
|
|
54
54
|
))
|
|
55
55
|
const controls = container.querySelector('[data-testid="controls"]')!
|
|
56
|
-
expect(controls.querySelector('button[aria-label="Export
|
|
56
|
+
expect(controls.querySelector('button[aria-label="Export graph"]')).not.toBeNull()
|
|
57
57
|
})
|
|
@@ -25,7 +25,8 @@ import { SEVERITY_BADGE, SEVERITY_DOT, SEVERITY_TEXT } from '@skyhook-io/k8s-ui/
|
|
|
25
25
|
import { getNamespaceColor } from '../../utils/traffic-colors'
|
|
26
26
|
import { Tooltip } from '../ui/Tooltip'
|
|
27
27
|
import { TrafficData } from './TrafficData'
|
|
28
|
-
import {
|
|
28
|
+
import { describeTrafficNode } from './traffic-export'
|
|
29
|
+
import { dataByProtocol, protocolsOf, throughputLabel, totalDataByProtocol, protocolName, isRateBasedSource, isExternalKind, requestRateOf, errorRateOf, formatRate, formatConnections, formatVolume, MAX_VISIBLE_PORTS, displayVolume, latencyWeightOf, edgesOnPort, protocolLabel, type TrafficFocus } from './trafficFilters'
|
|
29
30
|
|
|
30
31
|
// ELK is 1.5 MB; load it with the first traffic layout, not with the app.
|
|
31
32
|
let elkPromise: Promise<ELK> | null = null
|
|
@@ -97,20 +98,6 @@ function getEdgeWidth(connections: number): number {
|
|
|
97
98
|
return Math.min(6, Math.max(1.5, Math.log10(Math.max(connections, 1000)) - 1.5))
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
// Phase 2.2: Format connection counts for display
|
|
101
|
-
function formatConnections(count: number): string {
|
|
102
|
-
if (count >= 1_000_000_000) return `${(count / 1_000_000_000).toFixed(1)}B`
|
|
103
|
-
if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M`
|
|
104
|
-
if (count >= 1_000) return `${(count / 1_000).toFixed(0)}K`
|
|
105
|
-
return count.toString()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// A volume in the source's own unit: a rate to two significant places for a
|
|
109
|
-
// rate-based source, a whole count otherwise.
|
|
110
|
-
function formatVolume(volume: number, isRateBased: boolean): string {
|
|
111
|
-
return isRateBased ? formatRate(volume) : formatConnections(volume)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
101
|
function formatLatency(ms: number): string {
|
|
115
102
|
if (ms >= 1000) return `${(ms / 1000).toFixed(1)}s`
|
|
116
103
|
if (ms >= 1) return `${ms.toFixed(1)}ms`
|
|
@@ -207,7 +194,6 @@ const SERVICE_CATEGORY_COLORS: Record<string, { bg: string; border: string; dot:
|
|
|
207
194
|
const NODE_WIDTH = 180
|
|
208
195
|
const NODE_BASE_HEIGHT = 56 // Base height without ports
|
|
209
196
|
const NODE_PORT_HEIGHT = 18 // Height per port row
|
|
210
|
-
const MAX_VISIBLE_PORTS = 4 // Maximum ports to show before "+N more"
|
|
211
197
|
|
|
212
198
|
// Custom node component
|
|
213
199
|
export function TrafficNode({ data }: { data: TrafficNodeData }) {
|
|
@@ -1819,7 +1805,7 @@ export function TrafficGraph({ flows, hotPathThreshold = 0, showNamespaceGroups
|
|
|
1819
1805
|
>
|
|
1820
1806
|
<Background />
|
|
1821
1807
|
<Controls>
|
|
1822
|
-
<GraphExportButton defaultFilename="traffic" title="Export traffic" onDownloadBlob={onDownloadBlob} />
|
|
1808
|
+
<GraphExportButton defaultFilename="traffic" title="Export traffic" onDownloadBlob={onDownloadBlob} describeNode={describeTrafficNode} />
|
|
1823
1809
|
</Controls>
|
|
1824
1810
|
<FitViewOnChange shouldFitViewRef={shouldFitViewRef} layoutedNodes={layoutedNodes} />
|
|
1825
1811
|
</ReactFlow>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { describeTrafficNode } from './traffic-export'
|
|
3
|
+
|
|
4
|
+
describe('describeTrafficNode', () => {
|
|
5
|
+
it('makes the addon group the only container', () => {
|
|
6
|
+
expect(describeTrafficNode({ id: 'addon-group', type: 'addonGroup', data: {} })).toMatchObject({ shape: 'group', tone: 'addon' })
|
|
7
|
+
const node = describeTrafficNode({ id: 'shop/web', type: 'traffic', data: { kind: 'Pod', label: 'web', namespace: 'shop', namespaceColor: '#1e3a5f' } })
|
|
8
|
+
expect(node).toMatchObject({ shape: 'resource', name: 'web', detail: 'shop', fill: '#1e3a5f' })
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('shows a workload by its workload kind', () => {
|
|
12
|
+
expect(describeTrafficNode({ id: 'shop/api', type: 'traffic', data: { kind: 'Workload', workloadKind: 'Deployment', label: 'api' } }))
|
|
13
|
+
.toMatchObject({ kind: 'Deployment', kindLabel: 'Deployment' })
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('keeps the category of an external service and no namespace tint', () => {
|
|
17
|
+
const node = describeTrafficNode({ id: 'db.example.com', type: 'traffic', data: { kind: 'External', label: 'db.example.com', serviceCategory: 'database', namespaceColor: '#123456' } })
|
|
18
|
+
expect(node).toMatchObject({ shape: 'resource', kind: 'External', category: 'database' })
|
|
19
|
+
expect(node?.fill).toBeUndefined()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('lists ports with their counts, up to the card limit, or the connection total', () => {
|
|
23
|
+
const ports = [80, 443, 8080, 9090, 9100].map((port, i) => ({ port, connections: i === 1 ? 0 : 1500 }))
|
|
24
|
+
const node = describeTrafficNode({ id: 'shop/api', type: 'traffic', data: { kind: 'Pod', label: 'api', ports, isHotPath: true } })
|
|
25
|
+
expect(node?.rows).toEqual([
|
|
26
|
+
{ text: ':80', code: true, hot: true, value: '2K' },
|
|
27
|
+
{ text: ':443', code: true, hot: true },
|
|
28
|
+
{ text: ':8080', code: true, hot: true, value: '2K' },
|
|
29
|
+
{ text: ':9090', code: true, hot: true, value: '2K' },
|
|
30
|
+
{ text: '+1 more', muted: true },
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
const client = describeTrafficNode({ id: 'demo/client', type: 'traffic', data: { kind: 'Pod', label: 'client', ports: [{ port: 0, connections: 5 }], totalConnections: 540, connLabel: 'conn' } })
|
|
34
|
+
expect(client?.rows).toEqual([{ text: '540 conn', hot: false }])
|
|
35
|
+
expect(describeTrafficNode({ id: 'idle', type: 'traffic', data: { kind: 'Pod', label: 'idle' } })?.rows).toBeUndefined()
|
|
36
|
+
|
|
37
|
+
const pod = describeTrafficNode({ id: 'shop/api-7d9', type: 'traffic', data: { kind: 'Pod', label: 'api-7d9', workload: 'api', totalConnections: 3 } })
|
|
38
|
+
expect(pod?.rows).toEqual([{ text: 'api' }, { text: '3 conn', hot: false }])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('washes an external card in its category color', () => {
|
|
42
|
+
expect(describeTrafficNode({ id: 'web', type: 'traffic', data: { kind: 'External', label: 'HTTPS', serviceCategory: 'web' } })?.tint).toEqual({ color: '#3B82F6', opacity: 0.2 })
|
|
43
|
+
expect(describeTrafficNode({ id: 'x', type: 'traffic', data: { kind: 'External', label: 'x' } })?.tint).toEqual({ color: '#EAB308', opacity: 0.1 })
|
|
44
|
+
expect(describeTrafficNode({ id: 'shop/web', type: 'traffic', data: { kind: 'Pod', label: 'web' } })?.tint).toBeUndefined()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('draws both Internet kinds as Internet', () => {
|
|
48
|
+
expect(describeTrafficNode({ id: 'internet', type: 'traffic', data: { kind: 'Internet', label: 'internet' } })?.shape).toBe('internet')
|
|
49
|
+
expect(describeTrafficNode({ id: 'addon-internet', type: 'traffic', data: { kind: 'AddonInternet', label: 'Internet' } })?.shape).toBe('internet')
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { CircleQuestionMark, Database, Globe, Puzzle, Server } from 'lucide-react'
|
|
2
|
+
import { getTopologyIcon } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import type { GraphBoxRow, GraphNodeMapper } from '@skyhook-io/k8s-ui/utils/graph-model'
|
|
4
|
+
import { formatVolume, isExternalKind, MAX_VISIBLE_PORTS } from './trafficFilters'
|
|
5
|
+
|
|
6
|
+
// Hex values of the Tailwind 500 shades the traffic nodes use for these categories.
|
|
7
|
+
const CATEGORY_COLORS: Record<string, string> = {
|
|
8
|
+
database: '#8B5CF6',
|
|
9
|
+
cloud: '#06B6D4',
|
|
10
|
+
monitoring: '#84CC16',
|
|
11
|
+
payment: '#10B981',
|
|
12
|
+
auth: '#F59E0B',
|
|
13
|
+
email: '#EC4899',
|
|
14
|
+
messaging: '#A855F7',
|
|
15
|
+
cache: '#F97316',
|
|
16
|
+
infra: '#64748B',
|
|
17
|
+
web: '#3B82F6',
|
|
18
|
+
}
|
|
19
|
+
const HOT = '#F97316'
|
|
20
|
+
const EXTERNAL = '#EAB308'
|
|
21
|
+
const ADDON = '#A855F7'
|
|
22
|
+
const HEALTHY = '#22C55E'
|
|
23
|
+
const ADDON_FILL = '#581C87'
|
|
24
|
+
|
|
25
|
+
function str(value: unknown): string | undefined {
|
|
26
|
+
return typeof value === 'string' && value !== '' ? value : undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function num(value: unknown): number | undefined {
|
|
30
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The card's port rows (":80 230"), or its connection total when it lists no port.
|
|
34
|
+
function trafficRows(data: Record<string, unknown>, hot: boolean): GraphBoxRow[] {
|
|
35
|
+
const rateBased = data.connLabel === 'req/s'
|
|
36
|
+
const ports = (Array.isArray(data.ports) ? data.ports : []).flatMap((p: unknown) => {
|
|
37
|
+
if (typeof p !== 'object' || p === null || !('port' in p)) return []
|
|
38
|
+
const port = num(p.port)
|
|
39
|
+
const connections = ('connections' in p ? num(p.connections) : undefined) ?? 0
|
|
40
|
+
return port ? [{ port, connections }] : []
|
|
41
|
+
})
|
|
42
|
+
if (ports.length > 0) {
|
|
43
|
+
const rows: GraphBoxRow[] = ports.slice(0, MAX_VISIBLE_PORTS).map(({ port, connections }) => ({
|
|
44
|
+
text: `:${port}`,
|
|
45
|
+
code: true,
|
|
46
|
+
hot,
|
|
47
|
+
// No figure for a port with no measured traffic, as on the card.
|
|
48
|
+
...(connections > 0 ? { value: `${formatVolume(connections, rateBased)}${rateBased ? '/s' : ''}` } : {}),
|
|
49
|
+
}))
|
|
50
|
+
if (ports.length > MAX_VISIBLE_PORTS) rows.push({ text: `+${ports.length - MAX_VISIBLE_PORTS} more`, muted: true })
|
|
51
|
+
return rows
|
|
52
|
+
}
|
|
53
|
+
const total = num(data.totalConnections)
|
|
54
|
+
return total && total > 0 ? [{ text: `${formatVolume(total, rateBased)} ${str(data.connLabel) ?? 'conn'}`, hot }] : []
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function capitalize(s: string): string {
|
|
58
|
+
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Live Traffic nodes as export boxes. Namespaces are tints on the nodes; only the addon group is a container. */
|
|
62
|
+
export const describeTrafficNode: GraphNodeMapper = ({ type, data }) => {
|
|
63
|
+
if (type === 'addonGroup') {
|
|
64
|
+
return { shape: 'group', tone: 'addon', kind: 'Addon', name: 'Cluster Addons', icon: Puzzle }
|
|
65
|
+
}
|
|
66
|
+
if (type !== 'traffic') return null
|
|
67
|
+
const kind = str(data.kind) ?? 'Unknown'
|
|
68
|
+
const name = str(data.label) ?? ''
|
|
69
|
+
if (kind === 'Internet' || kind === 'AddonInternet') {
|
|
70
|
+
return { shape: 'internet', kind, name: 'Internet', accent: kind === 'AddonInternet' ? ADDON : '#0EA5E9', icon: Globe }
|
|
71
|
+
}
|
|
72
|
+
const namespace = str(data.namespace)
|
|
73
|
+
const category = str(data.serviceCategory)
|
|
74
|
+
const isAddonNode = data.isAddonNode === true
|
|
75
|
+
const external = isExternalKind(kind)
|
|
76
|
+
const workloadKind = str(data.workloadKind)
|
|
77
|
+
const shownKind = kind === 'Workload' && workloadKind ? workloadKind : kind
|
|
78
|
+
const namespaceColor = str(data.namespaceColor)
|
|
79
|
+
const fill = isAddonNode ? ADDON_FILL : !external && kind !== 'Addon' ? namespaceColor : undefined
|
|
80
|
+
const accent = data.isHotPath === true
|
|
81
|
+
? HOT
|
|
82
|
+
: kind === 'Addon' || isAddonNode
|
|
83
|
+
? ADDON
|
|
84
|
+
: external
|
|
85
|
+
? (category && CATEGORY_COLORS[category]) || EXTERNAL
|
|
86
|
+
: HEALTHY
|
|
87
|
+
const icon = kind === 'Addon'
|
|
88
|
+
? Puzzle
|
|
89
|
+
: kind.toLowerCase() === 'unknown'
|
|
90
|
+
? CircleQuestionMark
|
|
91
|
+
: external
|
|
92
|
+
? category === 'database' ? Database : Server
|
|
93
|
+
: getTopologyIcon(shownKind)
|
|
94
|
+
const detail = namespace ?? (category ? capitalize(category) : kind === 'Addon' ? 'Monitoring, logging, etc.' : undefined)
|
|
95
|
+
const workload = str(data.workload)
|
|
96
|
+
// The card lists the workload under the namespace when it differs from the endpoint name.
|
|
97
|
+
const rows = [...(workload && workload !== name ? [{ text: workload }] : []), ...trafficRows(data, data.isHotPath === true)]
|
|
98
|
+
// External cards are washed in their category color (yellow without one), as on screen.
|
|
99
|
+
const tint = external ? (category && CATEGORY_COLORS[category] ? { color: CATEGORY_COLORS[category], opacity: 0.2 } : { color: EXTERNAL, opacity: 0.1 }) : undefined
|
|
100
|
+
return {
|
|
101
|
+
shape: 'resource',
|
|
102
|
+
kind: shownKind,
|
|
103
|
+
name,
|
|
104
|
+
kindLabel: shownKind,
|
|
105
|
+
accent,
|
|
106
|
+
icon,
|
|
107
|
+
...(detail ? { detail } : {}),
|
|
108
|
+
...(category ? { category } : {}),
|
|
109
|
+
...(fill ? { fill, textColor: '#FFFFFF' } : {}),
|
|
110
|
+
...(tint ? { tint } : {}),
|
|
111
|
+
nameFirst: true,
|
|
112
|
+
...(rows.length > 0 ? { rows } : {}),
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -876,3 +876,19 @@ export function emptyWarningHeadline(kind: TrafficWarningKind | undefined): stri
|
|
|
876
876
|
default: return 'Unable to fetch traffic data'
|
|
877
877
|
}
|
|
878
878
|
}
|
|
879
|
+
|
|
880
|
+
export function formatConnections(count: number): string {
|
|
881
|
+
if (count >= 1_000_000_000) return `${(count / 1_000_000_000).toFixed(1)}B`
|
|
882
|
+
if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M`
|
|
883
|
+
if (count >= 1_000) return `${(count / 1_000).toFixed(0)}K`
|
|
884
|
+
return count.toString()
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// A volume in the source's own unit: a rate to two significant places for a
|
|
888
|
+
// rate-based source, a whole count otherwise.
|
|
889
|
+
export function formatVolume(volume: number, isRateBased: boolean): string {
|
|
890
|
+
return isRateBased ? formatRate(volume) : formatConnections(volume)
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/** Ports a traffic card lists before "+N more". */
|
|
894
|
+
export const MAX_VISIBLE_PORTS = 4
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
5
|
+
import { WorkloadRevisionsButton } from './WorkloadRevisionsButton'
|
|
6
|
+
import { useWorkloadRevisions } from '../../api/client'
|
|
7
|
+
|
|
8
|
+
vi.mock('../../api/client', () => ({ useWorkloadRevisions: vi.fn() }))
|
|
9
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
10
|
+
vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} })
|
|
11
|
+
afterEach(() => { document.body.replaceChildren(); vi.clearAllMocks() })
|
|
12
|
+
|
|
13
|
+
it('reads only the chosen workload, compares retained templates, and has no mutation actions', async () => {
|
|
14
|
+
const data = [
|
|
15
|
+
{ number: 8, image: 'worker:v1', isCurrent: true, replicas: 2, readyReplicas: 0, matchesDesired: true, template: 'path: /healthz' },
|
|
16
|
+
{ number: 7, image: 'worker:v1', isCurrent: false, replicas: 2, readyReplicas: 2, template: 'path: /ready' },
|
|
17
|
+
]
|
|
18
|
+
vi.mocked(useWorkloadRevisions).mockReturnValue({ data, isError: false, isLoading: false, error: null } as ReturnType<typeof useWorkloadRevisions>)
|
|
19
|
+
const container = document.createElement('div')
|
|
20
|
+
document.body.append(container)
|
|
21
|
+
const root = createRoot(container)
|
|
22
|
+
await act(() => root.render(<WorkloadRevisionsButton kind="Deployment" group="apps" namespace="prod" name="worker" />))
|
|
23
|
+
expect(useWorkloadRevisions).not.toHaveBeenCalled()
|
|
24
|
+
await act(() => container.querySelector('button')!.click())
|
|
25
|
+
expect(useWorkloadRevisions).toHaveBeenCalledWith('deployments', 'prod', 'worker')
|
|
26
|
+
const dialog = document.querySelector('[role=dialog]')!
|
|
27
|
+
expect(dialog.textContent).toContain('0/2 ready')
|
|
28
|
+
expect(dialog.textContent).toContain('2/2 ready')
|
|
29
|
+
expect(dialog.textContent).not.toContain('Rollback')
|
|
30
|
+
await act(() => Array.from(dialog.querySelectorAll('button')).find(b => b.textContent === 'Diff')!.click())
|
|
31
|
+
expect(dialog.textContent).toContain('/healthz')
|
|
32
|
+
expect(dialog.textContent).toContain('/ready')
|
|
33
|
+
await act(() => root.unmount())
|
|
34
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { RevisionHistoryDialog } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { useWorkloadRevisions } from '../../api/client'
|
|
4
|
+
import { kindToPluralWithGroup } from '../../utils/navigation'
|
|
5
|
+
|
|
6
|
+
type Workload = { kind: string; group?: string; namespace: string; name: string }
|
|
7
|
+
|
|
8
|
+
export function supportsWorkloadRevisions(kind: string, group?: string) {
|
|
9
|
+
const plural = kindToPluralWithGroup(kind, group ?? '').toLowerCase()
|
|
10
|
+
return (['deployments', 'statefulsets', 'daemonsets'].includes(plural) && (!group || group === 'apps'))
|
|
11
|
+
|| (plural === 'rollouts' && group === 'argoproj.io')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function WorkloadRevisionsButton({ kind, group, namespace, name }: Workload) {
|
|
15
|
+
const plural = kindToPluralWithGroup(kind, group ?? '').toLowerCase()
|
|
16
|
+
const [openTarget, setOpenTarget] = useState<string | null>(null)
|
|
17
|
+
if (!supportsWorkloadRevisions(kind, group)) return null
|
|
18
|
+
const target = JSON.stringify([plural, namespace, name])
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<button type="button" aria-label={`Revisions for ${name}`} className="text-xs font-medium text-accent-text hover:underline" onClick={() => setOpenTarget(target)}>Revisions</button>
|
|
22
|
+
{openTarget === target && <ReadOnlyRevisions kind={plural} namespace={namespace} name={name} onClose={() => setOpenTarget(null)} />}
|
|
23
|
+
</>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function ReadOnlyRevisions({ kind, namespace, name, onClose }: Workload & { onClose: () => void }) {
|
|
28
|
+
const revisions = useWorkloadRevisions(kind, namespace, name)
|
|
29
|
+
return <RevisionHistoryDialog kind={kind} namespace={namespace} name={name} open onClose={onClose}
|
|
30
|
+
revisions={revisions.isError ? undefined : revisions.data} isLoading={revisions.isLoading} error={revisions.error} />
|
|
31
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { supportsWorkloadRevisions, WorkloadRevisionsButton } from './WorkloadRevisionsButton'
|
|
1
2
|
import { RelatedFindingsSection } from './RelatedFindingsSection'
|
|
2
3
|
import { decorateResourceDiagnose, resourceDetailRedirect, resourceDetailSlots, resourceIssueDetail, resourceLogs, resourceRendererOverrides } from '../../integrations/resourceHosts'
|
|
3
4
|
import { ApplicationEvidenceAction } from '../application-evidence/ApplicationEvidenceAction'
|
|
@@ -154,7 +155,7 @@ type TabType = WorkloadTabType
|
|
|
154
155
|
|
|
155
156
|
// The usage-report view a tab counts under. Timeline holds the resource's
|
|
156
157
|
// events (it replaced the Events tab), so it counts as panel:events.
|
|
157
|
-
const PANEL_USAGE_VIEWS: Partial<Record<TabType, string
|
|
158
|
+
const PANEL_USAGE_VIEWS: Readonly<Partial<Record<TabType | "deploys", string>>> = {
|
|
158
159
|
logs: 'panel:logs',
|
|
159
160
|
yaml: 'panel:yaml',
|
|
160
161
|
metrics: 'panel:metrics',
|
|
@@ -361,7 +362,7 @@ function useActionsBarProps(
|
|
|
361
362
|
|
|
362
363
|
const isRolloutShape = isRolloutKind(kind)
|
|
363
364
|
const isRollout = isRolloutShape && group === 'argoproj.io'
|
|
364
|
-
const isRollbackKind =
|
|
365
|
+
const isRollbackKind = supportsWorkloadRevisions(kind, group)
|
|
365
366
|
const { data: rolloutCapabilities, isPending: rolloutCapabilitiesPending } = useRolloutCapabilities(namespace, name, isRollout)
|
|
366
367
|
// Restart and Rollback are the generic workload buttons, so a Rollout has to
|
|
367
368
|
// withhold the callback the way promote-full does. Permissive until the probe
|
|
@@ -595,7 +596,7 @@ export function WorkloadView({
|
|
|
595
596
|
// recount the same open tab: the drawer mounts hidden WorkloadView layers
|
|
596
597
|
// for expand-on-hover and crossfades.
|
|
597
598
|
const handleTabChange = useCallback(
|
|
598
|
-
(tab: TabType, opts?: { replace?: boolean }) => {
|
|
599
|
+
(tab: TabType | 'deploys', opts?: { replace?: boolean }) => {
|
|
599
600
|
const panel = PANEL_USAGE_VIEWS[tab]
|
|
600
601
|
if (panel && tab !== migratedTab) recordUsageEvent({ type: 'view', name: panel })
|
|
601
602
|
const params = new URLSearchParams(searchParams)
|
|
@@ -1408,6 +1409,12 @@ export function WorkloadView({
|
|
|
1408
1409
|
</div>
|
|
1409
1410
|
)
|
|
1410
1411
|
: undefined}
|
|
1412
|
+
timelineActions={(supportsWorkloadRevisions(apiKind, effectiveGroup) || rest.extraTabs?.some(tab => tab.id === 'deploys')) && (
|
|
1413
|
+
<div className="flex flex-wrap items-center gap-3 border-b border-theme-border px-4 py-2">
|
|
1414
|
+
<WorkloadRevisionsButton kind={apiKind} group={effectiveGroup} namespace={namespace} name={name} />
|
|
1415
|
+
{rest.extraTabs?.some(tab => tab.id === 'deploys') && <button type="button" className="text-xs text-accent-text hover:underline" onClick={() => handleTabChange('deploys')}>View application deploys</button>}
|
|
1416
|
+
</div>
|
|
1417
|
+
)}
|
|
1411
1418
|
renderOverviewExtra={({ kind: k, namespace: ns, name: n, group: g, context }) => {
|
|
1412
1419
|
// Network entry kinds (Service/Ingress/Route/Gateway) ARE the diagnosis
|
|
1413
1420
|
// target: DiagnoseInlineSection renders in the drawer, no hint. Workload
|
|
@@ -1423,6 +1430,7 @@ export function WorkloadView({
|
|
|
1423
1430
|
) : null
|
|
1424
1431
|
return (
|
|
1425
1432
|
<>
|
|
1433
|
+
<WorkloadRevisionsButton kind={k} group={g} namespace={ns} name={n} />
|
|
1426
1434
|
{diagnoseInline}
|
|
1427
1435
|
<ApplicationEvidenceAction kind={k} namespace={ns} name={n} group={g} uid={resource?.metadata?.uid ?? ''} />
|
|
1428
1436
|
{diagnoseHint}
|
|
@@ -55,7 +55,7 @@ describe('application resource hosts', () => {
|
|
|
55
55
|
'RolloutRenderer', 'KyvernoPolicyCoverage', 'KyvernoPolicyQueued', 'CNPGObjectStoreRenderer',
|
|
56
56
|
'VeleroBSLRenderer', 'VeleroBackupRenderer', 'VeleroRestoreRenderer', 'CNPGClusterRenderer',
|
|
57
57
|
'CNPGDatabaseRenderer', 'CNPGPublicationRenderer', 'CNPGSubscriptionRenderer', 'CNPGImageCatalogRenderer',
|
|
58
|
-
'FluxHelmReleaseRenderer', 'OpenTelemetryCollectorRenderer', 'ValidatingAdmissionPolicyRenderer', 'ValidatingAdmissionPolicyBindingRenderer', 'SecretProviderClassRenderer', 'UpgradePlanRenderer', 'SealedSecretRenderer',
|
|
58
|
+
'FluxHelmReleaseRenderer', 'OpenTelemetryCollectorRenderer', 'ValidatingAdmissionPolicyRenderer', 'ValidatingAdmissionPolicyBindingRenderer', 'SecretProviderClassRenderer', 'UpgradePlanRenderer', 'SealedSecretRenderer', 'K3sHelmChartRenderer',
|
|
59
59
|
].sort())
|
|
60
60
|
const inherited = [{ id: 'local', label: 'Local', render: () => null }]
|
|
61
61
|
expect(resourceDetailSlots({ kind: 'Pod', group: '', namespace: 'db', name: 'pg-1' }, inherited).extraTabs).toEqual(inherited)
|
|
@@ -41,6 +41,7 @@ import { LonghornVolumeRenderer } from '../components/resources/renderers/Longho
|
|
|
41
41
|
import { FluxHelmReleaseRenderer } from '../components/resources/renderers/FluxHelmReleaseRenderer'
|
|
42
42
|
import { SecretProviderClassRenderer } from '../components/resources/renderers/SecretProviderClassRenderer'
|
|
43
43
|
import { SealedSecretRenderer } from '../components/resources/renderers/SealedSecretRenderer'
|
|
44
|
+
import { K3sHelmChartRenderer } from '../components/resources/renderers/K3sHelmChartRenderer'
|
|
44
45
|
import { UpgradePlanRenderer } from '../components/resources/renderers/UpgradePlanRenderer'
|
|
45
46
|
import {
|
|
46
47
|
ValidatingAdmissionPolicyBindingRenderer,
|
|
@@ -52,6 +53,7 @@ export const resourceHosts: readonly ResourceHost[] = [
|
|
|
52
53
|
{ id: 'gateway-api', renderers: { HTTPRouteRenderer } },
|
|
53
54
|
{ id: 'rbac', renderers: { ServiceAccountRenderer, RoleRenderer, RoleBindingRenderer, NamespaceRenderer } },
|
|
54
55
|
{ id: 'sealed-secrets', renderers: { SealedSecretRenderer } },
|
|
56
|
+
{ id: 'k3s-helm', renderers: { K3sHelmChartRenderer } },
|
|
55
57
|
{ id: 'system-upgrade', renderers: { UpgradePlanRenderer } },
|
|
56
58
|
{ id: 'batch-and-admission', renderers: { JobRenderer, JobSetRenderer, KueueWorkloadRenderer } },
|
|
57
59
|
{
|