@skyhook-io/radar-app 1.18.2 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -6
- 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 +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +97 -3
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +41 -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/diagnose/AIMarkdown.tsx +4 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
- package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
- package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
- package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
- package/src/components/diagnose/AnalysisStory.tsx +17 -4
- package/src/components/diagnose/AssessmentCard.tsx +39 -8
- 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.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +272 -10
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +208 -5
- package/src/components/diagnose/Home.tsx +187 -36
- package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
- package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
- package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
- package/src/components/diagnose/InvestigationView.tsx +249 -54
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +495 -0
- package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
- package/src/components/diagnose/QuestionFocus.tsx +123 -0
- package/src/components/diagnose/ResourcePicker.tsx +206 -0
- package/src/components/diagnose/StoryExcerpt.tsx +12 -3
- package/src/components/diagnose/assessmentCopy.ts +5 -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.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
- package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
- package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
- package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
- package/src/components/diagnose/investigationEvidence/index.ts +1 -1
- package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -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 +7 -0
- package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
- package/src/components/diagnose/investigationFocus.test.ts +271 -0
- package/src/components/diagnose/investigationFocus.ts +132 -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/parts.test.tsx +20 -0
- package/src/components/diagnose/questionSuggestions.test.ts +111 -0
- package/src/components/diagnose/questionSuggestions.ts +150 -0
- package/src/components/diagnose/storyParts.test.tsx +13 -0
- package/src/components/diagnose/target.test.ts +143 -2
- package/src/components/diagnose/target.ts +109 -7
- package/src/components/diagnose/testdata/story-runs.json +474 -0
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/diagnose/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- 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/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +141 -0
- package/src/components/home/HomeAgentBlock.tsx +103 -0
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +86 -47
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- 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 +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -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/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
- package/src/components/ui/Omnibar.tsx +47 -3
- package/src/components/ui/RadarOmnibar.test.tsx +1 -0
- package/src/components/ui/RadarOmnibar.tsx +11 -0
- 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 +18 -4
- package/src/components/whats-new/releaseNotes.ts +136 -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 +6 -4
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
- package/src/hooks/useElementSize.ts +30 -0
- 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 +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
package/src/api/client.ts
CHANGED
|
@@ -2,9 +2,15 @@ import { createListRefetchInterval, normalizeResourceList, type ResourceListBody
|
|
|
2
2
|
import type { CascadeDetail } from '@skyhook-io/k8s-ui/components/ui/ForceDeleteConfirmDialog'
|
|
3
3
|
import { canonicalResourceGroup } from '@skyhook-io/k8s-ui/utils/api-resources'
|
|
4
4
|
import { pluralize } from '@skyhook-io/k8s-ui/utils/pluralize'
|
|
5
|
+
import type { ReadGap } from '@skyhook-io/k8s-ui/types/read-coverage'
|
|
6
|
+
import type { WorkloadHistoryCoverage } from '@skyhook-io/k8s-ui/utils/workload-history-notes'
|
|
5
7
|
import { knownKindForPluralWithGroup, pluralToKind } from '@skyhook-io/k8s-ui/utils/navigation'
|
|
6
8
|
import { useEffect, useRef, useCallback, useMemo } from 'react'
|
|
7
|
-
import
|
|
9
|
+
import { argoSyncOptionsForRequest } from '@skyhook-io/k8s-ui'
|
|
10
|
+
import { useClusterConnected } from '../context/clusterConnected'
|
|
11
|
+
import type { KueueAdmissionResponse, KueuePositionResponse } from '@skyhook-io/k8s-ui/types/scheduling'
|
|
12
|
+
import type { KueueQueueMembership, KueueQueueWorkloadsResponse } from '@skyhook-io/k8s-ui/types/kueue-queues'
|
|
13
|
+
import { kueueQueueRetryable } from '@skyhook-io/k8s-ui/utils/kueue-queue-workloads'
|
|
8
14
|
import { canonicalReadCode, readActionFor } from '@skyhook-io/k8s-ui/utils/read-actions'
|
|
9
15
|
import type { SearchCoverage } from '@skyhook-io/k8s-ui/types/read-coverage'
|
|
10
16
|
import type { GitOpsWriteEvidence } from '@skyhook-io/k8s-ui/utils/gitops-write-guard'
|
|
@@ -26,7 +32,7 @@ import type {
|
|
|
26
32
|
YamlDocumentIdentity,
|
|
27
33
|
YamlSchemaLoadResult,
|
|
28
34
|
} from '@skyhook-io/k8s-ui'
|
|
29
|
-
import { useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
35
|
+
import { focusManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
30
36
|
import { showApiError, showApiSuccess, showApiNotice } from '../components/ui/Toast'
|
|
31
37
|
import { useIsAuthEnabled, useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
|
|
32
38
|
import type {
|
|
@@ -67,12 +73,15 @@ import type {
|
|
|
67
73
|
PodEnvironmentRevealResponse,
|
|
68
74
|
} from '../types'
|
|
69
75
|
import type { GitOpsOperationResponse } from '../types/gitops'
|
|
70
|
-
import { apiUrl, getApiBase, getAuthHeaders, getCredentialsMode, getBasename, routePath, stripBasename } from './config'
|
|
76
|
+
import { apiUrl, automaticRequestHeaders, getApiBase, getAuthHeaders, getCredentialsMode, getBasename, routePath, stripBasename } from './config'
|
|
71
77
|
import { httpStatusMessage, markShownInline, readErrorBody, readErrorResponse } from './httpErrors'
|
|
72
78
|
import {
|
|
73
79
|
RadarFeatureUnsupportedError,
|
|
74
80
|
guardRadarFeature,
|
|
81
|
+
radarControlBlocked,
|
|
82
|
+
radarControlBlockedReason,
|
|
75
83
|
radarFeatureSupport,
|
|
84
|
+
radarUpgradeRequirement,
|
|
76
85
|
shouldRetryRadarQuery,
|
|
77
86
|
type RadarFeature,
|
|
78
87
|
} from './radarFeatures'
|
|
@@ -233,6 +242,18 @@ export function isForbiddenError(error: unknown): boolean {
|
|
|
233
242
|
return error instanceof ApiError && error.status === 403;
|
|
234
243
|
}
|
|
235
244
|
|
|
245
|
+
// Answers that won't change on the next poll: a rejected request, a denial, a
|
|
246
|
+
// missing or recreated root. A 401 (an expired session) can recover.
|
|
247
|
+
export function isStableClientError(error: unknown): boolean {
|
|
248
|
+
return error instanceof ApiError && [400, 403, 404, 409].includes(error.status)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// An owner-UID query stops polling on an answer that will repeat; a recreated
|
|
252
|
+
// root recovers when its new UID changes the query key.
|
|
253
|
+
export function workloadPodsRefetchInterval(error: unknown, options?: { ownerUID?: string; refetchInterval?: number | false }): number | false {
|
|
254
|
+
return options?.ownerUID && isStableClientError(error) ? false : options?.refetchInterval ?? false
|
|
255
|
+
}
|
|
256
|
+
|
|
236
257
|
export function isNotFoundError(error: unknown): boolean {
|
|
237
258
|
return error instanceof ApiError && error.status === 404;
|
|
238
259
|
}
|
|
@@ -492,17 +513,8 @@ export interface DashboardChange {
|
|
|
492
513
|
timestamp: string;
|
|
493
514
|
}
|
|
494
515
|
|
|
495
|
-
export interface DashboardTopFlow {
|
|
496
|
-
src: string;
|
|
497
|
-
dst: string;
|
|
498
|
-
requestsPerSec?: number;
|
|
499
|
-
connections: number;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
516
|
export interface DashboardTrafficSummary {
|
|
503
517
|
source: string;
|
|
504
|
-
flowCount: number;
|
|
505
|
-
topFlows: DashboardTopFlow[];
|
|
506
518
|
}
|
|
507
519
|
|
|
508
520
|
export interface DashboardHelmRelease {
|
|
@@ -710,9 +722,12 @@ export function useDashboard(
|
|
|
710
722
|
export function useAudit(namespaces: string[] = []) {
|
|
711
723
|
const params =
|
|
712
724
|
namespaces.length > 0 ? `?namespaces=${namespaces.join(",")}` : "";
|
|
725
|
+
// Mounted app-wide, so without this it keeps polling a cluster that is down.
|
|
726
|
+
const connected = useClusterConnected();
|
|
713
727
|
return useQuery<AuditResponse>({
|
|
714
728
|
queryKey: ["audit", namespaces],
|
|
715
729
|
queryFn: () => fetchJSON(`/audit${params}`),
|
|
730
|
+
enabled: connected,
|
|
716
731
|
staleTime: 30000,
|
|
717
732
|
refetchInterval: AUDIT_REFRESH_INTERVAL_MS,
|
|
718
733
|
placeholderData: (prev) => prev,
|
|
@@ -828,12 +843,17 @@ export function useResourceAudit(
|
|
|
828
843
|
// the "Operational Issues" section in the resource detail. Cluster-scoped
|
|
829
844
|
// resources pass "_" for namespace; namespaced ones also scope the scan via
|
|
830
845
|
// ?namespaces= for a cheap, bounded Compose.
|
|
846
|
+
// rootObservation is an opaque root UID/resourceVersion token: changes schedule
|
|
847
|
+
// a refresh at most every 10s, without creating a query key per version. Omit it
|
|
848
|
+
// to retain the 60s visible-tab fallback and stale-view/focus refreshes.
|
|
849
|
+
// Disabled hooks and cluster-scoped subjects do not poll for namespaced Issues.
|
|
831
850
|
export function useResourceIssues(
|
|
832
851
|
kind: string,
|
|
833
852
|
group: string | undefined,
|
|
834
853
|
namespace: string,
|
|
835
854
|
name: string,
|
|
836
855
|
enabled = true,
|
|
856
|
+
rootObservation?: string,
|
|
837
857
|
) {
|
|
838
858
|
const clusterScoped = !namespace;
|
|
839
859
|
const pathNs = clusterScoped ? "_" : encodeURIComponent(namespace);
|
|
@@ -843,16 +863,52 @@ export function useResourceIssues(
|
|
|
843
863
|
const qs = params.toString();
|
|
844
864
|
// An older Radar without the endpoint settles as unsupported, so the
|
|
845
865
|
// renderers fall back to their own status-derived problem banners.
|
|
846
|
-
const { guard, gatedKey } = useRadarFeature("resourceIssues");
|
|
847
|
-
|
|
848
|
-
|
|
866
|
+
const { guard, gatedKey, support } = useRadarFeature("resourceIssues");
|
|
867
|
+
const queryClient = useQueryClient();
|
|
868
|
+
const queryKey = useMemo(() => ["issues", "resource", kind, group ?? "", namespace, name, ...gatedKey],
|
|
869
|
+
[kind, group, namespace, name, gatedKey]);
|
|
870
|
+
const query = useQuery<Issue[]>({
|
|
871
|
+
queryKey,
|
|
849
872
|
queryFn: () => guard(() => fetchJSON<Issue[]>(`${path}${qs ? `?${qs}` : ""}`)),
|
|
850
873
|
retry: shouldRetryRadarQuery,
|
|
851
|
-
// No refetchInterval: a drawer doesn't need to poll; staleTime keeps it fresh
|
|
852
|
-
// on reopen without re-running an uncapped Compose every 30s.
|
|
853
874
|
staleTime: 30000,
|
|
875
|
+
// Time-based detections can change without a resource watch update.
|
|
876
|
+
refetchInterval: (q) => clusterScoped || q.state.error instanceof RadarFeatureUnsupportedError ? false : 60000,
|
|
877
|
+
refetchIntervalInBackground: false,
|
|
878
|
+
refetchOnWindowFocus: (q) => !(q.state.error instanceof RadarFeatureUnsupportedError),
|
|
854
879
|
enabled: enabled && !!kind && !!name,
|
|
855
880
|
});
|
|
881
|
+
const { error, refetch } = query;
|
|
882
|
+
useEffect(() => {
|
|
883
|
+
if (enabled && kind && name && support === "supported" && error instanceof RadarFeatureUnsupportedError) void refetch();
|
|
884
|
+
}, [enabled, kind, name, support, error, refetch]);
|
|
885
|
+
const identity = JSON.stringify(queryKey);
|
|
886
|
+
const previous = useRef<{ identity: string; rootObservation: string | undefined; refreshedAt: number } | null>(null);
|
|
887
|
+
useEffect(() => {
|
|
888
|
+
const prior = previous.current;
|
|
889
|
+
if (prior?.identity !== identity) {
|
|
890
|
+
previous.current = { identity, rootObservation, refreshedAt: Date.now() };
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (prior.rootObservation === undefined) {
|
|
894
|
+
prior.rootObservation = rootObservation;
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (clusterScoped || !enabled || !kind || !name || query.error instanceof RadarFeatureUnsupportedError ||
|
|
898
|
+
rootObservation === undefined || prior.rootObservation === rootObservation) return;
|
|
899
|
+
|
|
900
|
+
// Keep the rootObservation out of the query key, and bound Compose requests even
|
|
901
|
+
// when a busy workload's resource version changes continuously.
|
|
902
|
+
const delay = Math.max(0, 10000 - (Date.now() - Math.max(prior.refreshedAt, query.dataUpdatedAt)));
|
|
903
|
+
const timer = window.setTimeout(() => {
|
|
904
|
+
prior.rootObservation = rootObservation;
|
|
905
|
+
prior.refreshedAt = Date.now();
|
|
906
|
+
void queryClient.invalidateQueries({ queryKey, exact: true,
|
|
907
|
+
refetchType: focusManager.isFocused() ? 'active' : 'none' });
|
|
908
|
+
}, delay);
|
|
909
|
+
return () => window.clearTimeout(timer);
|
|
910
|
+
}, [identity, rootObservation, enabled, kind, name, clusterScoped, queryClient, query.error, query.dataUpdatedAt, queryKey]);
|
|
911
|
+
return query;
|
|
856
912
|
}
|
|
857
913
|
|
|
858
914
|
// The Issues page narrowed to one subject: the same per-resource lookup with
|
|
@@ -875,6 +931,8 @@ export interface SubjectIssuesResponse {
|
|
|
875
931
|
coverage: "ok" | "syncing" | "notWatched" | "unknownKind";
|
|
876
932
|
withheld?: { issues: number };
|
|
877
933
|
visibility?: { state?: string; impact?: string };
|
|
934
|
+
/** Checks about this resource Radar couldn't make for the caller. */
|
|
935
|
+
unchecked_sources?: UncheckedSource[];
|
|
878
936
|
}
|
|
879
937
|
|
|
880
938
|
export function useSubjectIssues(
|
|
@@ -1086,6 +1144,8 @@ export type CostUnavailableReason =
|
|
|
1086
1144
|
| "access_denied"
|
|
1087
1145
|
| "not_found"
|
|
1088
1146
|
| "source_unavailable"
|
|
1147
|
+
| "metrics_port_forward_disabled"
|
|
1148
|
+
| "kubecost_port_forward_disabled"
|
|
1089
1149
|
| "authentication_error"
|
|
1090
1150
|
| "configuration_mismatch"
|
|
1091
1151
|
| "deployment_configuration_error"
|
|
@@ -1785,7 +1845,8 @@ export function useWhatsNewState(enabled: boolean) {
|
|
|
1785
1845
|
export async function markWhatsNewSeen(version: string): Promise<void> {
|
|
1786
1846
|
const response = await apiFetch(`${getApiBase()}/whats-new/seen`, {
|
|
1787
1847
|
method: "POST",
|
|
1788
|
-
|
|
1848
|
+
// Bookkeeping that follows the dialog, not a separate action.
|
|
1849
|
+
headers: { "Content-Type": "application/json", ...automaticRequestHeaders() },
|
|
1789
1850
|
body: JSON.stringify({ version }),
|
|
1790
1851
|
});
|
|
1791
1852
|
if (!response.ok) throw new ApiError(`HTTP ${response.status}`, response.status);
|
|
@@ -1886,9 +1947,14 @@ export function useVersionCheck() {
|
|
|
1886
1947
|
* (a host-supplied version before /capabilities answers) can lift later, and
|
|
1887
1948
|
* the key change is what makes the query fetch for real; ungated keys are
|
|
1888
1949
|
* unchanged.
|
|
1950
|
+
*
|
|
1951
|
+
* `upgrade` is set when a control the feature backs must render disabled with
|
|
1952
|
+
* RadarUpgradeNote's copy: the Radar is known to be too old, or failed to
|
|
1953
|
+
* answer /api/capabilities (see radarControlBlocked). Controls requiring
|
|
1954
|
+
* affirmative support instead get `blockedReason` while checking or unavailable.
|
|
1889
1955
|
*/
|
|
1890
1956
|
export function useRadarFeature(feature: RadarFeature) {
|
|
1891
|
-
const { data: capabilities } = useCapabilities()
|
|
1957
|
+
const { data: capabilities, isError: capabilitiesFailed } = useCapabilities()
|
|
1892
1958
|
const { data: versionInfo } = useQuery<VersionInfo>(versionCheckQueryOptions(getApiBase()))
|
|
1893
1959
|
const { radarVersion } = useRadarUpgradeHost()
|
|
1894
1960
|
const currentVersion = versionInfo?.currentVersion || radarVersion
|
|
@@ -1900,8 +1966,17 @@ export function useRadarFeature(feature: RadarFeature) {
|
|
|
1900
1966
|
[feature, support, currentVersion, latestVersion],
|
|
1901
1967
|
)
|
|
1902
1968
|
const gatedKey = useMemo(() => (support === 'unsupported' ? ['radar-feature-unsupported'] : []), [support])
|
|
1969
|
+
const blockedReason = radarControlBlockedReason(feature, support, capabilitiesFailed)
|
|
1903
1970
|
|
|
1904
|
-
return {
|
|
1971
|
+
return {
|
|
1972
|
+
support,
|
|
1973
|
+
blockedReason,
|
|
1974
|
+
upgrade: !blockedReason && radarControlBlocked(support, capabilitiesFailed)
|
|
1975
|
+
? radarUpgradeRequirement(feature, { currentVersion, latestVersion })
|
|
1976
|
+
: null,
|
|
1977
|
+
gatedKey,
|
|
1978
|
+
guard,
|
|
1979
|
+
}
|
|
1905
1980
|
}
|
|
1906
1981
|
|
|
1907
1982
|
// ============================================================================
|
|
@@ -2079,11 +2154,14 @@ export function useRuntimeStats(enabled: boolean = true) {
|
|
|
2079
2154
|
|
|
2080
2155
|
// Capabilities (RBAC-based feature flags)
|
|
2081
2156
|
export function useCapabilities() {
|
|
2157
|
+
const connected = useClusterConnected();
|
|
2082
2158
|
return useQuery<Capabilities>({
|
|
2083
2159
|
queryKey: ["capabilities"],
|
|
2084
2160
|
queryFn: () => fetchJSON("/capabilities"),
|
|
2085
2161
|
staleTime: 60000, // 1 minute - cached on backend too
|
|
2086
|
-
|
|
2162
|
+
// Re-check periodically so transient failures self-correct, but not while
|
|
2163
|
+
// the cluster is down: reconnecting refreshes every query anyway.
|
|
2164
|
+
refetchInterval: connected ? 60000 : false,
|
|
2087
2165
|
});
|
|
2088
2166
|
}
|
|
2089
2167
|
|
|
@@ -2136,7 +2214,7 @@ export interface CloudInstallAttempted {
|
|
|
2136
2214
|
mode: 'fresh' | 'adopt' | 'gitops'
|
|
2137
2215
|
namespace: string
|
|
2138
2216
|
release: string
|
|
2139
|
-
stage:
|
|
2217
|
+
stage: CloudInstallStage
|
|
2140
2218
|
// Discovery saw only the default namespace; a fresh plan is not proof that
|
|
2141
2219
|
// no Radar exists elsewhere.
|
|
2142
2220
|
partialScan?: boolean
|
|
@@ -2147,6 +2225,8 @@ export interface CloudInstallAttempted {
|
|
|
2147
2225
|
method?: 'argocd' | 'flux' | ''
|
|
2148
2226
|
}
|
|
2149
2227
|
|
|
2228
|
+
export type CloudInstallStage = 'inspect' | 'prepare' | 'preflight'
|
|
2229
|
+
|
|
2150
2230
|
export interface CloudInstallBlocked {
|
|
2151
2231
|
reason: 'gitops' | 'preflight' | 'unsupported'
|
|
2152
2232
|
// The Kubernetes user the attempt acted as; absent when the API server
|
|
@@ -2176,6 +2256,8 @@ export type CloudInstallState =
|
|
|
2176
2256
|
export interface CloudInstallStatus {
|
|
2177
2257
|
flowId?: string
|
|
2178
2258
|
state: CloudInstallState
|
|
2259
|
+
// Preparing only: the check the server is running now.
|
|
2260
|
+
prepareStep?: CloudInstallStage
|
|
2179
2261
|
plan?: CloudInstallPlanSummary
|
|
2180
2262
|
clusterName?: string
|
|
2181
2263
|
connectUrl?: string
|
|
@@ -2241,7 +2323,10 @@ export function useCloudConnectInfo(
|
|
|
2241
2323
|
});
|
|
2242
2324
|
}
|
|
2243
2325
|
|
|
2244
|
-
|
|
2326
|
+
// preparing: the prepare request is in flight. It answers only once every
|
|
2327
|
+
// check has run, and the cached status from before it says idle, so without
|
|
2328
|
+
// this nothing would poll and the steps could not advance.
|
|
2329
|
+
export function useCloudInstallStatus(enabled: boolean, preparing = false) {
|
|
2245
2330
|
const queryClient = useQueryClient()
|
|
2246
2331
|
const query = useQuery<CloudInstallStatus>({
|
|
2247
2332
|
queryKey: ['cloud-install-status'],
|
|
@@ -2249,7 +2334,10 @@ export function useCloudInstallStatus(enabled: boolean) {
|
|
|
2249
2334
|
enabled,
|
|
2250
2335
|
gcTime: 0,
|
|
2251
2336
|
staleTime: 0,
|
|
2252
|
-
refetchInterval: (q) =>
|
|
2337
|
+
refetchInterval: (q) => {
|
|
2338
|
+
if (preparing || q.state.data?.state === 'preparing') return 1000
|
|
2339
|
+
return cloudInstallActive(q.state.data?.state) ? 1500 : false
|
|
2340
|
+
},
|
|
2253
2341
|
})
|
|
2254
2342
|
return {
|
|
2255
2343
|
...query,
|
|
@@ -2846,30 +2934,42 @@ export function refetchOnResourceEvents(
|
|
|
2846
2934
|
return namedObjects.has(resourceEventKey(kind, String(namespace ?? ""), String(name ?? "")));
|
|
2847
2935
|
}
|
|
2848
2936
|
|
|
2849
|
-
//
|
|
2850
|
-
//
|
|
2851
|
-
export function
|
|
2937
|
+
// The query behind useResource, for callers that read several resources at
|
|
2938
|
+
// once (useQueries) and must keep its key, polling and retry rules.
|
|
2939
|
+
export function resourceQueryOptions<T>(
|
|
2852
2940
|
kind: string,
|
|
2853
2941
|
namespace: string,
|
|
2854
2942
|
name: string,
|
|
2855
2943
|
group?: string,
|
|
2856
2944
|
options?: { enabled?: boolean; refetchInterval?: number | false; cacheScope?: string },
|
|
2857
2945
|
) {
|
|
2858
|
-
|
|
2946
|
+
return {
|
|
2859
2947
|
queryKey: ["resource", kind, namespace, name, group, ...(options?.cacheScope ? [options.cacheScope] : [])],
|
|
2860
2948
|
queryFn: () => fetchResourceWithRelationships<T>(kind, namespace, name, group),
|
|
2861
2949
|
enabled: (options?.enabled ?? true) && Boolean(kind && name), // namespace can be empty for cluster-scoped resources
|
|
2862
|
-
refetchInterval: (query) => goneRecheckInterval(query, options?.refetchInterval),
|
|
2950
|
+
refetchInterval: (query: { state: { error: unknown } }) => goneRecheckInterval(query, options?.refetchInterval),
|
|
2863
2951
|
// Kind still completing its initial sync: stay in loading and poll until
|
|
2864
2952
|
// it becomes readable instead of erroring out (deep links during startup).
|
|
2865
|
-
retry: (failureCount, error) => {
|
|
2953
|
+
retry: (failureCount: number, error: unknown) => {
|
|
2866
2954
|
if (isStillLoadingError(error)) return true;
|
|
2867
2955
|
if (isKindSyncFailed(error)) return false;
|
|
2868
2956
|
return failureCount < 1; // one retry, 4xx included, unlike the QueryClient default
|
|
2869
2957
|
},
|
|
2870
|
-
retryDelay: (failureCount, error) =>
|
|
2958
|
+
retryDelay: (failureCount: number, error: unknown) =>
|
|
2871
2959
|
isStillLoadingError(error) ? 2000 : Math.min(1000 * 2 ** failureCount, 30000),
|
|
2872
|
-
}
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
// `cacheScope` keeps a caller's copy apart from the shared one, for hosts
|
|
2964
|
+
// that point one QueryClient at several clusters (see useGitOpsWriteGuard).
|
|
2965
|
+
export function useResource<T>(
|
|
2966
|
+
kind: string,
|
|
2967
|
+
namespace: string,
|
|
2968
|
+
name: string,
|
|
2969
|
+
group?: string,
|
|
2970
|
+
options?: { enabled?: boolean; refetchInterval?: number | false; cacheScope?: string },
|
|
2971
|
+
) {
|
|
2972
|
+
const query = useQuery<ResourceWithRelationships<T>>(resourceQueryOptions<T>(kind, namespace, name, group, options));
|
|
2873
2973
|
|
|
2874
2974
|
// Extract resource and relationships from the response
|
|
2875
2975
|
return {
|
|
@@ -2969,14 +3069,15 @@ export function useResources<T>(
|
|
|
2969
3069
|
kind: string,
|
|
2970
3070
|
namespace?: string,
|
|
2971
3071
|
group?: string,
|
|
2972
|
-
options?: { enabled?: boolean; refetchInterval?: number | false; cacheScope?: string },
|
|
3072
|
+
options?: { enabled?: boolean; refetchInterval?: number | false; cacheScope?: string; refetchOnMount?: boolean | 'always'; staleTime?: number },
|
|
2973
3073
|
) {
|
|
2974
3074
|
const loadingInterval = useMemo(() => createListRefetchInterval(options?.refetchInterval), [options?.refetchInterval])
|
|
2975
3075
|
const query = useQuery<ResourceListResult<T>>({
|
|
2976
3076
|
queryKey: ["resources", kind, group, namespace, ...(options?.cacheScope ? [options.cacheScope] : [])],
|
|
2977
3077
|
queryFn: ({ signal }) => fetchResourceList<T>(kind, { namespaces: namespace ? [namespace] : [], group, signal }),
|
|
2978
3078
|
enabled: (options?.enabled ?? true) && Boolean(kind),
|
|
2979
|
-
staleTime: 30000, // 30 seconds - matches refetchInterval in ResourcesView
|
|
3079
|
+
staleTime: options?.staleTime ?? 30000, // 30 seconds - matches refetchInterval in ResourcesView
|
|
3080
|
+
...(options?.refetchOnMount !== undefined ? { refetchOnMount: options.refetchOnMount } : {}),
|
|
2980
3081
|
refetchInterval: loadingInterval,
|
|
2981
3082
|
// Kind still completing its initial sync (progressive shell, or a
|
|
2982
3083
|
// deferred kind shortly after connect): keep polling instead of
|
|
@@ -3250,8 +3351,12 @@ export interface WorkloadHistoryPage {
|
|
|
3250
3351
|
events: TimelineEvent[];
|
|
3251
3352
|
truncated: boolean;
|
|
3252
3353
|
nextBeforeSeq?: number;
|
|
3253
|
-
/**
|
|
3354
|
+
/** Related history may be missing because scope bounds or expired ownership records limit traversal. */
|
|
3254
3355
|
incomplete?: boolean;
|
|
3356
|
+
/** Radar may not hold every change since the workload existed; absent when it does, and from older Radars. */
|
|
3357
|
+
historyCoverage?: WorkloadHistoryCoverage;
|
|
3358
|
+
/** Related kinds this history can't include for the caller (a queued job's Kueue Workload); the same on every page. */
|
|
3359
|
+
gaps?: ReadGap[];
|
|
3255
3360
|
}
|
|
3256
3361
|
|
|
3257
3362
|
function workloadHistoryPath(kind: string, namespace: string, name: string, group?: string, beforeSeq?: number): string {
|
|
@@ -4052,6 +4157,7 @@ export function useAutoPromConnect(): void {
|
|
|
4052
4157
|
// meta-driven toast handler stays silent — the user didn't click anything.
|
|
4053
4158
|
apiFetch(`${getApiBase()}/prometheus/connect?optional=true`, {
|
|
4054
4159
|
method: "POST",
|
|
4160
|
+
headers: automaticRequestHeaders(),
|
|
4055
4161
|
})
|
|
4056
4162
|
.then(async (resp) => {
|
|
4057
4163
|
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
|
@@ -6910,12 +7016,15 @@ export function useArtifactHubChart(
|
|
|
6910
7016
|
// GitOps Mutation Factory
|
|
6911
7017
|
// ============================================================================
|
|
6912
7018
|
|
|
6913
|
-
interface GitOpsMutationConfig<TVariables> {
|
|
7019
|
+
interface GitOpsMutationConfig<TVariables, TContext = undefined> {
|
|
6914
7020
|
getPath: (variables: TVariables) => string;
|
|
6915
|
-
|
|
7021
|
+
// Called by the hook on every render (so it may call hooks); its value is
|
|
7022
|
+
// passed to getBody.
|
|
7023
|
+
useRequestContext?: () => TContext;
|
|
7024
|
+
getBody?: (variables: TVariables, context: TContext) => unknown;
|
|
6916
7025
|
errorMessage: string;
|
|
6917
7026
|
successMessage?: string;
|
|
6918
|
-
getSuccessMessage?: (data: GitOpsOperationResponse) => string;
|
|
7027
|
+
getSuccessMessage?: (data: GitOpsOperationResponse, variables: TVariables) => string;
|
|
6919
7028
|
getInvalidateKeys: (variables: TVariables) => (string | undefined)[][];
|
|
6920
7029
|
}
|
|
6921
7030
|
|
|
@@ -6923,11 +7032,12 @@ interface GitOpsMutationConfig<TVariables> {
|
|
|
6923
7032
|
* Factory function for creating GitOps mutation hooks with consistent patterns.
|
|
6924
7033
|
* Handles fetch, error handling, meta messages, and query invalidation.
|
|
6925
7034
|
*/
|
|
6926
|
-
function createGitOpsMutation<TVariables>(
|
|
6927
|
-
config: GitOpsMutationConfig<TVariables>,
|
|
7035
|
+
function createGitOpsMutation<TVariables, TContext = undefined>(
|
|
7036
|
+
config: GitOpsMutationConfig<TVariables, TContext>,
|
|
6928
7037
|
) {
|
|
6929
7038
|
return function useGitOpsMutation() {
|
|
6930
7039
|
const queryClient = useQueryClient();
|
|
7040
|
+
const requestContext = config.useRequestContext?.() as TContext;
|
|
6931
7041
|
return useMutation<GitOpsOperationResponse, Error, TVariables>({
|
|
6932
7042
|
mutationFn: async (
|
|
6933
7043
|
variables: TVariables,
|
|
@@ -6940,7 +7050,7 @@ function createGitOpsMutation<TVariables>(
|
|
|
6940
7050
|
? { "Content-Type": "application/json" }
|
|
6941
7051
|
: undefined,
|
|
6942
7052
|
body: config.getBody
|
|
6943
|
-
? JSON.stringify(config.getBody(variables))
|
|
7053
|
+
? JSON.stringify(config.getBody(variables, requestContext))
|
|
6944
7054
|
: undefined,
|
|
6945
7055
|
},
|
|
6946
7056
|
);
|
|
@@ -6956,7 +7066,7 @@ function createGitOpsMutation<TVariables>(
|
|
|
6956
7066
|
},
|
|
6957
7067
|
onSuccess: (data, variables) => {
|
|
6958
7068
|
if (config.getSuccessMessage)
|
|
6959
|
-
showApiSuccess(config.getSuccessMessage(data));
|
|
7069
|
+
showApiSuccess(config.getSuccessMessage(data, variables));
|
|
6960
7070
|
config
|
|
6961
7071
|
.getInvalidateKeys(variables)
|
|
6962
7072
|
.forEach((key) => queryClient.invalidateQueries({ queryKey: key }));
|
|
@@ -6987,8 +7097,12 @@ export type ArgoSyncVars = ArgoAppVars & {
|
|
|
6987
7097
|
applyOnly?: boolean;
|
|
6988
7098
|
// Free-form Argo SyncOption strings, e.g. "Replace=true",
|
|
6989
7099
|
// "ServerSideApply=true", "PruneLast=true". Caller is responsible for
|
|
6990
|
-
// spelling.
|
|
7100
|
+
// spelling. Omitted: the Application's own spec.syncPolicy.syncOptions.
|
|
6991
7101
|
syncOptions?: string[];
|
|
7102
|
+
// The Application's spec.syncPolicy.syncOptions as the caller last read
|
|
7103
|
+
// them. Not a request field: sent as syncOptions only to a Radar that would
|
|
7104
|
+
// otherwise drop them (see argoSyncRequestBody).
|
|
7105
|
+
applicationSyncOptions?: string[];
|
|
6992
7106
|
};
|
|
6993
7107
|
|
|
6994
7108
|
export interface ArgoResourceValidationResult {
|
|
@@ -7009,11 +7123,13 @@ export function buildArgoResourceSyncVars(
|
|
|
7009
7123
|
name: string,
|
|
7010
7124
|
resource: GitOpsInsightRef,
|
|
7011
7125
|
opts: ArgoSyncOpts,
|
|
7126
|
+
applicationSyncOptions?: string[],
|
|
7012
7127
|
): ArgoSyncVars {
|
|
7013
7128
|
return {
|
|
7014
7129
|
namespace,
|
|
7015
7130
|
name,
|
|
7016
7131
|
...opts,
|
|
7132
|
+
applicationSyncOptions,
|
|
7017
7133
|
resources: [
|
|
7018
7134
|
{
|
|
7019
7135
|
group: resource.group,
|
|
@@ -7096,24 +7212,45 @@ export const useFluxSyncWithSource = createGitOpsMutation<FluxResourceVars>({
|
|
|
7096
7212
|
// ArgoCD API hooks
|
|
7097
7213
|
// ============================================================================
|
|
7098
7214
|
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7215
|
+
// argoSyncRequestBody is the body POSTed to .../sync. A Radar that predates
|
|
7216
|
+
// argoSyncInheritance prunes when prune is omitted and syncs with no options
|
|
7217
|
+
// when syncOptions is omitted, so prune is always sent and, for such a Radar,
|
|
7218
|
+
// the Application's options are sent in place of an omission.
|
|
7219
|
+
export function argoSyncRequestBody(
|
|
7220
|
+
v: ArgoSyncVars,
|
|
7221
|
+
serverInheritsOptions: boolean,
|
|
7222
|
+
) {
|
|
7223
|
+
return {
|
|
7102
7224
|
resources: v.resources,
|
|
7103
7225
|
revision: v.revision,
|
|
7104
|
-
prune: v.prune,
|
|
7226
|
+
prune: v.prune ?? false,
|
|
7105
7227
|
dryRun: v.dryRun,
|
|
7106
7228
|
force: v.force,
|
|
7107
7229
|
applyOnly: v.applyOnly,
|
|
7108
|
-
syncOptions:
|
|
7109
|
-
|
|
7230
|
+
syncOptions: argoSyncOptionsForRequest(
|
|
7231
|
+
v.syncOptions,
|
|
7232
|
+
v.applicationSyncOptions,
|
|
7233
|
+
serverInheritsOptions,
|
|
7234
|
+
),
|
|
7235
|
+
};
|
|
7236
|
+
}
|
|
7237
|
+
|
|
7238
|
+
function useArgoSyncInheritance(): boolean {
|
|
7239
|
+
return useRadarFeature("argoSyncInheritance").support === "supported";
|
|
7240
|
+
}
|
|
7241
|
+
|
|
7242
|
+
export const useArgoSync = createGitOpsMutation<ArgoSyncVars, boolean>({
|
|
7243
|
+
getPath: (v) => `/argo/applications/${v.namespace}/${v.name}/sync`,
|
|
7244
|
+
useRequestContext: useArgoSyncInheritance,
|
|
7245
|
+
getBody: argoSyncRequestBody,
|
|
7110
7246
|
errorMessage: "Failed to trigger sync",
|
|
7111
|
-
|
|
7247
|
+
getSuccessMessage: (_data, v) => (v.dryRun ? "Dry run started" : "Sync initiated"),
|
|
7112
7248
|
getInvalidateKeys: argoInvalidateKeys,
|
|
7113
7249
|
});
|
|
7114
7250
|
|
|
7115
7251
|
export function useArgoResourceValidation() {
|
|
7116
7252
|
const queryClient = useQueryClient();
|
|
7253
|
+
const serverInheritsOptions = useArgoSyncInheritance();
|
|
7117
7254
|
return useMutation<ArgoResourceValidationResult, Error, ArgoSyncVars>({
|
|
7118
7255
|
mutationFn: async (variables) => {
|
|
7119
7256
|
const response = await apiFetch(
|
|
@@ -7124,7 +7261,11 @@ export function useArgoResourceValidation() {
|
|
|
7124
7261
|
body: JSON.stringify({
|
|
7125
7262
|
resources: variables.resources,
|
|
7126
7263
|
force: variables.force,
|
|
7127
|
-
syncOptions:
|
|
7264
|
+
syncOptions: argoSyncOptionsForRequest(
|
|
7265
|
+
variables.syncOptions,
|
|
7266
|
+
variables.applicationSyncOptions,
|
|
7267
|
+
serverInheritsOptions,
|
|
7268
|
+
),
|
|
7128
7269
|
}),
|
|
7129
7270
|
},
|
|
7130
7271
|
);
|
|
@@ -7146,7 +7287,7 @@ export const useArgoRollback = createGitOpsMutation<ArgoRollbackVars>({
|
|
|
7146
7287
|
getPath: (v) => `/argo/applications/${v.namespace}/${v.name}/rollback`,
|
|
7147
7288
|
getBody: (v) => ({ id: v.id, prune: v.prune, dryRun: v.dryRun }),
|
|
7148
7289
|
errorMessage: "Failed to roll back application",
|
|
7149
|
-
|
|
7290
|
+
getSuccessMessage: (_data, v) => (v.dryRun ? "Rollback preview started" : "Rollback initiated"),
|
|
7150
7291
|
getInvalidateKeys: argoInvalidateKeys,
|
|
7151
7292
|
});
|
|
7152
7293
|
|
|
@@ -7256,6 +7397,19 @@ export async function fetchSessionCounts(): Promise<SessionCounts> {
|
|
|
7256
7397
|
const CONTEXT_SWITCH_TIMEOUT = 45000; // 45 seconds
|
|
7257
7398
|
|
|
7258
7399
|
// Switch to a different context
|
|
7400
|
+
// A refused context switch. errorType is set when the server checked the new
|
|
7401
|
+
// cluster before leaving the current one and it didn't answer; older Radar
|
|
7402
|
+
// servers never send it.
|
|
7403
|
+
export class SwitchContextError extends Error {
|
|
7404
|
+
constructor(
|
|
7405
|
+
message: string,
|
|
7406
|
+
readonly errorType?: string,
|
|
7407
|
+
) {
|
|
7408
|
+
super(message);
|
|
7409
|
+
this.name = "SwitchContextError";
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
|
|
7259
7413
|
export function useSwitchContext() {
|
|
7260
7414
|
const queryClient = useQueryClient();
|
|
7261
7415
|
|
|
@@ -7279,7 +7433,10 @@ export function useSwitchContext() {
|
|
|
7279
7433
|
|
|
7280
7434
|
if (!response.ok) {
|
|
7281
7435
|
const error = await readErrorBody(response);
|
|
7282
|
-
throw new
|
|
7436
|
+
throw new SwitchContextError(
|
|
7437
|
+
error.error || `HTTP ${response.status}`,
|
|
7438
|
+
typeof error.errorType === "string" ? error.errorType : undefined,
|
|
7439
|
+
);
|
|
7283
7440
|
}
|
|
7284
7441
|
return response.json();
|
|
7285
7442
|
} catch (error) {
|
|
@@ -7671,8 +7828,8 @@ export function useWorkloadPods(
|
|
|
7671
7828
|
fetchJSON(`/workloads/${kind}/${namespace}/${name}/pods${queryString}`),
|
|
7672
7829
|
enabled: Boolean(kind && namespace && name),
|
|
7673
7830
|
staleTime: 10000, // 10 seconds - pods can change
|
|
7674
|
-
refetchInterval:
|
|
7675
|
-
retry: options?.ownerUID ? (count, error) => !(error
|
|
7831
|
+
refetchInterval: (query) => workloadPodsRefetchInterval(query.state.error, options),
|
|
7832
|
+
retry: options?.ownerUID ? (count, error) => !isStableClientError(error) && count < 2 : undefined,
|
|
7676
7833
|
});
|
|
7677
7834
|
}
|
|
7678
7835
|
|
|
@@ -7732,6 +7889,32 @@ export function useKueueAdmission(namespace: string, name: string, uid: string |
|
|
|
7732
7889
|
})
|
|
7733
7890
|
}
|
|
7734
7891
|
|
|
7892
|
+
// Kueue's reported position for one pending Workload. Polls only while the
|
|
7893
|
+
// answer can change by itself: a refusal, an absent API or an unsupported
|
|
7894
|
+
// version gives the same answer until someone changes access or the cluster.
|
|
7895
|
+
const kueuePositionPolledStatuses = new Set(['listed', 'not_listed', 'limit_reached', 'queue_unknown'])
|
|
7896
|
+
|
|
7897
|
+
export function kueuePositionRefetchInterval({ data, error }: { data?: KueuePositionResponse; error?: unknown }): number | false {
|
|
7898
|
+
if (error && !shouldRetryRadarQuery(0, error)) return false
|
|
7899
|
+
if (!data?.eligible || !data.position) return 30000
|
|
7900
|
+
const { status, code } = data.position
|
|
7901
|
+
return kueuePositionPolledStatuses.has(status) || (status === 'unavailable' && readActionFor(code) === 'retry') ? 30000 : false
|
|
7902
|
+
}
|
|
7903
|
+
|
|
7904
|
+
/** UID and queueName invalidate the cache; the endpoint reads by namespace/name.
|
|
7905
|
+
* Callers must check the returned UID and eligibility before displaying a position. */
|
|
7906
|
+
export function useKueuePendingPosition(namespace: string, name: string, uid: string | undefined, queueName: string | undefined, enabled: boolean) {
|
|
7907
|
+
const { guard, gatedKey } = useRadarFeature('kueuePendingPosition')
|
|
7908
|
+
return useQuery<KueuePositionResponse>({
|
|
7909
|
+
queryKey: ['kueue-position', namespace, name, uid, queueName ?? '', ...gatedKey],
|
|
7910
|
+
queryFn: () => guard(() => fetchJSON<KueuePositionResponse>(`/kueue/position/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}`)),
|
|
7911
|
+
enabled: enabled && Boolean(namespace && name && uid),
|
|
7912
|
+
staleTime: 15000,
|
|
7913
|
+
refetchInterval: (query) => kueuePositionRefetchInterval(query.state),
|
|
7914
|
+
retry: shouldRetryRadarQuery,
|
|
7915
|
+
})
|
|
7916
|
+
}
|
|
7917
|
+
|
|
7735
7918
|
// Fetch logs for a workload (non-streaming)
|
|
7736
7919
|
export function useWorkloadLogs(
|
|
7737
7920
|
kind: string,
|
|
@@ -8076,6 +8259,53 @@ export interface KueueProvisioningResponse {
|
|
|
8076
8259
|
}>
|
|
8077
8260
|
}
|
|
8078
8261
|
|
|
8262
|
+
// The Workloads that belong to a Kueue queue, page by page. Pages chain by
|
|
8263
|
+
// cursor; a refetch re-reads them from the first, so a list that changed is
|
|
8264
|
+
// traversed again rather than patched. Nothing is read until the queue's UID
|
|
8265
|
+
// is known, nor for a LocalQueue without its namespace.
|
|
8266
|
+
export function useKueueQueueWorkloads(queue: { kind: 'ClusterQueue' | 'LocalQueue'; namespace?: string; name: string; uid?: string }, filters: { membership?: KueueQueueMembership; state?: string }) {
|
|
8267
|
+
const { membership, state } = filters
|
|
8268
|
+
const { guard, gatedKey, support, upgrade } = useRadarFeature('kueueQueueWorkloads')
|
|
8269
|
+
const path = queue.kind === 'ClusterQueue'
|
|
8270
|
+
? `/kueue/clusterqueues/${encodeURIComponent(queue.name)}/workloads`
|
|
8271
|
+
: `/kueue/localqueues/${encodeURIComponent(queue.namespace ?? '')}/${encodeURIComponent(queue.name)}/workloads`
|
|
8272
|
+
const query = useInfiniteQuery<KueueQueueWorkloadsResponse>({
|
|
8273
|
+
queryKey: ['kueue-queue-workloads', queue.kind, queue.namespace ?? '', queue.name, queue.uid ?? '', membership ?? '', state ?? '', ...gatedKey],
|
|
8274
|
+
queryFn: ({ pageParam, signal }) => {
|
|
8275
|
+
const params = new URLSearchParams()
|
|
8276
|
+
if (membership) params.set('membership', membership)
|
|
8277
|
+
if (state) params.set('state', state)
|
|
8278
|
+
if (typeof pageParam === 'string') params.set('cursor', pageParam)
|
|
8279
|
+
const qs = params.toString()
|
|
8280
|
+
return guard(() => fetchJSON<KueueQueueWorkloadsResponse>(`${path}${qs ? `?${qs}` : ''}`, signal))
|
|
8281
|
+
},
|
|
8282
|
+
initialPageParam: undefined as string | undefined,
|
|
8283
|
+
getNextPageParam: last => last.workloads?.next,
|
|
8284
|
+
// A changed filter keeps the previous list on screen until the new one
|
|
8285
|
+
// arrives; the renderer drops pages of another queue (by UID).
|
|
8286
|
+
placeholderData: previous => previous,
|
|
8287
|
+
enabled: Boolean(queue.name && queue.uid && (queue.kind === 'ClusterQueue' || queue.namespace)) && support !== 'unsupported',
|
|
8288
|
+
staleTime: 5000,
|
|
8289
|
+
// A paged list isn't replayed on mount (that would reread the queue once
|
|
8290
|
+
// per page); the renderer restarts it from the first page instead.
|
|
8291
|
+
refetchOnMount: query => (query.state.data?.pages.length ?? 0) <= 1,
|
|
8292
|
+
refetchOnWindowFocus: query => (query.state.data?.pages.length ?? 0) <= 1,
|
|
8293
|
+
refetchOnReconnect: query => (query.state.data?.pages.length ?? 0) <= 1,
|
|
8294
|
+
// Poll the first page only: refetching an infinite query rereads every
|
|
8295
|
+
// loaded page, so a list paged further waits for an explicit refresh.
|
|
8296
|
+
// A part a retry can complete (still loading, a check that failed) is
|
|
8297
|
+
// polled sooner.
|
|
8298
|
+
refetchInterval: query => {
|
|
8299
|
+
if (query.state.error instanceof ApiError && query.state.error.status < 500) return false
|
|
8300
|
+
const pages = query.state.data?.pages ?? []
|
|
8301
|
+
if (pages.length > 1) return false
|
|
8302
|
+
return kueueQueueRetryable(pages[0]) ? 3000 : 15000
|
|
8303
|
+
},
|
|
8304
|
+
retry: shouldRetryRadarQuery,
|
|
8305
|
+
})
|
|
8306
|
+
return { ...query, upgrade, support }
|
|
8307
|
+
}
|
|
8308
|
+
|
|
8079
8309
|
export function useKueueProvisioning(namespace: string, name: string, uid: string | undefined, enabled: boolean) {
|
|
8080
8310
|
return useQuery<KueueProvisioningResponse>({
|
|
8081
8311
|
queryKey: ['kueue-provisioning', namespace, name, uid],
|