@skyhook-io/radar-app 1.19.0 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +5 -5
- package/src/App.tsx +37 -9
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +353 -64
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/helmInventory.test.tsx +108 -0
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +42 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/curl/ServiceCurlAvailability.test.tsx +32 -0
- package/src/components/curl/ServiceCurlButton.tsx +2 -2
- package/src/components/diagnose/AIMarkdown.tsx +3 -0
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
- package/src/components/diagnose/DiagnoseContext.tsx +68 -2
- package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +26 -0
- package/src/components/diagnose/Home.tsx +20 -1
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
- package/src/components/diagnose/InvestigationView.tsx +94 -26
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.tsx +8 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.test.tsx +50 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +72 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +51 -16
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/listings.ts +34 -4
- package/src/components/diagnose/investigationEvidence/adapters/resource.ts +3 -2
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/helm/HelmDrawerFrame.tsx +101 -0
- package/src/components/helm/HelmDrawerRouting.test.tsx +86 -0
- package/src/components/helm/HelmReleaseDrawer.tsx +23 -86
- package/src/components/helm/HelmView.tsx +213 -71
- package/src/components/helm/ObservedHelmNotice.tsx +146 -0
- package/src/components/helm/ObservedHelmRelease.test.tsx +261 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +80 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +228 -0
- package/src/components/helm/OwnedResources.tsx +4 -2
- package/src/components/home/ClusterHealthCard.restricted.test.tsx +76 -0
- package/src/components/home/ClusterHealthCard.tsx +28 -5
- package/src/components/home/HelmSummary.tsx +23 -4
- package/src/components/home/HelmSummary.unread.test.ts +16 -0
- package/src/components/home/HomeAgentBlock.test.tsx +31 -3
- package/src/components/home/HomeAgentBlock.tsx +20 -4
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +81 -41
- package/src/components/home/MCPSetupDialog.test.tsx +126 -10
- package/src/components/home/MCPSetupDialog.tsx +33 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +67 -14
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +22 -1
- package/src/components/issues/uncheckedSources.ts +21 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/resources/renderers/ServiceRenderer.test.tsx +15 -2
- package/src/components/resources/renderers/ServiceRenderer.tsx +1 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +160 -0
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +128 -0
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
- package/src/components/whats-new/releaseNotes.ts +77 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +8 -4
- package/src/hooks/useElementSize.ts +30 -0
- package/src/hooks/useResolvedGitOpsOwner.test.ts +22 -0
- package/src/hooks/useResolvedGitOpsOwner.ts +6 -3
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +17 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -3,7 +3,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
3
3
|
import { KueueWorkloadRenderer } from './KueueWorkloadRenderer'
|
|
4
4
|
|
|
5
5
|
const mock = vi.hoisted(() => ({ query: {} as any }))
|
|
6
|
-
vi.mock('../../../api/client', () => ({ useKueueProvisioning: () => mock.query }))
|
|
6
|
+
vi.mock('../../../api/client', () => ({ useKueueProvisioning: () => mock.query, useKueuePendingPosition: () => ({ isPending: false, refetch: vi.fn() }) }))
|
|
7
|
+
// The admission-path reads have their own tests; here they stay unread.
|
|
8
|
+
vi.mock('../../kueue/useRelatedReads', () => ({
|
|
9
|
+
relatedReadKey: () => '',
|
|
10
|
+
useRelatedObjects: () => ({ byName: {}, all: { state: 'loading' }, completeness: 'unknown' }),
|
|
11
|
+
useRelatedReads: (refs: unknown[]) => refs.map(() => ({ state: 'loading' })),
|
|
12
|
+
}))
|
|
7
13
|
const data = { metadata: { name: 'work', namespace: 'ml', uid: 'new' }, status: { admissionChecks: [{ name: 'capacity', state: 'Rejected', message: 'Capacity unavailable' }] } }
|
|
8
14
|
const render = () => renderToStaticMarkup(<KueueWorkloadRenderer data={data} />)
|
|
9
15
|
|
|
@@ -1,26 +1,63 @@
|
|
|
1
|
+
import { KueuePendingPosition } from '../../kueue/KueuePendingPosition'
|
|
1
2
|
import { Boxes } from 'lucide-react'
|
|
2
3
|
import { KueueWorkloadRenderer as BaseRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/KueueWorkloadRenderer'
|
|
3
|
-
import { getProvisioningRequestStatus, getProvisioningRequestMessage } from '@skyhook-io/k8s-ui/components/resources/resource-utils-kueue'
|
|
4
|
-
import { Badge, ResourceLink, Section, type ResourceRef } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { getProvisioningRequestStatus, getProvisioningRequestMessage, isKueueWorkloadEligibleForPendingPosition } from '@skyhook-io/k8s-ui/components/resources/resource-utils-kueue'
|
|
5
|
+
import { Badge, ResourceLink, Section, type Relationships, type ResourceRef } from '@skyhook-io/k8s-ui'
|
|
6
|
+
import { needsNamespaceLabels } from '@skyhook-io/k8s-ui/components/kueue/eligibility'
|
|
7
|
+
import { KUEUE_GROUP } from '@skyhook-io/k8s-ui/components/kueue/constants'
|
|
5
8
|
import { useKueueProvisioning } from '../../../api/client'
|
|
9
|
+
import { relatedReadKey, useRelatedObjects, useRelatedReads } from '../../kueue/useRelatedReads'
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
// Reads the Workload's admission path as the viewer: its LocalQueue, the
|
|
12
|
+
// ClusterQueue that LocalQueue names, the ClusterQueue holding a reservation
|
|
13
|
+
// when that differs, and the namespace's labels only when a selector needs them.
|
|
14
|
+
function useAdmissionPathReads(data: any) {
|
|
15
|
+
const namespace: string = data.metadata?.namespace ?? ''
|
|
16
|
+
const queueName: string = data.spec?.queueName ?? ''
|
|
17
|
+
const reserved: string = data.status?.admission?.clusterQueue ?? ''
|
|
18
|
+
const flavorNames = [...new Set<string>((data.status?.admission?.podSetAssignments ?? []).flatMap((assignment: any) => Object.values(assignment?.flavors ?? {}).map(String)))]
|
|
19
|
+
const key = relatedReadKey(data, [queueName, reserved, ...flavorNames], ['QuotaReserved', 'Admitted', 'Finished'])
|
|
20
|
+
const localQueue = useRelatedObjects('localqueues', KUEUE_GROUP, namespace, [queueName], !!queueName && !!namespace, key).byName[queueName]
|
|
21
|
+
const configured: string = localQueue?.state === 'found' ? localQueue.object?.spec?.clusterQueue ?? '' : ''
|
|
22
|
+
const names = [...new Set([configured, reserved].filter(Boolean))]
|
|
23
|
+
const queues = useRelatedObjects('clusterqueues', KUEUE_GROUP, undefined, names, names.length > 0, key)
|
|
24
|
+
const flavors = useRelatedObjects('resourceflavors', KUEUE_GROUP, undefined, flavorNames, flavorNames.length > 0, key)
|
|
25
|
+
const configuredRead = configured ? queues.byName[configured] : undefined
|
|
26
|
+
// Eligibility is shown only while unreserved, so a reserved Workload skips the Namespace read.
|
|
27
|
+
const needsLabels = !reserved && configuredRead?.state === 'found' && needsNamespaceLabels(configuredRead.object?.spec?.namespaceSelector)
|
|
28
|
+
const namespaceState = JSON.stringify([key, configured, needsLabels, configuredRead?.state === 'found' ? configuredRead.object?.spec?.namespaceSelector : null])
|
|
29
|
+
const [namespaceRead] = useRelatedReads([{ kind: 'namespaces', name: namespace }], needsLabels && !!namespace, namespaceState)
|
|
30
|
+
return {
|
|
31
|
+
localQueue: queueName ? localQueue : undefined,
|
|
32
|
+
clusterQueues: queues.byName,
|
|
33
|
+
flavors: flavors.byName,
|
|
34
|
+
namespace: needsLabels ? namespaceRead : undefined,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Keyed by UID so moving the drawer to another Workload starts its reads (and their mount time) afresh.
|
|
39
|
+
export function KueueWorkloadRenderer(props: { data: any; onNavigate?: (ref: ResourceRef) => void; relationships?: Relationships }) {
|
|
40
|
+
return <KueueWorkloadReads key={props.data.metadata?.uid} {...props} />
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function KueueWorkloadReads({ data, onNavigate, relationships }: { data: any; onNavigate?: (ref: ResourceRef) => void; relationships?: Relationships }) {
|
|
44
|
+
const reads = useAdmissionPathReads(data)
|
|
8
45
|
const namespace = data.metadata?.namespace ?? ''
|
|
9
46
|
const uid = data.metadata?.uid
|
|
10
47
|
const hasChecks = (data.status?.admissionChecks?.length ?? 0) > 0
|
|
11
48
|
const requests = useKueueProvisioning(namespace, data.metadata?.name ?? '', uid, hasChecks)
|
|
12
49
|
const current = requests.data?.uid === uid ? requests.data : undefined
|
|
13
|
-
const provisioning = hasChecks ? <Section title="Provisioning Requests" icon={Boxes} defaultExpanded>
|
|
50
|
+
const provisioning = hasChecks ? <Section variant="card" title="Provisioning Requests" icon={Boxes} defaultExpanded>
|
|
14
51
|
{requests.error ? <p className="text-sm text-warning-text">Could not observe provisioning requests: {requests.error.message}</p>
|
|
15
52
|
: !current ? <p className="text-sm text-theme-text-tertiary">Looking for provisioning requests…</p>
|
|
16
53
|
: !current.installed ? <p className="text-sm text-theme-text-tertiary">The ProvisioningRequest API is not served by this cluster.</p>
|
|
17
54
|
: current.requests.length === 0 ? <p className="text-sm text-theme-text-tertiary">No retained provisioning requests found on this cluster. A request may not be needed or may have been cleaned up. Check results above retain the controller’s explanation; requests on a MultiKueue worker cluster are not included.</p>
|
|
18
|
-
: <div className="space-y-
|
|
55
|
+
: <div className="space-y-3">
|
|
19
56
|
<p className="text-xs text-theme-text-tertiary">Currently retained requests owned by this Workload, not a retry history. Requests may be removed after completion or eviction.</p>
|
|
20
57
|
{current.requests.map(request => {
|
|
21
58
|
const status = getProvisioningRequestStatus(request)
|
|
22
59
|
const message = getProvisioningRequestMessage(request)
|
|
23
|
-
return <div key={request.metadata.uid} className="
|
|
60
|
+
return <div key={request.metadata.uid} className="border-t border-theme-border pt-3">
|
|
24
61
|
<div className="flex flex-wrap items-center gap-2 break-all [&_button]:text-left">
|
|
25
62
|
<ResourceLink kind="provisioningrequests" group="autoscaling.x-k8s.io" namespace={namespace} name={request.metadata.name} onNavigate={onNavigate} />
|
|
26
63
|
<Badge colorClass={status.color} size="sm">{status.text}</Badge>
|
|
@@ -33,5 +70,8 @@ export function KueueWorkloadRenderer({ data, onNavigate }: { data: any; onNavig
|
|
|
33
70
|
{current.truncated && <p className="text-xs text-theme-text-tertiary">Showing {current.requests.length} of {current.total} retained requests, newest first.</p>}
|
|
34
71
|
</div>}
|
|
35
72
|
</Section> : undefined
|
|
36
|
-
|
|
73
|
+
const pendingPosition = isKueueWorkloadEligibleForPendingPosition(data)
|
|
74
|
+
? <KueuePendingPosition namespace={namespace} name={data.metadata?.name ?? ''} uid={uid} queueName={data.spec?.queueName} requeueAt={data.status?.requeueState?.requeueAt} />
|
|
75
|
+
: undefined
|
|
76
|
+
return <BaseRenderer pendingPosition={pendingPosition} data={data} onNavigate={onNavigate} provisioning={provisioning} relationships={relationships} reads={reads} />
|
|
37
77
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { beforeEach, expect, it, vi } from 'vitest'
|
|
3
|
+
import { OpenTelemetryCollectorRenderer } from './OpenTelemetryCollectorRenderer'
|
|
4
|
+
|
|
5
|
+
const read = vi.hoisted(() => vi.fn())
|
|
6
|
+
vi.mock('../../../api/client', () => ({ useResource: read }))
|
|
7
|
+
const root = { apiVersion: 'opentelemetry.io/v1beta1', kind: 'OpenTelemetryCollector', metadata: { name: 'collector', namespace: 'observe', uid: 'root' }, spec: { mode: 'deployment', config: {} } }
|
|
8
|
+
const reference = { group: 'apps', kind: 'Deployment', namespace: 'observe', name: 'runtime' }
|
|
9
|
+
const workload = { apiVersion: 'apps/v1', kind: 'Deployment', metadata: { namespace: 'observe', ownerReferences: [{ apiVersion: 'opentelemetry.io/v1beta1', kind: 'OpenTelemetryCollector', name: 'collector', uid: 'root', controller: true }] }, spec: { replicas: 0 }, status: {} }
|
|
10
|
+
|
|
11
|
+
beforeEach(() => read.mockReset())
|
|
12
|
+
|
|
13
|
+
it('separates current scaled-to-zero workload state from operator readiness', () => {
|
|
14
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: true } } } } : { data: workload })
|
|
15
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
16
|
+
expect(html).toContain('Current Workloads')
|
|
17
|
+
expect(html).toContain('Deployment / runtime')
|
|
18
|
+
expect(html).toContain('Scaled to 0')
|
|
19
|
+
expect(html).not.toContain('Not currently controlled')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('does not attribute a replaced workload to the current Collector', () => {
|
|
23
|
+
const replaced = structuredClone(workload)
|
|
24
|
+
replaced.metadata.ownerReferences[0].uid = 'old-root'
|
|
25
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: true } } } } : { data: replaced })
|
|
26
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
27
|
+
expect(html).toContain('Not currently controlled')
|
|
28
|
+
expect(html).not.toContain('Scaled to 0')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('keeps unknown evidence and sidecar emptiness neutral and explicit', () => {
|
|
32
|
+
read.mockReturnValue({})
|
|
33
|
+
expect(renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)).toContain('Owned-workload evidence is unavailable')
|
|
34
|
+
read.mockReturnValue({ relationships: { children: [], ownership: { children: { complete: true, narrowed: true } } } })
|
|
35
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={{ ...root, spec: { ...root.spec, mode: 'sidecar' } }} />)
|
|
36
|
+
expect(html).toContain('Sidecar mode runs inside annotated application Pods')
|
|
37
|
+
expect(html).toContain('Only resources you can read are shown')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('bounds automatic workload reads while leaving additional objects followable', () => {
|
|
41
|
+
const children = Array.from({ length: 30 }, (_, index) => ({ ...reference, name: `runtime-${index}` }))
|
|
42
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children, ownership: { children: { complete: true } } } } : { data: workload })
|
|
43
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
44
|
+
expect(read).toHaveBeenCalledTimes(4)
|
|
45
|
+
expect(html).toContain('This workload preview is incomplete')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('does not warn about workload coverage because unrelated CRD kinds are uncollected', () => {
|
|
49
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: false, notChecked: [{ group: 'example.io', kind: 'Widget', reason: 'radar_kind_not_collected' }] } } } } : { data: workload })
|
|
50
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
51
|
+
expect(html).toContain('Scaled to 0')
|
|
52
|
+
expect(html).not.toContain('preview is incomplete')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('shows an explicit partial workload preview when an apps inventory is unavailable', () => {
|
|
56
|
+
read.mockReturnValue({ relationships: { children: [], ownership: { children: { complete: false, notChecked: [{ group: 'apps', kind: 'DaemonSet', reason: 'kind_sync_pending' }] } } } })
|
|
57
|
+
expect(renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)).toContain('This workload preview is incomplete')
|
|
58
|
+
read.mockReturnValue({ isLoading: true })
|
|
59
|
+
expect(renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)).toContain('Reading owned workloads')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('pauses root and child reads while the resource view is inactive', () => {
|
|
63
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: true } } } } : { data: workload })
|
|
64
|
+
renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} active={false} />)
|
|
65
|
+
expect(read).toHaveBeenCalledTimes(2)
|
|
66
|
+
for (const call of read.mock.calls) expect(call[4]).toMatchObject({ enabled: false, refetchInterval: false })
|
|
67
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OpenTelemetryCollectorRenderer as BaseRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/OpenTelemetryRenderers'
|
|
2
|
+
import { getWorkloadStatus } from '@skyhook-io/k8s-ui/components/resources/resource-utils'
|
|
3
|
+
import { Badge } from '@skyhook-io/k8s-ui/components/ui/Badge'
|
|
4
|
+
import { healthToSeverity } from '@skyhook-io/k8s-ui/utils/badge-colors'
|
|
5
|
+
import { Property, PropertyList, ResourceLink, Section } from '@skyhook-io/k8s-ui/components/ui/drawer-components'
|
|
6
|
+
import { apiVersionToGroup } from '@skyhook-io/k8s-ui/utils/navigation'
|
|
7
|
+
import type { ResourceRef } from '@skyhook-io/k8s-ui'
|
|
8
|
+
import { useResource } from '../../../api/client'
|
|
9
|
+
|
|
10
|
+
function OwnedWorkload({ root, reference, onNavigate, active }: { root: any; reference: ResourceRef; onNavigate?: (ref: ResourceRef) => void; active: boolean }) {
|
|
11
|
+
const kind = `${reference.kind.toLowerCase()}s`
|
|
12
|
+
const query = useResource<any>(kind, reference.namespace, reference.name, reference.group, { enabled: active, refetchInterval: active ? 30000 : false })
|
|
13
|
+
const workload = query.data
|
|
14
|
+
const owned = root.metadata.uid && workload?.metadata?.namespace === root.metadata.namespace && workload.metadata.ownerReferences?.some((owner: any) => owner.controller === true && apiVersionToGroup(owner.apiVersion) === 'opentelemetry.io' && owner.kind === 'OpenTelemetryCollector' && owner.name === root.metadata.name && owner.uid === root.metadata.uid)
|
|
15
|
+
const status = owned ? getWorkloadStatus(workload, kind) : undefined
|
|
16
|
+
return <Property label={<ResourceLink {...reference} label={`${reference.kind} / ${reference.name}`} onNavigate={onNavigate} />} value={query.error ? 'Could not read workload; open it for details.' : !workload ? 'Reading current status…' : !owned ? 'Not currently controlled by this Collector; status not attributed.' : <Badge severity={healthToSeverity(status!.level)}>{status!.text}</Badge>} />
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function OpenTelemetryCollectorRenderer({ data, onNavigate, active = true }: { data: any; onNavigate?: (ref: ResourceRef) => void; active?: boolean }) {
|
|
20
|
+
const root = useResource<any>('opentelemetrycollectors', data.metadata.namespace, data.metadata.name, 'opentelemetry.io', { enabled: active, refetchInterval: active ? 30000 : false })
|
|
21
|
+
const coverage = root.relationships?.ownership
|
|
22
|
+
const children = (root.relationships?.children ?? []).filter(ref => ref.group === 'apps' && ['Deployment', 'StatefulSet', 'DaemonSet'].includes(ref.kind))
|
|
23
|
+
const runtimeGap = coverage?.children.notChecked?.some(gap => !gap.kind || gap.group === 'apps' && ['Deployment', 'StatefulSet', 'DaemonSet'].includes(gap.kind))
|
|
24
|
+
const partial = !coverage || coverage.unavailableReason || runtimeGap || coverage.children.truncated
|
|
25
|
+
return <BaseRenderer data={data} workloadEvidence={<Section title="Current Workloads" defaultExpanded>
|
|
26
|
+
<p className="mb-2 text-xs text-theme-text-tertiary">Workloads this Collector runs. Ready Pods do not confirm that telemetry is delivered.</p>
|
|
27
|
+
{root.isLoading ? <p className="text-sm text-theme-text-secondary">Reading owned workloads…</p> : root.error ? <p className="text-sm text-theme-text-secondary">Could not read owned workloads. Retry or inspect Related Resources.</p> : !coverage ? <p className="text-sm text-theme-text-secondary">Owned-workload evidence is unavailable. Related Resources may provide more detail.</p> : children.length ? <PropertyList>{children.slice(0, 3).map(ref => <OwnedWorkload key={`${ref.group}/${ref.kind}/${ref.namespace}/${ref.name}`} root={data} reference={ref} onNavigate={onNavigate} active={active} />)}</PropertyList> : <p className="text-sm text-theme-text-secondary">No standalone workloads observed{partial ? ' in the available evidence' : ''}. {data.spec?.mode === 'sidecar' ? 'Sidecar mode runs inside annotated application Pods.' : 'Inspect reconciliation and management state if you expected a runtime.'}</p>}
|
|
28
|
+
{(partial || children.length > 3) && <p className="mt-2 text-xs text-theme-text-tertiary">This workload preview is incomplete. Inspect Related Resources for coverage and additional owned objects.</p>}
|
|
29
|
+
{coverage?.children.narrowed && <p className="mt-2 text-xs text-theme-text-tertiary">Only resources you can read are shown.</p>}
|
|
30
|
+
</Section>} />
|
|
31
|
+
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
1
4
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
5
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
6
|
import { RayClusterRenderer } from './RayClusterRenderer'
|
|
4
|
-
const mock = vi.hoisted(() => ({ result: {} as any, calls: [] as any[] }))
|
|
5
|
-
vi.mock('../../../api/client', () => ({
|
|
7
|
+
const mock = vi.hoisted(() => ({ result: {} as any, calls: [] as any[], canViewLogs: true, opened: [] as any[], support: 'supported' as string, logsUnknown: false, capsFailed: false }))
|
|
8
|
+
vi.mock('../../../api/client', () => ({
|
|
9
|
+
ApiError: class ApiError extends Error { constructor(message: string, public status: number) { super(message) } },
|
|
10
|
+
useWorkloadPods: (...args: any[]) => { mock.calls.push(args); return mock.result },
|
|
11
|
+
useCapabilities: () => ({ data: mock.capsFailed ? undefined : { features: { rayClusterPods: true, podSidecarMarks: true } }, isError: mock.capsFailed }),
|
|
12
|
+
isStableClientError: (e: any) => [400, 403, 404, 409].includes(e?.status),
|
|
13
|
+
useRadarFeature: () => ({ support: mock.support, upgrade: mock.support === 'unsupported' ? { feature: 'RayCluster runtime Pods', minimumVersion: 'v1.15.0' } : null }),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('../../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canViewLogs: mock.canViewLogs, logsUnknown: mock.logsUnknown }) }))
|
|
16
|
+
vi.mock('../../dock', () => ({ useOpenLogs: () => (opts: any) => mock.opened.push(opts) }))
|
|
17
|
+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
|
6
18
|
const root = { apiVersion: 'ray.io/v1', kind: 'RayCluster', metadata: { name: 'cluster', namespace: 'ml', uid: 'current' } }
|
|
19
|
+
const worker = { name: 'cluster-cpu-worker-def', ready: true, containers: ['wait-gcs-ready', 'ray-worker'], containerStatuses: [{ name: 'ray-worker', ready: true, restartCount: 0 }, { name: 'wait-gcs-ready', init: true, ready: true, restartCount: 0 }] }
|
|
7
20
|
describe('RayCluster host evidence', () => {
|
|
8
|
-
beforeEach(() => { mock.result = {}; mock.calls = [] })
|
|
21
|
+
beforeEach(() => { mock.result = {}; mock.calls = []; mock.canViewLogs = true; mock.opened = []; mock.support = 'supported'; mock.logsUnknown = false; mock.capsFailed = false })
|
|
9
22
|
it('makes one bounded UID-bound query with polling', () => {
|
|
10
23
|
renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
11
24
|
expect(mock.calls).toEqual([['rayclusters', 'ml', 'cluster', { ownerUID: 'current', limit: 200, refetchInterval: 5000 }]])
|
|
@@ -15,4 +28,69 @@ describe('RayCluster host evidence', () => {
|
|
|
15
28
|
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
16
29
|
expect(html).toContain(message); expect(html).not.toContain('No directly owned Pods')
|
|
17
30
|
})
|
|
31
|
+
it('opens a verified Pod in the logs dock on its application container', () => {
|
|
32
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
33
|
+
const host = document.createElement('div')
|
|
34
|
+
const view = createRoot(host)
|
|
35
|
+
act(() => view.render(<RayClusterRenderer data={root} />))
|
|
36
|
+
act(() => host.querySelector<HTMLButtonElement>('[aria-label="Open logs for cluster-cpu-worker-def"]')!.click())
|
|
37
|
+
expect(mock.opened).toEqual([{ namespace: 'ml', podName: 'cluster-cpu-worker-def', containers: ['wait-gcs-ready', 'ray-worker'], containerName: 'ray-worker' }])
|
|
38
|
+
act(() => view.unmount())
|
|
39
|
+
})
|
|
40
|
+
it('opens a Pending worker in the init container it waits on', () => {
|
|
41
|
+
mock.result = { data: { pods: [{ ...worker, phase: 'Pending', containerStatuses: [{ name: 'wait-gcs-ready', init: true, ready: false, restartCount: 0 }, { name: 'ray-worker', ready: false, restartCount: 0 }] }], total: 1, truncated: false } }
|
|
42
|
+
const host = document.createElement('div')
|
|
43
|
+
const view = createRoot(host)
|
|
44
|
+
act(() => view.render(<RayClusterRenderer data={root} />))
|
|
45
|
+
act(() => host.querySelector<HTMLButtonElement>('[aria-label="Open logs for cluster-cpu-worker-def"]')!.click())
|
|
46
|
+
expect(mock.opened.at(-1).containerName).toBe('wait-gcs-ready')
|
|
47
|
+
act(() => view.unmount())
|
|
48
|
+
})
|
|
49
|
+
it('keeps the last Pod list, with its Logs buttons, through a passing refresh failure', async () => {
|
|
50
|
+
const { ApiError } = await import('../../../api/client') as any
|
|
51
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false }, error: new ApiError('Cluster connection changed; retry the Pod request', 503) }
|
|
52
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
53
|
+
expect(html).toContain('Open logs for cluster-cpu-worker-def')
|
|
54
|
+
expect(html).toContain('Pod list not refreshed: Cluster connection changed')
|
|
55
|
+
expect(html).not.toContain('Pod evidence unavailable')
|
|
56
|
+
})
|
|
57
|
+
it('offers no log links without permission to read Pod logs, and says so', () => {
|
|
58
|
+
mock.canViewLogs = false
|
|
59
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
60
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
61
|
+
expect(html).not.toContain('Open logs for'); expect(html).toContain('Pod logs need get on pods/log')
|
|
62
|
+
})
|
|
63
|
+
it('keeps log links while the namespace permission is unconfirmed', () => {
|
|
64
|
+
mock.canViewLogs = false
|
|
65
|
+
mock.logsUnknown = true
|
|
66
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
67
|
+
expect(renderToStaticMarkup(<RayClusterRenderer data={root} />)).toContain('Open logs for')
|
|
68
|
+
})
|
|
69
|
+
it('keeps log links when the global permission check has failed without an answer', () => {
|
|
70
|
+
mock.canViewLogs = false
|
|
71
|
+
mock.capsFailed = true
|
|
72
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
73
|
+
expect(renderToStaticMarkup(<RayClusterRenderer data={root} />)).toContain('Open logs for')
|
|
74
|
+
})
|
|
75
|
+
it('withholds cached Pod evidence after a definitive access denial', async () => {
|
|
76
|
+
const { ApiError } = await import('../../../api/client') as any
|
|
77
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false }, error: new ApiError('Reading RayCluster Pods requires get rayclusters and list pods', 403) }
|
|
78
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
79
|
+
expect(html).toContain('Pod evidence unavailable')
|
|
80
|
+
expect(html).not.toContain('Open logs for')
|
|
81
|
+
expect(html).not.toContain('Pod list not refreshed')
|
|
82
|
+
})
|
|
83
|
+
it('names an unsupporting Radar rather than echoing its 400 when support is unknown', async () => {
|
|
84
|
+
const { ApiError } = await import('../../../api/client') as any
|
|
85
|
+
mock.support = 'unknown'
|
|
86
|
+
mock.result = { error: new ApiError('only deployments, statefulsets, daemonsets, rollouts, jobs, and workflows are supported', 400) }
|
|
87
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
88
|
+
expect(html).toContain('Radar v1.15 and later'); expect(html).not.toContain('only deployments')
|
|
89
|
+
})
|
|
90
|
+
it('does not ask an older Radar for Pods it cannot list, and says which Radar can', () => {
|
|
91
|
+
mock.support = 'unsupported'
|
|
92
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
93
|
+
expect(mock.calls[0][2]).toBe('')
|
|
94
|
+
expect(html).toContain('RayCluster runtime Pods'); expect(html).toContain('v1.15')
|
|
95
|
+
})
|
|
18
96
|
})
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
2
|
import { RayClusterRenderer as BaseRenderer, type RayClusterPodSelection } from '@skyhook-io/k8s-ui/components/resources/renderers/RayClusterRenderer'
|
|
3
|
-
import type { ResourceRef } from '@skyhook-io/k8s-ui'
|
|
4
|
-
import { useWorkloadPods } from '../../../api/client'
|
|
3
|
+
import type { ResourceRef, WorkloadPodInfo } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { isStableClientError, useRadarFeature, useWorkloadPods } from '../../../api/client'
|
|
5
|
+
import { useOpenLogs } from '../../dock'
|
|
6
|
+
import { logsContainer } from '@skyhook-io/k8s-ui/components/resources/resource-utils-ray'
|
|
7
|
+
import { rayClusterPodsError, useLogsReadability, useSidecarsMarked } from '../../logs/rayClusterPods'
|
|
5
8
|
|
|
6
9
|
export function RayClusterRenderer(props: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
7
10
|
return <RayClusterEvidence key={props.data.metadata.uid} {...props} />
|
|
@@ -10,8 +13,20 @@ export function RayClusterRenderer(props: { data: any; onNavigate?: (ref: Resour
|
|
|
10
13
|
function RayClusterEvidence({ data, onNavigate }: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
11
14
|
const [requestedSelection, setSelection] = useState<RayClusterPodSelection>({})
|
|
12
15
|
const selection = requestedSelection.workerGroup != null && !(data.spec?.workerGroupSpecs ?? []).some((group: any) => group.groupName === requestedSelection.workerGroup) ? {} : requestedSelection
|
|
13
|
-
const
|
|
16
|
+
const { support, upgrade } = useRadarFeature('rayClusterPods')
|
|
17
|
+
const query = useWorkloadPods('rayclusters', data.metadata.namespace, data.metadata.uid && support !== 'unsupported' ? data.metadata.name : '', {
|
|
14
18
|
ownerUID: data.metadata.uid, ...selection, limit: 200, refetchInterval: 5000,
|
|
15
19
|
})
|
|
16
|
-
|
|
20
|
+
const logsReadable = useLogsReadability(data.metadata.namespace) !== 'denied'
|
|
21
|
+
// A refresh that fails for a passing reason keeps the last list, as the Logs tab does.
|
|
22
|
+
const kept = query.data && query.error && !isStableClientError(query.error)
|
|
23
|
+
const openLogs = useOpenLogs()
|
|
24
|
+
const sidecarsMarked = useSidecarsMarked()
|
|
25
|
+
const openPodLogs = (pod: WorkloadPodInfo) => openLogs({
|
|
26
|
+
namespace: data.metadata.namespace,
|
|
27
|
+
podName: pod.name,
|
|
28
|
+
containers: pod.containers,
|
|
29
|
+
containerName: logsContainer(pod, sidecarsMarked),
|
|
30
|
+
})
|
|
31
|
+
return <BaseRenderer data={data} onNavigate={onNavigate} selection={selection} onSelectPods={setSelection} podEvidence={query.data} podsLoading={query.isLoading} podsError={kept ? undefined : rayClusterPodsError(query.error, support)} podsNote={kept ? `Pod list not refreshed: ${rayClusterPodsError(query.error, support)}` : undefined} onOpenPodLogs={logsReadable ? openPodLogs : undefined} podLogsNote={logsReadable ? undefined : 'Pod logs need get on pods/log in this namespace.'} podsUpgrade={support === 'unsupported' ? upgrade : null} />
|
|
17
32
|
}
|
|
@@ -4,6 +4,7 @@ import { RadarFeatureUnsupportedError } from '../../../api/radarFeatures'
|
|
|
4
4
|
import { ServiceRenderer } from './ServiceRenderer'
|
|
5
5
|
|
|
6
6
|
const mock = vi.hoisted(() => ({
|
|
7
|
+
local: true,
|
|
7
8
|
serviceQuery: {} as any,
|
|
8
9
|
namespaceQuery: {} as any,
|
|
9
10
|
serviceReads: [] as any[],
|
|
@@ -13,9 +14,9 @@ vi.mock('../../../api/client', () => ({
|
|
|
13
14
|
useServiceEndpointSlices: (...args: any[]) => { mock.serviceReads.push(args); return mock.serviceQuery },
|
|
14
15
|
useResources: (...args: any[]) => { mock.namespaceReads.push(args); return mock.namespaceQuery },
|
|
15
16
|
}))
|
|
16
|
-
vi.mock('../../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canPortForward: false }), useIsLocalDeployment: () =>
|
|
17
|
+
vi.mock('../../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canPortForward: false }), useIsLocalDeployment: () => mock.local }))
|
|
17
18
|
vi.mock('../../portforward/PortForwardButton', () => ({ PortForwardInlineButton: () => null }))
|
|
18
|
-
vi.mock('../../curl/ServiceCurlButton', () => ({ CurlButton: () =>
|
|
19
|
+
vi.mock('../../curl/ServiceCurlButton', () => ({ CurlButton: () => <button>Service curl</button>, CurlPanel: () => null, isHttpishPort: () => true, defaultScheme: () => '', defaultPathForPort: () => '' }))
|
|
19
20
|
|
|
20
21
|
const service = { apiVersion: 'v1', kind: 'Service', metadata: { name: 'web', namespace: 'team' }, spec: { selector: { app: 'web' } } }
|
|
21
22
|
const selectorless = { ...service, spec: {} }
|
|
@@ -24,6 +25,7 @@ const render = (data: any = service) => renderToStaticMarkup(<ServiceRenderer da
|
|
|
24
25
|
const unsupported = () => new RadarFeatureUnsupportedError('serviceEndpointSlices', { currentVersion: 'v1.7.0' })
|
|
25
26
|
|
|
26
27
|
beforeEach(() => {
|
|
28
|
+
mock.local = true
|
|
27
29
|
mock.serviceQuery = {}
|
|
28
30
|
mock.namespaceQuery = {}
|
|
29
31
|
mock.serviceReads = []
|
|
@@ -79,3 +81,14 @@ it('keeps selector Services free of slice lookups on an older Radar', () => {
|
|
|
79
81
|
expect(mock.namespaceReads[0][3].enabled).toBe(false)
|
|
80
82
|
expect(html).not.toContain('EndpointSlices')
|
|
81
83
|
})
|
|
84
|
+
|
|
85
|
+
it('preserves in-cluster UI curl for all Service types', () => {
|
|
86
|
+
mock.local = false
|
|
87
|
+
const ports = [{ port: 80, name: 'http', protocol: 'TCP' }]
|
|
88
|
+
expect(render({ ...service, spec: { ...service.spec, ports } })).toContain('Service curl')
|
|
89
|
+
expect(render({ ...service, spec: { ports } })).toContain('Service curl')
|
|
90
|
+
expect(render({ ...service, spec: { type: 'ExternalName', externalName: 'example.org', ports } })).toContain('Service curl')
|
|
91
|
+
expect(render({ ...service, spec: { ...service.spec, clusterIP: 'None', ports } })).toContain('Service curl')
|
|
92
|
+
mock.local = true
|
|
93
|
+
expect(render({ ...service, spec: { ...service.spec, ports } })).not.toContain('Service curl')
|
|
94
|
+
})
|
|
@@ -26,7 +26,6 @@ export function ServiceRenderer({ data, onCopy, copied, onNavigate }: ServiceRen
|
|
|
26
26
|
const showPortForward = canPortForward || !isLocal
|
|
27
27
|
// Curl dials the Service directly from in-cluster, so it's only available when
|
|
28
28
|
// Radar runs in-cluster/Cloud — locally you'd port-forward instead.
|
|
29
|
-
const showCurl = !isLocal
|
|
30
29
|
// Which port's inline curl panel is open (one at a time). `closing` keeps the
|
|
31
30
|
// panel mounted through its collapse animation before we drop it.
|
|
32
31
|
const [curl, setCurl] = useState<{ port: number; closing: boolean } | null>(null)
|
|
@@ -38,6 +37,7 @@ export function ServiceRenderer({ data, onCopy, copied, onNavigate }: ServiceRen
|
|
|
38
37
|
}, [])
|
|
39
38
|
const spec = data.spec || {}
|
|
40
39
|
const hasNoSelector = !spec.selector || Object.keys(spec.selector).length === 0
|
|
40
|
+
const showCurl = !isLocal
|
|
41
41
|
const canListEndpointSlices = Boolean(namespace && serviceName && spec.type !== 'ExternalName')
|
|
42
42
|
const serviceSlices = useServiceEndpointSlices(namespace, serviceName, canListEndpointSlices)
|
|
43
43
|
// A Radar without the per-Service endpoint keeps its earlier behavior: only
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import {
|
|
4
|
+
ValidatingAdmissionPolicyBindingRenderer,
|
|
5
|
+
ValidatingAdmissionPolicyRenderer,
|
|
6
|
+
} from './ValidatingAdmissionPolicyRenderer'
|
|
7
|
+
|
|
8
|
+
const mock = vi.hoisted(() => ({
|
|
9
|
+
query: {} as any,
|
|
10
|
+
reads: [] as any[],
|
|
11
|
+
policyQuery: {} as any,
|
|
12
|
+
policyReads: [] as any[],
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
vi.mock('../../../api/client', () => ({
|
|
16
|
+
useResources: (...args: any[]) => {
|
|
17
|
+
mock.reads.push(args)
|
|
18
|
+
return mock.query
|
|
19
|
+
},
|
|
20
|
+
useResourceWithRelationships: (...args: any[]) => {
|
|
21
|
+
mock.policyReads.push(args)
|
|
22
|
+
return mock.policyQuery
|
|
23
|
+
},
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
const policy = {
|
|
27
|
+
apiVersion: 'admissionregistration.k8s.io/v1',
|
|
28
|
+
kind: 'ValidatingAdmissionPolicy',
|
|
29
|
+
metadata: { name: 'require-owner', generation: 1 },
|
|
30
|
+
spec: { validations: [{ expression: 'true' }] },
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const binding = (name: string, policyName: string) => ({
|
|
34
|
+
apiVersion: 'admissionregistration.k8s.io/v1',
|
|
35
|
+
kind: 'ValidatingAdmissionPolicyBinding',
|
|
36
|
+
metadata: { name },
|
|
37
|
+
spec: { policyName, validationActions: ['Deny'] },
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const render = () => renderToStaticMarkup(<ValidatingAdmissionPolicyRenderer data={policy} onNavigate={() => {}} />)
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
mock.query = {}
|
|
44
|
+
mock.reads = []
|
|
45
|
+
mock.policyQuery = {}
|
|
46
|
+
mock.policyReads = []
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe('ValidatingAdmissionPolicy reverse binding lookup', () => {
|
|
50
|
+
it('lists only readable bindings that name this policy', () => {
|
|
51
|
+
mock.query = { data: [binding('owner-prod', 'require-owner'), binding('image-prod', 'require-images')], coverage: { status: 'complete' }, isLoading: false }
|
|
52
|
+
const html = render()
|
|
53
|
+
expect(mock.reads).toEqual([[
|
|
54
|
+
'validatingadmissionpolicybindings',
|
|
55
|
+
undefined,
|
|
56
|
+
'admissionregistration.k8s.io',
|
|
57
|
+
{ enabled: true, refetchInterval: 30000 },
|
|
58
|
+
]])
|
|
59
|
+
expect(html).toContain('Bindings (1)')
|
|
60
|
+
expect(html).toContain('owner-prod')
|
|
61
|
+
expect(html).not.toContain('image-prod')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('reports no binding only when the list response establishes complete coverage', () => {
|
|
65
|
+
mock.query = { data: [], coverage: { status: 'complete' }, isLoading: false }
|
|
66
|
+
expect(render()).toContain('No readable bindings select this policy')
|
|
67
|
+
expect(render()).toContain('this policy has no effect')
|
|
68
|
+
|
|
69
|
+
mock.query = { data: [], coverage: { status: 'unknown' }, isLoading: false }
|
|
70
|
+
const unknown = render()
|
|
71
|
+
expect(unknown).toContain('Binding availability could not be established')
|
|
72
|
+
expect(unknown).not.toContain('this policy has no effect')
|
|
73
|
+
expect(unknown).not.toContain('Bindings (0)')
|
|
74
|
+
|
|
75
|
+
mock.query = { isLoading: true }
|
|
76
|
+
const loading = render()
|
|
77
|
+
expect(loading).toContain('Looking for readable bindings')
|
|
78
|
+
expect(loading).not.toContain('No readable bindings')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('distinguishes forbidden from other list failures and never reports either as no bindings', () => {
|
|
82
|
+
mock.query = { error: { status: 403, message: 'Forbidden' }, isLoading: false }
|
|
83
|
+
const denied = render()
|
|
84
|
+
expect(denied).toContain('don’t have permission')
|
|
85
|
+
expect(denied).not.toContain('No readable bindings')
|
|
86
|
+
expect(denied).not.toContain('Bindings (0)')
|
|
87
|
+
|
|
88
|
+
mock.query = { error: new Error('binding list unavailable'), isLoading: false }
|
|
89
|
+
const failed = render()
|
|
90
|
+
expect(failed).toContain('Could not check')
|
|
91
|
+
expect(failed).toContain('binding list unavailable')
|
|
92
|
+
expect(failed).not.toContain('No readable bindings')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('marks a non-empty partial binding list as incomplete', () => {
|
|
96
|
+
mock.query = { data: [binding('owner-prod', 'require-owner')], coverage: { status: 'partial' }, isLoading: false }
|
|
97
|
+
const partial = render()
|
|
98
|
+
expect(partial).toContain('Bindings (1+)')
|
|
99
|
+
expect(partial).toContain('This list may be incomplete')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('stops reporting an exact count when a refresh fails after a complete list', () => {
|
|
103
|
+
mock.query = {
|
|
104
|
+
data: [binding('owner-prod', 'require-owner')],
|
|
105
|
+
coverage: { status: 'complete' },
|
|
106
|
+
error: new Error('binding list unavailable'),
|
|
107
|
+
isLoading: false,
|
|
108
|
+
}
|
|
109
|
+
const stale = render()
|
|
110
|
+
expect(stale).toContain('Bindings (1+)')
|
|
111
|
+
expect(stale).not.toContain('Bindings (1)')
|
|
112
|
+
expect(stale).toContain('This may be incomplete')
|
|
113
|
+
expect(stale).toContain('owner-prod')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('keeps the binding wrapper declarative and free of parameter discovery reads', () => {
|
|
117
|
+
mock.policyQuery = { data: { resource: policy } }
|
|
118
|
+
const html = renderToStaticMarkup(<ValidatingAdmissionPolicyBindingRenderer data={{
|
|
119
|
+
...binding('owner-prod', 'require-owner'),
|
|
120
|
+
spec: {
|
|
121
|
+
policyName: 'require-owner',
|
|
122
|
+
validationActions: ['Warn'],
|
|
123
|
+
paramRef: { selector: { matchLabels: { tier: 'strict' } }, parameterNotFoundAction: 'Allow' },
|
|
124
|
+
},
|
|
125
|
+
}} onNavigate={() => {}} />)
|
|
126
|
+
expect(html).toContain('tier')
|
|
127
|
+
expect(html).toContain('strict')
|
|
128
|
+
expect(mock.reads).toEqual([])
|
|
129
|
+
expect(mock.policyReads).toEqual([[
|
|
130
|
+
'validatingadmissionpolicies',
|
|
131
|
+
'',
|
|
132
|
+
'require-owner',
|
|
133
|
+
'admissionregistration.k8s.io',
|
|
134
|
+
]])
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('keeps policy loading, missing, denied, and failed reference checks distinct', () => {
|
|
138
|
+
const renderBinding = () => renderToStaticMarkup(<ValidatingAdmissionPolicyBindingRenderer
|
|
139
|
+
data={binding('owner-prod', 'require-owner')}
|
|
140
|
+
onNavigate={() => {}}
|
|
141
|
+
/>)
|
|
142
|
+
|
|
143
|
+
mock.policyQuery = { isLoading: true }
|
|
144
|
+
expect(renderBinding()).toContain('Checking policy availability')
|
|
145
|
+
|
|
146
|
+
mock.policyQuery = { error: { status: 404, message: 'Not Found' } }
|
|
147
|
+
expect(renderBinding()).toContain('Referenced policy was not found')
|
|
148
|
+
|
|
149
|
+
mock.policyQuery = { error: { status: 403, message: 'Forbidden' } }
|
|
150
|
+
expect(renderBinding()).toContain('Not permitted to check policy availability')
|
|
151
|
+
|
|
152
|
+
mock.policyQuery = { error: new Error('policy read failed') }
|
|
153
|
+
expect(renderBinding()).toContain('Could not check policy availability')
|
|
154
|
+
|
|
155
|
+
mock.policyQuery = { data: { resource: policy } }
|
|
156
|
+
const present = renderBinding()
|
|
157
|
+
expect(present).not.toContain('availability')
|
|
158
|
+
expect(present).toContain('>require-owner</button>')
|
|
159
|
+
})
|
|
160
|
+
})
|