@skyhook-io/radar-app 1.21.6 → 1.21.8

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.
Files changed (118) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -4
  4. package/src/RadarApp.tsx +8 -2
  5. package/src/api/client.discoverMetrics.test.tsx +69 -0
  6. package/src/api/client.issueCorrelation.test.tsx +244 -0
  7. package/src/api/client.issueRowChanges.test.tsx +129 -0
  8. package/src/api/client.pendingOwnership.test.tsx +197 -0
  9. package/src/api/client.prometheusStatus.test.ts +4 -0
  10. package/src/api/client.restartError.test.ts +36 -1
  11. package/src/api/client.stopWorkflow.test.tsx +133 -0
  12. package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
  13. package/src/api/client.ts +582 -114
  14. package/src/api/connectionBinding.test.tsx +3 -1
  15. package/src/api/connectionBinding.ts +14 -2
  16. package/src/api/gitOpsPermissions.render.test.tsx +155 -0
  17. package/src/api/gitOpsPermissions.test.ts +90 -0
  18. package/src/api/gitOpsPermissions.ts +51 -0
  19. package/src/api/httpErrors.test.ts +30 -1
  20. package/src/api/httpErrors.ts +17 -0
  21. package/src/api/openobserveSetup.ts +85 -0
  22. package/src/api/podDebug.test.tsx +137 -0
  23. package/src/api/podDebug.ts +82 -0
  24. package/src/api/prometheusCharts.test.ts +23 -0
  25. package/src/api/prometheusCharts.ts +25 -0
  26. package/src/api/radarFeatures.render.test.tsx +43 -2
  27. package/src/api/radarFeatures.test.ts +18 -1
  28. package/src/api/radarFeatures.ts +17 -4
  29. package/src/api/reviewedActionMutation.ts +9 -2
  30. package/src/api/workloadMetrics.ts +2 -0
  31. package/src/components/NamespaceSwitcher.tsx +6 -2
  32. package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
  33. package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
  34. package/src/components/applications/ApplicationsView.tsx +127 -173
  35. package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
  36. package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
  37. package/src/components/cnpg/host.test.tsx +1 -1
  38. package/src/components/cnpg/host.tsx +0 -2
  39. package/src/components/dock/BottomDock.tsx +7 -3
  40. package/src/components/dock/MissingShellDebug.test.tsx +193 -0
  41. package/src/components/dock/MissingShellDebug.tsx +114 -0
  42. package/src/components/dock/PodDebugSession.test.tsx +60 -0
  43. package/src/components/dock/PodDebugSession.tsx +96 -0
  44. package/src/components/dock/TerminalTab.test.tsx +48 -4
  45. package/src/components/dock/TerminalTab.tsx +47 -25
  46. package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
  47. package/src/components/dock/WorkloadLogsTab.tsx +16 -0
  48. package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
  49. package/src/components/execution/BatchExecutionView.tsx +88 -5
  50. package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
  51. package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
  52. package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
  53. package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
  54. package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
  55. package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
  56. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
  57. package/src/components/gitops/GitOpsView.tsx +93 -32
  58. package/src/components/helm/OwnedResources.tsx +1 -0
  59. package/src/components/home/HomeView.tsx +9 -1
  60. package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
  61. package/src/components/home/mcpToolCatalog.ts +1 -0
  62. package/src/components/issues/IssuesPane.render.test.tsx +78 -2
  63. package/src/components/issues/IssuesPane.tsx +49 -6
  64. package/src/components/issues/useIssueExpansion.ts +91 -0
  65. package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
  66. package/src/components/resource/MetricsNotConnected.tsx +114 -0
  67. package/src/components/resource/PVCUsageBar.tsx +2 -1
  68. package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
  69. package/src/components/resource/PrometheusCharts.tsx +14 -2
  70. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
  71. package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
  72. package/src/components/resource/RestartChart.tsx +4 -3
  73. package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
  74. package/src/components/resource/RightsizingStrip.tsx +5 -3
  75. package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
  76. package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
  77. package/src/components/resource/nameMatchedScope.ts +9 -3
  78. package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
  79. package/src/components/resources/PodDebugAction.test.tsx +157 -0
  80. package/src/components/resources/PodDebugAction.tsx +207 -0
  81. package/src/components/resources/PodDebugPermission.tsx +21 -0
  82. package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
  83. package/src/components/resources/ResourcesView.tsx +39 -5
  84. package/src/components/resources/namespaceHint.test.ts +34 -0
  85. package/src/components/resources/namespaceHint.ts +19 -0
  86. package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
  87. package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
  88. package/src/components/resources/renderers/PodRenderer.tsx +12 -5
  89. package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
  90. package/src/components/settings/FormSaveActions.tsx +6 -2
  91. package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
  92. package/src/components/settings/MetricsBackendSwitch.tsx +165 -0
  93. package/src/components/settings/OpenObserveSetup.test.tsx +384 -0
  94. package/src/components/settings/OpenObserveSetup.tsx +328 -0
  95. package/src/components/settings/SettingsDialog.tsx +21 -7
  96. package/src/components/settings/openobserveStatus.test.ts +34 -0
  97. package/src/components/settings/openobserveStatus.ts +55 -0
  98. package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
  99. package/src/components/timeline/TimelineList.test.ts +18 -0
  100. package/src/components/timeline/TimelineList.tsx +19 -5
  101. package/src/components/timeline/TimelineView.tsx +2 -0
  102. package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
  103. package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
  104. package/src/components/workload/WorkloadView.tsx +103 -16
  105. package/src/components/workspace/WorkspaceConditions.tsx +56 -0
  106. package/src/components/workspace/layout.test.tsx +20 -0
  107. package/src/components/workspace/layout.tsx +1 -1
  108. package/src/context/TimelineNavigation.test.ts +59 -0
  109. package/src/context/TimelineNavigation.tsx +86 -0
  110. package/src/contexts/CapabilitiesContext.tsx +5 -1
  111. package/src/hooks/useResourceCounts.ts +2 -1
  112. package/src/hooks/useWorkflowStopAction.ts +31 -0
  113. package/src/index.css +1 -0
  114. package/src/integrations/resourceHosts.test.tsx +2 -2
  115. package/src/integrations/resourceHosts.tsx +4 -2
  116. package/src/k8s-ui-exports.test.ts +10 -0
  117. package/src/utils/page-links.ts +15 -1
  118. package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
@@ -1,12 +1,12 @@
1
1
  import { useState, useMemo, useCallback } from 'react'
2
2
  import { useLocation, useNavigate } from 'react-router-dom'
3
3
  import { useQuery } from '@tanstack/react-query'
4
- import { fetchJSON, isForbiddenError, isKindSyncFailed, isStillLoadingError, useCapabilities, useNamespaceCapabilities, useResources, useSecretCertExpiry, useTopPodMetrics, useTopNodeMetrics, useBulkDeleteResources, useBulkRestartWorkloads, useBulkScaleWorkloads, useAuditBadges, useIssues, fetchResourceList, isListTooLargeError, isUnretryableReadError } from '../../api/client'
4
+ import { fetchJSON, useNamespaceScope, isForbiddenError, isKindSyncFailed, isStillLoadingError, useCapabilities, useNamespaceCapabilities, useResources, useSecretCertExpiry, useTopPodMetrics, useTopNodeMetrics, useBulkDeleteResources, useBulkRestartWorkloads, useBulkScaleWorkloads, useAuditBadges, useIssues, fetchResourceList, isListTooLargeError, isUnretryableReadError, useRadarFeature } from '../../api/client'
5
5
  import { isBadgeWorthy } from '../../utils/auditBadges'
6
6
  import { ISSUE_SEVERITY_RANK } from '@skyhook-io/k8s-ui'
7
7
  import type { Issue, AuditBadgeMessage } from '@skyhook-io/k8s-ui'
8
8
  import { stripBasename } from '../../api/config'
9
- import { createListRefetchInterval, type ResourceListResult } from '../../api/resourceLists'
9
+ import { createListRefetchInterval, listSyncPending, type ResourceListResult } from '../../api/resourceLists'
10
10
  import { useAPIResources } from '../../api/apiResources'
11
11
  import { useConnection } from '../../context/ConnectionContext'
12
12
  import { getSecretStoreProviderType } from '@skyhook-io/k8s-ui'
@@ -26,11 +26,13 @@ import {
26
26
  intersectWorkloadWrites,
27
27
  hasCuratedColumns,
28
28
  } from '@skyhook-io/k8s-ui'
29
- import type { Capabilities, ResourceQueryResult, WorkloadWritePermissions } from '@skyhook-io/k8s-ui'
29
+ import type { APIResource, Capabilities, ResourceQueryResult, WorkloadWritePermissions } from '@skyhook-io/k8s-ui'
30
30
  import type { SelectedResource } from '../../types'
31
31
  import { apiVersionToGroup, kindToPluralWithGroup, type NavigateToResource } from '../../utils/navigation'
32
32
  import { CreateResourceDialog } from '../shared/CreateResourceDialog'
33
33
  import { getSkeletonYaml } from '../../utils/skeleton-yaml'
34
+ import { EmptyNamespaceHint } from './EmptyNamespaceHint'
35
+ import { emptyNamespaceHint } from './namespaceHint'
34
36
 
35
37
  interface ResourcesViewProps {
36
38
  namespaces: string[]
@@ -73,6 +75,13 @@ function resourceCountKey(kind: NonNullable<SelectedKindInfo>): string {
73
75
  return kind.group ? `${kind.group}/${kind.kind}` : kind.kind
74
76
  }
75
77
 
78
+ function namespacedKind(apiResources: APIResource[] | undefined, kind: SelectedKindInfo): boolean {
79
+ if (!kind) return false
80
+ const match = apiResources?.find(r => r.name === kind.name && r.group === kind.group)
81
+ ?? CORE_RESOURCES.find(r => r.name === kind.name && r.group === kind.group)
82
+ return match?.namespaced ?? false
83
+ }
84
+
76
85
  function hasResourceCount(counts: Record<string, number> | undefined, key: string): boolean {
77
86
  return Object.prototype.hasOwnProperty.call(counts ?? {}, key)
78
87
  }
@@ -81,6 +90,7 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
81
90
  const location = useLocation()
82
91
  const navigate = useNavigate()
83
92
  const { connection } = useConnection()
93
+ const { data: namespaceScope } = useNamespaceScope()
84
94
 
85
95
  const { data: capabilities, isPending: capabilitiesPending } = useCapabilities()
86
96
  const hostFeatures = useResourceHostFeatures()
@@ -187,7 +197,9 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
187
197
  return map
188
198
  }, [audit.data?.findings, audit.data?.checks, selectedKind, selectedKindCanonical])
189
199
 
190
- const selectedCountKey = selectedKind ? resourceCountKey(selectedKind) : ''
200
+ const selectedCountKey = selectedKind && selectedKindCanonical
201
+ ? resourceCountKey({ ...selectedKind, kind: selectedKindCanonical })
202
+ : ''
191
203
  const selectedCount = selectedCountKey ? countsData?.counts[selectedCountKey] : undefined
192
204
  const selectedCountKnown = selectedCountKey ? hasResourceCount(countsData?.counts, selectedCountKey) : false
193
205
  const selectedCountUnavailable = selectedCountKey ? countsData?.unavailable?.includes(selectedCountKey) ?? false : false
@@ -239,6 +251,8 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
239
251
 
240
252
  const loadingInterval = useMemo(() => createListRefetchInterval(120000), [])
241
253
 
254
+ const selectedKindListsAsTable = resourceKindListMode(selectedKind, hostFeatures, capabilitiesPending) === 'table'
255
+
242
256
  // Fetch full data only for the selected kind
243
257
  const selectedKindQuery = useQuery({
244
258
  queryKey: ['resources', selectedKind?.name, isSelectedCrd ? selectedKind?.group : '', namespaces],
@@ -254,7 +268,7 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
254
268
  summary: selectedKindSummaryServed, table: wantsTable, signal,
255
269
  })
256
270
  },
257
- enabled: !!selectedKind && !selectedKindQueryBlocked && resourceKindListMode(selectedKind, hostFeatures, capabilitiesPending) === 'table',
271
+ enabled: !!selectedKind && !selectedKindQueryBlocked && selectedKindListsAsTable,
258
272
  staleTime: 30000,
259
273
  // Safety net — SSE k8s_event drives near-real-time invalidation. A list
260
274
  // whose namespaces are still loading is re-read until they finish.
@@ -286,6 +300,21 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
286
300
  }
287
301
  }, [selectedKind, selectedKindQueryBlocked, waitingForGuardCount, selectedKindQuery.data?.items, selectedKindQuery.data?.coverage, selectedKindQuery.isLoading, selectedKindQuery.error, selectedKindQuery.refetch, selectedKindQuery.dataUpdatedAt])
288
302
 
303
+ // An empty filtered list reads as "there are none" unless it says what the
304
+ // filter hides. Under --namespace-scope the cache holds no other namespace,
305
+ // so there is nothing to count. The All-namespaces counts are the query the
306
+ // sidebar runs at All, and it runs only while a filtered list is empty.
307
+ const selectedKindRows = selectedKindQueryResult && !selectedKindQueryResult.isLoading && !largeListGuard ? selectedKindQueryResult.data?.length : undefined
308
+ const selectedKindNamespaced = namespacedKind(apiResources, selectedKind)
309
+ const wantsEmptyHint = namespaces.length > 0 && selectedKindRows === 0 && selectedKindNamespaced &&
310
+ namespaceScope?.cacheScoped === false && !listSyncPending(selectedKindQueryResult?.coverage) && selectedKindListsAsTable
311
+ const { data: allNamespaceCounts } = useResourceCounts([], { enabled: wantsEmptyHint })
312
+ const emptyHint = useMemo(() => {
313
+ if (!wantsEmptyHint || !selectedCountKey) return null
314
+ const total = hasResourceCount(allNamespaceCounts?.counts, selectedCountKey) ? allNamespaceCounts?.counts[selectedCountKey] : undefined
315
+ return emptyNamespaceHint(total, allNamespaceCounts?.coverage?.[selectedCountKey])
316
+ }, [wantsEmptyHint, selectedCountKey, allNamespaceCounts])
317
+
289
318
  // Metrics
290
319
  const { data: topPodMetrics } = useTopPodMetrics({ enabled: topPodMetricsEnabled, namespaces })
291
320
  const { data: topNodeMetrics } = useTopNodeMetrics({ enabled: topNodeMetricsEnabled })
@@ -323,6 +352,7 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
323
352
  // Dock actions
324
353
  const openLogs = useOpenLogs()
325
354
  const openWorkloadLogs = useOpenWorkloadLogs()
355
+ const { support: replicaSetLogSupport } = useRadarFeature('replicaSetLogs')
326
356
 
327
357
  // Bulk delete
328
358
  const bulkDeleteMutation = useBulkDeleteResources()
@@ -385,6 +415,9 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
385
415
  rememberedKindSearch={rememberedKindSearch}
386
416
  onKindFiltersChange={onKindFiltersChange}
387
417
  onApplyNamespacesToAllSections={onApplyNamespacesToAllSections}
418
+ emptyScopeHint={emptyHint && selectedKindCanonical
419
+ ? <EmptyNamespaceHint hint={emptyHint} namespaces={namespaces} kind={selectedKindCanonical} onShowAll={namespaceScope?.canClearNamespace ? onClearNamespaces : undefined} />
420
+ : undefined}
388
421
  // Injected data
389
422
  apiResources={apiResources}
390
423
  // Lightweight counts for sidebar (replaces 233 parallel queries)
@@ -427,6 +460,7 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
427
460
  // Dock actions
428
461
  onOpenLogs={openLogs}
429
462
  onOpenWorkloadLogs={openWorkloadLogs}
463
+ replicaSetLogs={replicaSetLogSupport === 'supported'}
430
464
  // Create resource
431
465
  onCreateResource={handleCreateResource}
432
466
  renderKindView={renderKindView}
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import type { ResourceCoverage } from '@skyhook-io/k8s-ui'
3
+ import { emptyNamespaceHint } from './namespaceHint'
4
+
5
+ const complete: ResourceCoverage = { status: 'complete', scope: { type: 'all_namespaces' }, gaps: [] }
6
+ const partial: ResourceCoverage = { status: 'partial', scope: { type: 'all_namespaces' }, gaps: [] }
7
+ const narrowed: ResourceCoverage = {
8
+ status: 'complete',
9
+ scope: { type: 'all_namespaces' },
10
+ narrowedBy: ['user_access'],
11
+ gaps: [],
12
+ }
13
+
14
+ describe('emptyNamespaceHint', () => {
15
+ it('counts what exists in other namespaces', () => {
16
+ expect(emptyNamespaceHint(15, complete)).toEqual({ type: 'elsewhere', count: 15, atLeast: false })
17
+ })
18
+
19
+ it('treats a partial or access-narrowed count as a lower bound', () => {
20
+ expect(emptyNamespaceHint(15, partial)).toEqual({ type: 'elsewhere', count: 15, atLeast: true })
21
+ expect(emptyNamespaceHint(15, narrowed)).toEqual({ type: 'elsewhere', count: 15, atLeast: true })
22
+ expect(emptyNamespaceHint(15, undefined)).toEqual({ type: 'elsewhere', count: 15, atLeast: true })
23
+ })
24
+
25
+ it('says none elsewhere only when the count covers every namespace', () => {
26
+ expect(emptyNamespaceHint(0, complete)).toEqual({ type: 'none-elsewhere' })
27
+ expect(emptyNamespaceHint(0, partial)).toBeNull()
28
+ expect(emptyNamespaceHint(0, narrowed)).toBeNull()
29
+ })
30
+
31
+ it('says nothing without a count', () => {
32
+ expect(emptyNamespaceHint(undefined, complete)).toBeNull()
33
+ })
34
+ })
@@ -0,0 +1,19 @@
1
+ import type { ResourceCoverage } from '@skyhook-io/k8s-ui'
2
+
3
+ export type EmptyNamespaceHint =
4
+ | { type: 'elsewhere'; count: number; atLeast: boolean }
5
+ | { type: 'none-elsewhere' }
6
+
7
+ /**
8
+ * What an empty, namespace-filtered list says about the rest of the cluster,
9
+ * from the kind's count across every namespace the caller can read.
10
+ *
11
+ * A count Radar couldn't fully read, or one narrowed by the caller's access,
12
+ * is a lower bound, so it can't back "none in other namespaces".
13
+ */
14
+ export function emptyNamespaceHint(total: number | undefined, coverage: ResourceCoverage | undefined): EmptyNamespaceHint | null {
15
+ if (total === undefined) return null
16
+ const complete = coverage?.status === 'complete' && !coverage.narrowedBy?.length
17
+ if (total > 0) return { type: 'elsewhere', count: total, atLeast: !complete }
18
+ return complete ? { type: 'none-elsewhere' } : null
19
+ }
@@ -0,0 +1,135 @@
1
+ import { Link2 } from 'lucide-react'
2
+ import {
3
+ RelationshipGroup,
4
+ ResourceLink,
5
+ Section,
6
+ type ResourceRef,
7
+ } from '@skyhook-io/k8s-ui'
8
+ import { isFetchError, isForbiddenError } from '@skyhook-io/k8s-ui/types/fetch-error'
9
+ import { LookupFailureNote } from '@skyhook-io/k8s-ui/components/resources/renderers/LookupFailureNote'
10
+ import {
11
+ ValidatingAdmissionPolicyBindingRenderer as BaseBindingRenderer,
12
+ ValidatingAdmissionPolicyRenderer as BasePolicyRenderer,
13
+ } from '@skyhook-io/k8s-ui/components/resources/renderers/ValidatingAdmissionPolicyRenderers'
14
+ import {
15
+ MutatingAdmissionPolicyBindingRenderer as BaseMutatingBinding,
16
+ MutatingAdmissionPolicyRenderer as BaseMutatingPolicy,
17
+ } from '@skyhook-io/k8s-ui/components/resources/renderers/MutatingAdmissionPolicyRenderers'
18
+ import { useResources, useResourceWithRelationships } from '../../../api/client'
19
+
20
+ const ADMISSION_REGISTRATION_GROUP = 'admissionregistration.k8s.io'
21
+
22
+ interface AdmissionProps {
23
+ data: any
24
+ onNavigate?: (ref: ResourceRef) => void
25
+ }
26
+
27
+ export function ValidatingAdmissionPolicyRenderer(props: AdmissionProps) {
28
+ return <BasePolicyRenderer {...props} bindings={<PolicyBindings {...props} mutating={false} />} />
29
+ }
30
+
31
+ export function MutatingAdmissionPolicyRenderer(props: AdmissionProps) {
32
+ return <BaseMutatingPolicy {...props} bindings={<PolicyBindings {...props} mutating />} />
33
+ }
34
+
35
+ function PolicyBindings({ data, onNavigate, mutating }: AdmissionProps & { mutating: boolean }) {
36
+ const name = data?.metadata?.name
37
+ const query = useResources<any>(
38
+ mutating ? 'mutatingadmissionpolicybindings' : 'validatingadmissionpolicybindings',
39
+ undefined,
40
+ ADMISSION_REGISTRATION_GROUP,
41
+ { enabled: Boolean(name), refetchInterval: 30000 },
42
+ )
43
+ const denied = isForbiddenError(query.error)
44
+ const bindings = denied ? [] : (query.data ?? []).filter(binding => binding?.spec?.policyName === name)
45
+ const bindingLookupComplete = query.coverage?.status === 'complete' && !query.error
46
+ const bindingTitle = bindingLookupComplete
47
+ ? `Bindings (${bindings.length})`
48
+ : bindings.length > 0 ? `Bindings (${bindings.length}+)` : 'Bindings'
49
+ const refs = bindings.map(binding => ({
50
+ kind: mutating ? 'MutatingAdmissionPolicyBinding' : 'ValidatingAdmissionPolicyBinding',
51
+ namespace: '',
52
+ name: binding?.metadata?.name ?? '',
53
+ group: ADMISSION_REGISTRATION_GROUP,
54
+ }))
55
+
56
+ return (
57
+ <Section title={bindingTitle} icon={Link2} defaultExpanded>
58
+ {query.isLoading ? (
59
+ <div className="text-sm text-theme-text-tertiary">Looking for readable bindings…</div>
60
+ ) : query.error && bindings.length === 0 ? (
61
+ <LookupFailureNote errors={[query.error]} what="which bindings select this policy" />
62
+ ) : bindings.length === 0 && bindingLookupComplete ? (
63
+ <div className="text-sm text-theme-text-tertiary">
64
+ No readable bindings select this policy; this policy has no effect.
65
+ </div>
66
+ ) : bindings.length === 0 ? (
67
+ <div className="text-sm text-theme-text-tertiary">
68
+ Binding availability could not be established; this policy may still have readable bindings.
69
+ </div>
70
+ ) : (
71
+ <div className="space-y-2">
72
+ {!bindingLookupComplete && !query.error && (
73
+ <div className="text-sm text-theme-text-tertiary">
74
+ This list may be incomplete; binding coverage could not be confirmed.
75
+ </div>
76
+ )}
77
+ <LookupFailureNote
78
+ errors={[query.error]}
79
+ what="which bindings select this policy"
80
+ incomplete
81
+ />
82
+ <RelationshipGroup label="Select this policy" refs={refs} onNavigate={onNavigate} />
83
+ </div>
84
+ )}
85
+ </Section>
86
+ )
87
+ }
88
+
89
+ export function ValidatingAdmissionPolicyBindingRenderer(props: AdmissionProps) {
90
+ return <BaseBindingRenderer {...props} policyReference={<PolicyReference {...props} kind="validatingadmissionpolicies" />} />
91
+ }
92
+
93
+ export function MutatingAdmissionPolicyBindingRenderer(props: AdmissionProps) {
94
+ return <BaseMutatingBinding {...props} policyReference={<PolicyReference {...props} kind="mutatingadmissionpolicies" />} />
95
+ }
96
+
97
+ function PolicyReference({ data, onNavigate, kind }: AdmissionProps & { kind: string }) {
98
+ const policyName = data?.spec?.policyName ?? ''
99
+ const query = useResourceWithRelationships<any>(
100
+ kind,
101
+ '',
102
+ policyName,
103
+ ADMISSION_REGISTRATION_GROUP,
104
+ )
105
+ const status = isFetchError(query.error) ? query.error.status : undefined
106
+ if (!policyName) return <>Not specified</>
107
+ return query.isLoading ? (
108
+ <ReferenceState name={policyName} note="Checking policy availability…" />
109
+ ) : status === 404 ? (
110
+ <ReferenceState name={policyName} note="Referenced policy was not found." />
111
+ ) : status === 403 ? (
112
+ <ReferenceState name={policyName} note="Not permitted to check policy availability." />
113
+ ) : query.error ? (
114
+ <ReferenceState name={policyName} note="Could not check policy availability." />
115
+ ) : query.data ? (
116
+ <ResourceLink
117
+ name={policyName}
118
+ kind={kind}
119
+ namespace=""
120
+ group={ADMISSION_REGISTRATION_GROUP}
121
+ onNavigate={onNavigate}
122
+ />
123
+ ) : (
124
+ <ReferenceState name={policyName} note="Policy availability was not checked." />
125
+ )
126
+ }
127
+
128
+ function ReferenceState({ name, note }: { name: string; note: string }) {
129
+ return (
130
+ <span className="space-y-0.5">
131
+ <span className="block">{name || 'Not specified'}</span>
132
+ <span className="block text-xs text-theme-text-tertiary">{note}</span>
133
+ </span>
134
+ )
135
+ }
@@ -1,3 +1,4 @@
1
+ import { hasPrometheusCharts } from '../../../api/prometheusCharts'
1
2
  import { NodeRenderer as BaseNodeRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/NodeRenderer'
2
3
  import { useNavigate } from 'react-router-dom'
3
4
  import { getVisibleLiveMetrics, isLiveMetricsUnavailable, shouldFetchLiveMetrics, useNodeRemovalPlan, useNodeMetrics, useNodeMetricsHistory, usePrometheusResourceMetrics, usePrometheusStatus } from '../../../api/client'
@@ -26,7 +27,7 @@ export function NodeRenderer({ data, relationships }: NodeRendererProps) {
26
27
 
27
28
  // Determine whether to hide metrics-server section (Prometheus has data)
28
29
  const { data: prometheusStatus } = usePrometheusStatus()
29
- const prometheusConnected = prometheusStatus?.connected === true
30
+ const prometheusConnected = hasPrometheusCharts(prometheusStatus)
30
31
  const { data: prometheusCPU, isLoading: prometheusCPULoading, error: prometheusCPUError } = usePrometheusResourceMetrics(
31
32
  'Node', '', nodeName ?? '', 'cpu', '1h', prometheusConnected,
32
33
  )
@@ -1,3 +1,7 @@
1
+ import { connectionHeaderValue } from '../../../api/connectionBinding'
2
+ import { usePodDetailAccess } from '../PodDebugAction'
3
+ import { getApiBase } from '../../../api/config'
4
+ import { hasPrometheusCharts } from '../../../api/prometheusCharts'
1
5
  import { PodRenderer as BasePodRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/PodRenderer'
2
6
  import type { CopyHandler } from '@skyhook-io/k8s-ui/components/ui/drawer-components'
3
7
  import { getPodNetworks, uniqueNetworkAttachmentRefs } from '@skyhook-io/k8s-ui/utils/multus'
@@ -48,10 +52,9 @@ export function PodRenderer({ data, onCopy, copied, onNavigate, onOpenLogs, reso
48
52
  const awaitsScheduling = podAwaitsScheduling(data)
49
53
 
50
54
  // Capabilities (namespace-scoped: re-checks RBAC if globally denied)
51
- const { canExec, canViewLogs, canPortForward } = useNamespacedCapabilities(namespace)
52
- // Show the port-forward affordance for a live forward (local + RBAC) OR when
53
- // not local — in-cluster/Cloud surfaces a copy-paste kubectl command instead.
54
- // The button itself picks live vs. copy-command based on deployment mode.
55
+ const nsCaps = useNamespacedCapabilities(namespace)
56
+ const { canViewLogs, canPortForward } = nsCaps
57
+ const { canExec, canOpenEphemeralTerminal } = usePodDetailAccess(data, nsCaps)
55
58
  const isLocal = useIsLocalDeployment()
56
59
  const showPortForward = canPortForward || !isLocal
57
60
 
@@ -66,7 +69,7 @@ export function PodRenderer({ data, onCopy, copied, onNavigate, onOpenLogs, reso
66
69
 
67
70
  // Hide metrics-server section when Prometheus has CPU data
68
71
  const { data: prometheusStatus } = usePrometheusStatus()
69
- const prometheusConnected = prometheusStatus?.connected === true
72
+ const prometheusConnected = hasPrometheusCharts(prometheusStatus)
70
73
  const { data: prometheusCPU, isLoading: prometheusCPULoading, error: prometheusCPUError } = usePrometheusResourceMetrics(
71
74
  'Pod', namespace ?? '', podName ?? '', 'cpu', '1h', prometheusConnected,
72
75
  )
@@ -143,6 +146,10 @@ export function PodRenderer({ data, onCopy, copied, onNavigate, onOpenLogs, reso
143
146
  canViewLogs={canViewLogs}
144
147
  canPortForward={showPortForward}
145
148
  onOpenTerminal={(params) => openTerminal(params)}
149
+ onOpenEphemeralTerminal={canOpenEphemeralTerminal ? (name, image) => openTerminal({
150
+ namespace, podName, containerName: name, containers: [name],
151
+ debugSession: { podUID: data.metadata.uid, image, connectionId: connectionHeaderValue(), apiBase: getApiBase() },
152
+ }) : undefined}
146
153
  onOpenLogsPanel={(params) => openLogsPanel(params)}
147
154
  renderPortAction={({ namespace: ns, podName: pod, port, protocol, disabled }) => (
148
155
  <PortForwardInlineButton
@@ -1,9 +1,11 @@
1
1
  import { renderToStaticMarkup } from 'react-dom/server'
2
2
  import { beforeEach, describe, expect, it, vi } from 'vitest'
3
3
  import {
4
+ MutatingAdmissionPolicyBindingRenderer,
5
+ MutatingAdmissionPolicyRenderer,
4
6
  ValidatingAdmissionPolicyBindingRenderer,
5
7
  ValidatingAdmissionPolicyRenderer,
6
- } from './ValidatingAdmissionPolicyRenderer'
8
+ } from './AdmissionPolicyRenderers'
7
9
 
8
10
  const mock = vi.hoisted(() => ({
9
11
  query: {} as any,
@@ -158,3 +160,24 @@ describe('ValidatingAdmissionPolicy reverse binding lookup', () => {
158
160
  expect(present).toContain('>require-owner</button>')
159
161
  })
160
162
  })
163
+
164
+ describe('mutating admission policy relationships', () => {
165
+ it('reads the mutating binding kind and withholds cached rows after permission loss', () => {
166
+ mock.query = { data: [binding('owner-prod', 'require-owner')], coverage: { status: 'complete' }, isLoading: false }
167
+ const renderMutating = () => renderToStaticMarkup(<MutatingAdmissionPolicyRenderer data={policy} />)
168
+ expect(renderMutating()).toContain('owner-prod')
169
+ expect(mock.reads[0][0]).toBe('mutatingadmissionpolicybindings')
170
+ mock.query.error = { status: 403, message: 'Forbidden' }
171
+ const html = renderMutating()
172
+ expect(html).not.toContain('owner-prod')
173
+ expect(html).toContain('permission')
174
+ })
175
+
176
+ it('looks up its policy in the mutating API without requesting parameters', () => {
177
+ mock.policyQuery = { data: { resource: policy } }
178
+ const html = renderToStaticMarkup(<MutatingAdmissionPolicyBindingRenderer data={binding('team', 'require-owner')} onNavigate={() => {}} />)
179
+ expect(html).toContain('>require-owner</button>')
180
+ expect(mock.policyReads[0]).toEqual(['mutatingadmissionpolicies', '', 'require-owner', 'admissionregistration.k8s.io'])
181
+ expect(mock.reads).toHaveLength(0)
182
+ })
183
+ })
@@ -13,6 +13,8 @@ export function FormSaveActions({
13
13
  onDiscard,
14
14
  feedback,
15
15
  error,
16
+ saveLabel = "Save changes",
17
+ canSave = dirty,
16
18
  }: {
17
19
  dirty: boolean;
18
20
  busy: boolean;
@@ -20,6 +22,8 @@ export function FormSaveActions({
20
22
  onDiscard: () => void;
21
23
  feedback?: FormFeedback;
22
24
  error?: string;
25
+ saveLabel?: string;
26
+ canSave?: boolean;
23
27
  }) {
24
28
  const success = !dirty && !busy && !error && feedback?.tone === "success";
25
29
  const detail =
@@ -29,11 +33,11 @@ export function FormSaveActions({
29
33
  <div className="flex min-h-8 flex-wrap items-center gap-3">
30
34
  <button
31
35
  type="button"
32
- disabled={!dirty || busy}
36
+ disabled={!canSave || busy}
33
37
  onClick={onSave}
34
38
  className="btn-brand min-w-28 px-3 py-2 text-xs"
35
39
  >
36
- {busy ? "Saving…" : "Save changes"}
40
+ {busy ? "Saving…" : saveLabel}
37
41
  </button>
38
42
  {success && (
39
43
  <span
@@ -1,5 +1,6 @@
1
1
  import { useOpenCostSummary, usePrometheusStatus, type useArgoStatus } from '../../api/client'
2
2
  import { costIntegrationUnavailableMessage, costSourceLabel } from '../cost/source'
3
+ import { metricsSourceLine, sourceNote } from './openobserveStatus'
3
4
  import type { IntegrationKind, IntegrationProfile } from './LocalConnectionSettings'
4
5
  import { Badge, Collapse } from '@skyhook-io/k8s-ui'
5
6
  import { useRef } from 'react'
@@ -20,11 +21,21 @@ export function LocalIntegrationStatus({ kind, profile, argo, busy, changedAt }:
20
21
  Math.max(query.dataUpdatedAt, query.errorUpdatedAt) < changedAt
21
22
  let status = 'Checking…'
22
23
  let detail: string | undefined
24
+ let sourceTone: 'success' | 'warning' | 'neutral' | undefined
23
25
  if (!checking) {
24
26
  if (query.isError) status = 'Status unavailable'
25
27
  else if (kind === 'metrics' && prom.data) {
26
- status = prom.data.connected ? 'Connected' : prom.data.discovering ? 'Discovering…' : 'Not connected'
27
- detail = prom.data.connected ? !profile.url ? `Discovered: ${prom.data.address}` : undefined : prom.data.error
28
+ const line = metricsSourceLine(prom.data.source)
29
+ if (line) {
30
+ status = line.status
31
+ detail = line.detail
32
+ sourceTone = line.tone
33
+ } else {
34
+ status = prom.data.connected ? 'Connected' : prom.data.gkeSystemMetrics ? 'GKE system metrics' : prom.data.discovering ? 'Discovering…' : 'Not connected'
35
+ detail = prom.data.connected ? !profile.url ? `Discovered: ${prom.data.address}` : undefined : prom.data.gkeSystemMetrics ? undefined : prom.data.error
36
+ const note = sourceNote(prom.data.source)
37
+ if (note) detail = detail ? `${detail} · ${note}` : note
38
+ }
28
39
  } else if (kind === 'argocd' && argo.data) {
29
40
  status = argo.data.connected ? argo.data.anonymous ? 'Connected · no token needed' : 'Connected' : argo.data.connecting ? 'Connecting…' : 'Not connected'
30
41
  detail = argo.data.reason ?? (argo.data.connected && !profile.url ? `Discovered: ${argo.data.address}` : undefined)
@@ -40,7 +51,7 @@ export function LocalIntegrationStatus({ kind, profile, argo, busy, changedAt }:
40
51
  const failed = !checking && (query.isError || configured && ['Not connected', 'Unavailable', 'No cost data'].includes(status))
41
52
  return (
42
53
  <div role="group" className="contents text-xs text-theme-text-secondary" aria-label="Current connection">
43
- <Badge severity={status.startsWith('Connected') || status.startsWith('Available') ? 'success' : failed ? 'warning' : 'neutral'}>{status}</Badge>
54
+ <Badge severity={sourceTone ?? (status.startsWith('Connected') || status.startsWith('Available') ? 'success' : failed ? 'warning' : 'neutral')}>{status}</Badge>
44
55
  <Collapse open={lastDetail.current.visible} className="basis-full min-w-0">
45
56
  <p className={`break-words text-theme-text-tertiary ${checking ? 'invisible' : ''}`}>{lastDetail.current.text}</p>
46
57
  </Collapse>
@@ -0,0 +1,165 @@
1
+ import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
2
+ import { clsx } from 'clsx'
3
+ import {
4
+ getOpenObserveState,
5
+ removeOpenObserveCluster,
6
+ type OpenObserveState,
7
+ } from '../../api/openobserveSetup'
8
+ import { OpenObserveSetup } from './OpenObserveSetup'
9
+
10
+ type Backend = 'prometheus' | 'openobserve'
11
+
12
+ const OPTIONS: { value: Backend; title: string; description: string }[] = [
13
+ { value: 'prometheus', title: 'Prometheus-compatible', description: 'Prometheus, VictoriaMetrics, Thanos or Grafana Mimir.' },
14
+ { value: 'openobserve', title: 'OpenObserve', description: 'Read this cluster’s metrics from OpenObserve, filtered to this cluster.' },
15
+ ]
16
+
17
+ export interface PrometheusViewProps {
18
+ status?: ReactNode
19
+ onDirtyChange: (dirty: boolean) => void
20
+ onBusyChange: (busy: boolean) => void
21
+ }
22
+
23
+ export function MetricsBackendSwitch({
24
+ locked = false,
25
+ status,
26
+ prometheus,
27
+ onChanged,
28
+ onDirtyChange,
29
+ onBusyChange,
30
+ }: {
31
+ locked?: boolean
32
+ status?: ReactNode
33
+ prometheus: (props: PrometheusViewProps) => ReactNode
34
+ onChanged: () => void
35
+ onDirtyChange?: (dirty: boolean) => void
36
+ onBusyChange?: (busy: boolean) => void
37
+ }) {
38
+ const [data, setData] = useState<OpenObserveState | null>(null)
39
+ const [loadError, setLoadError] = useState('')
40
+ const [retry, setRetry] = useState(0)
41
+ const [picked, setChoice] = useState<Backend | null>(null)
42
+ const [promDirty, setPromDirty] = useState(false)
43
+ const [promBusy, setPromBusy] = useState(false)
44
+ const [ooDirty, setOoDirty] = useState(false)
45
+ const [ooBusy, setOoBusy] = useState(false)
46
+ const [releasing, setReleasing] = useState(false)
47
+ const [releaseError, setReleaseError] = useState('')
48
+ const busy = promBusy || ooBusy || releasing
49
+ const choice: Backend | null = picked ?? (loadError ? 'prometheus' : null)
50
+
51
+ useEffect(() => {
52
+ const controller = new AbortController()
53
+ getOpenObserveState(controller.signal)
54
+ .then((next) => {
55
+ if (controller.signal.aborted) return
56
+ setData(next)
57
+ setLoadError('')
58
+ setChoice((current) => current ?? (next.cluster.match ? 'openobserve' : 'prometheus'))
59
+ })
60
+ .catch((error: unknown) => {
61
+ if (controller.signal.aborted) return
62
+ setLoadError(error instanceof Error ? error.message : String(error))
63
+ })
64
+ return () => controller.abort()
65
+ }, [retry])
66
+
67
+ useEffect(() => onDirtyChange?.(promDirty || ooDirty), [promDirty, ooDirty, onDirtyChange])
68
+ useEffect(() => onBusyChange?.(busy), [busy, onBusyChange])
69
+
70
+ // The Prometheus form restores focus in the same commit it reports idle, so
71
+ // the dialog must hear it then: a parent still marked busy keeps the pane inert.
72
+ const reported = useRef({ promDirty: false, ooDirty: false, promBusy: false, ooBusy: false, releasing: false })
73
+ reported.current = { promDirty, ooDirty, promBusy, ooBusy, releasing }
74
+ const promDirtyChange = useCallback((dirty: boolean) => {
75
+ setPromDirty(dirty)
76
+ onDirtyChange?.(dirty || reported.current.ooDirty)
77
+ }, [onDirtyChange])
78
+ const promBusyChange = useCallback((next: boolean) => {
79
+ setPromBusy(next)
80
+ onBusyChange?.(next || reported.current.ooBusy || reported.current.releasing)
81
+ }, [onBusyChange])
82
+
83
+ const releaseCluster = async () => {
84
+ setReleasing(true)
85
+ setReleaseError('')
86
+ try {
87
+ setData(await removeOpenObserveCluster(data?.cluster.uid))
88
+ onChanged()
89
+ } catch (error) {
90
+ setReleaseError(error instanceof Error ? error.message : String(error))
91
+ } finally {
92
+ setReleasing(false)
93
+ }
94
+ }
95
+
96
+ const statusRow = status ? <div className="flex flex-wrap items-center gap-x-3 gap-y-1">{status}</div> : null
97
+ const matched = !!data?.cluster.match
98
+ // The status describes where metrics come from now, whichever view is open.
99
+ const active: Backend = matched ? 'openobserve' : 'prometheus'
100
+
101
+ return (
102
+ <div className="space-y-4">
103
+ <div role="radiogroup" aria-label="Metrics backend" className="grid gap-2 sm:grid-cols-2">
104
+ {OPTIONS.map((option) => {
105
+ const selected = choice === option.value
106
+ return (
107
+ <button
108
+ key={option.value}
109
+ type="button"
110
+ role="radio"
111
+ aria-checked={selected}
112
+ disabled={locked || busy || !choice}
113
+ onClick={() => setChoice(option.value)}
114
+ className={clsx(
115
+ 'rounded-lg border px-3 py-2 text-left transition-colors',
116
+ selected ? 'border-accent bg-accent-muted' : 'border-theme-border',
117
+ !selected && !locked && !busy && 'hover:bg-theme-hover',
118
+ (locked || busy) && 'cursor-not-allowed'
119
+ )}
120
+ >
121
+ <span className="block text-sm font-medium text-theme-text-primary">{option.title}</span>
122
+ <span className="mt-0.5 block text-xs text-theme-text-tertiary">{option.description}</span>
123
+ </button>
124
+ )
125
+ })}
126
+ </div>
127
+ {!choice && <p role="status" className="text-xs text-theme-text-tertiary">Checking the metrics backend…</p>}
128
+ <div className={clsx('space-y-4', choice !== 'prometheus' && 'hidden')} inert={choice !== 'prometheus' || undefined}>
129
+ {matched && !locked && (
130
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">
131
+ <span className="text-warning-text">This cluster still reads from OpenObserve.</span>
132
+ <button type="button" disabled={busy} onClick={() => void releaseCluster()} className="text-accent-text hover:underline">
133
+ {releasing ? 'Switching…' : 'Use Prometheus for this cluster'}
134
+ </button>
135
+ {releaseError && <span role="alert" className="basis-full text-semantic-error">{releaseError}</span>}
136
+ </div>
137
+ )}
138
+ {locked
139
+ ? active === 'prometheus' && statusRow
140
+ : prometheus({ status: active === 'prometheus' ? status : undefined, onDirtyChange: promDirtyChange, onBusyChange: promBusyChange })}
141
+ </div>
142
+ <div className={clsx(choice !== 'openobserve' && 'hidden')} inert={choice !== 'openobserve' || undefined}>
143
+ {data ? (
144
+ <OpenObserveSetup
145
+ state={data}
146
+ locked={locked}
147
+ status={active === 'openobserve' ? status : undefined}
148
+ onStateChange={(next) => {
149
+ setData(next)
150
+ if (!next.connection) setChoice('prometheus')
151
+ }}
152
+ onChanged={onChanged}
153
+ onDirtyChange={setOoDirty}
154
+ onBusyChange={setOoBusy}
155
+ />
156
+ ) : loadError ? (
157
+ <p role="alert" className="text-xs text-warning-text">
158
+ Couldn’t load OpenObserve settings: {loadError}{' '}
159
+ <button type="button" className="underline" onClick={() => setRetry((n) => n + 1)}>Retry</button>
160
+ </p>
161
+ ) : null}
162
+ </div>
163
+ </div>
164
+ )
165
+ }