@skyhook-io/radar-app 1.20.0 → 1.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/App.tsx +18 -11
- package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
- package/src/api/client.pauseDeployment.test.tsx +77 -0
- package/src/api/client.restartError.test.ts +14 -0
- package/src/api/client.revisionRefresh.test.tsx +44 -0
- package/src/api/client.rollbackError.test.ts +14 -0
- package/src/api/client.ts +287 -21
- package/src/api/helmInventory.test.tsx +108 -0
- package/src/api/networkAttachments.test.tsx +120 -0
- package/src/api/networkAttachments.ts +30 -0
- package/src/api/radarFeatures.test.ts +5 -0
- package/src/api/radarFeatures.ts +5 -0
- package/src/api/secretsStore.test.ts +33 -0
- package/src/api/secretsStore.ts +37 -0
- package/src/components/ConnectionErrorView.test.tsx +11 -0
- package/src/components/ConnectionErrorView.tsx +19 -0
- package/src/components/ContextSwitcher.tsx +9 -2
- package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
- package/src/components/applications/ApplicationsView.tsx +8 -11
- package/src/components/cost/CostView.tsx +27 -9
- package/src/components/curl/ServiceCurlAvailability.test.tsx +32 -0
- package/src/components/curl/ServiceCurlButton.tsx +2 -2
- package/src/components/diagnose/InvestigationView.tsx +12 -3
- package/src/components/diagnose/investigationCase.test.tsx +41 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +72 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +61 -16
- 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/bodies/platform.tsx +82 -51
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
- package/src/components/dock/TerminalPreferences.test.tsx +68 -0
- package/src/components/dock/TerminalPreferences.tsx +73 -0
- package/src/components/gitops/GitOpsView.tsx +1 -9
- package/src/components/helm/HelmDrawerFrame.tsx +101 -0
- package/src/components/helm/HelmDrawerRouting.test.tsx +86 -0
- package/src/components/helm/HelmReleaseDrawer.tsx +47 -98
- package/src/components/helm/HelmView.tsx +215 -71
- package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
- package/src/components/helm/NotCheckedBadge.tsx +39 -0
- 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.test.tsx +86 -0
- package/src/components/helm/OwnedResources.tsx +69 -10
- package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
- package/src/components/home/ClusterHealthCard.restricted.test.tsx +76 -0
- package/src/components/home/ClusterHealthCard.test.ts +44 -1
- package/src/components/home/ClusterHealthCard.tsx +49 -14
- package/src/components/home/HelmSummary.tsx +38 -19
- package/src/components/home/HelmSummary.unread.test.ts +16 -0
- package/src/components/home/HomeAgentBlock.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +38 -12
- package/src/components/home/MCPSetupDialog.tsx +5 -2
- package/src/components/home/mcpToolCatalog.ts +45 -5
- package/src/components/issues/uncheckedSources.test.ts +2 -0
- package/src/components/issues/uncheckedSources.ts +3 -0
- package/src/components/resource/RightsizingStrip.test.ts +57 -0
- package/src/components/resource/RightsizingStrip.tsx +53 -4
- package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
- package/src/components/resources/ImageFilesystemModal.tsx +98 -6
- package/src/components/resources/PodFileUploadPanel.tsx +150 -0
- package/src/components/resources/PodFilesystemModal.tsx +246 -3
- package/src/components/resources/pod-file-upload.test.tsx +223 -0
- package/src/components/resources/pod-file-upload.ts +266 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
- package/src/components/resources/renderers/PodRenderer.tsx +26 -1
- package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
- 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/rightsizing/RightsizingScanView.tsx +16 -1
- package/src/components/rightsizing/model.test.ts +11 -0
- package/src/components/rightsizing/model.ts +3 -1
- package/src/components/rightsizing/presentation.test.ts +46 -0
- package/src/components/rightsizing/presentation.ts +17 -2
- package/src/components/traffic/TrafficView.tsx +27 -27
- package/src/components/traffic/trafficFilters.test.ts +18 -1
- package/src/components/traffic/trafficFilters.ts +30 -1
- package/src/components/ui/Omnibar.tsx +4 -1
- package/src/components/ui/RadarOmnibar.test.tsx +55 -2
- package/src/components/ui/RadarOmnibar.tsx +7 -1
- package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
- package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
- package/src/components/ui/UpdateNotification.test.tsx +23 -1
- package/src/components/ui/UpdateNotification.tsx +26 -2
- package/src/components/ui/omnibar-match.test.ts +7 -0
- package/src/components/ui/omnibar-match.ts +1 -0
- package/src/components/ui/searchCoverageNote.test.ts +17 -0
- package/src/components/ui/searchCoverageNote.ts +31 -7
- package/src/components/useContextSwitchFlow.tsx +9 -1
- package/src/components/whats-new/releaseNotes.ts +1 -1
- package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
- package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +51 -11
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +2 -2
- package/src/contexts/CapabilitiesContext.tsx +2 -0
- package/src/hooks/useResolvedGitOpsOwner.test.ts +22 -0
- package/src/hooks/useResolvedGitOpsOwner.ts +6 -3
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +9 -0
- package/src/utils/namespacePick.test.ts +87 -0
- package/src/utils/namespacePick.ts +88 -0
package/src/api/client.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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'
|
|
5
|
+
import type { ReadGap, ReadGapSet } from '@skyhook-io/k8s-ui/types/read-coverage'
|
|
6
6
|
import type { WorkloadHistoryCoverage } from '@skyhook-io/k8s-ui/utils/workload-history-notes'
|
|
7
7
|
import { knownKindForPluralWithGroup, pluralToKind } from '@skyhook-io/k8s-ui/utils/navigation'
|
|
8
8
|
import { useEffect, useRef, useCallback, useMemo } from 'react'
|
|
@@ -35,6 +35,7 @@ import type {
|
|
|
35
35
|
import { focusManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
36
36
|
import { showApiError, showApiSuccess, showApiNotice } from '../components/ui/Toast'
|
|
37
37
|
import { useIsAuthEnabled, useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
|
|
38
|
+
import { applyTabPick, cleanPick, ownsTabPick, pruneTabPick, withActives, writeTabPick } from '../utils/namespacePick'
|
|
38
39
|
import type {
|
|
39
40
|
Topology,
|
|
40
41
|
ClusterInfo,
|
|
@@ -44,8 +45,10 @@ import type {
|
|
|
44
45
|
TimelineEvent,
|
|
45
46
|
TimeRange,
|
|
46
47
|
ResourceWithRelationships,
|
|
48
|
+
HelmInventory,
|
|
47
49
|
HelmRelease,
|
|
48
50
|
HelmReleaseDetail,
|
|
51
|
+
ObservedHelmReleaseDetail,
|
|
49
52
|
HelmValues,
|
|
50
53
|
ManifestDiff,
|
|
51
54
|
NotesDiff,
|
|
@@ -425,7 +428,12 @@ export async function fetchJSON<T>(
|
|
|
425
428
|
// ============================================================================
|
|
426
429
|
|
|
427
430
|
export interface DashboardCluster {
|
|
431
|
+
// Kubeconfig context, or "in-cluster". The kubeconfig cluster entry is in
|
|
432
|
+
// kubeconfigCluster.
|
|
428
433
|
name: string;
|
|
434
|
+
// Kubeconfig cluster entry the context points at; several contexts can
|
|
435
|
+
// share one. Absent in in-cluster mode and from older Radar.
|
|
436
|
+
kubeconfigCluster?: string;
|
|
429
437
|
platform: string;
|
|
430
438
|
version: string;
|
|
431
439
|
connected: boolean;
|
|
@@ -524,18 +532,27 @@ export interface DashboardHelmRelease {
|
|
|
524
532
|
chartVersion: string;
|
|
525
533
|
status: string;
|
|
526
534
|
resourceHealth?: string;
|
|
535
|
+
// Workloads and Pods whose live status wasn't read.
|
|
536
|
+
statusUnreadCount?: number;
|
|
527
537
|
}
|
|
528
538
|
|
|
529
539
|
export interface DashboardHelmSummary {
|
|
530
540
|
total: number;
|
|
531
541
|
releases: DashboardHelmRelease[];
|
|
532
|
-
|
|
542
|
+
// True when no Helm records could be read and the caller was refused. A
|
|
543
|
+
// refusal in only some namespaces leaves it false and fills unreadNamespaces.
|
|
544
|
+
restricted?: boolean;
|
|
533
545
|
// error + errorCode populated when the Helm read failed for a non-RBAC
|
|
534
546
|
// reason (client not initialized, unconfigured, network). Surfaced
|
|
535
547
|
// via the dashboard widget so empty results aren't mistaken for
|
|
536
548
|
// "this cluster has zero releases."
|
|
537
549
|
error?: string;
|
|
538
550
|
errorCode?: string;
|
|
551
|
+
// Namespaces whose Helm records weren't read: refused, or the permission
|
|
552
|
+
// check behind that went unanswered. Their releases are missing from total
|
|
553
|
+
// and releases. Absent when everything in scope was read, on a restricted or
|
|
554
|
+
// failed answer, and from an older Radar.
|
|
555
|
+
unreadNamespaces?: ReadGapSet<string>;
|
|
539
556
|
}
|
|
540
557
|
|
|
541
558
|
export interface DashboardCRDCount {
|
|
@@ -801,8 +818,10 @@ export interface UncheckedSource {
|
|
|
801
818
|
// The kinds within the source that went unchecked; absent means the whole
|
|
802
819
|
// source, or that Radar couldn't tell which kinds.
|
|
803
820
|
kinds?: { group?: string; kind: string }[];
|
|
804
|
-
// The namespaces
|
|
805
|
-
//
|
|
821
|
+
// The namespaces this entry's gap is limited to: the source was checked in
|
|
822
|
+
// the others, and these weren't (the read failed or was refused there, or
|
|
823
|
+
// Radar didn't read there because the caller can't). Absent means the gap
|
|
824
|
+
// isn't limited to particular namespaces.
|
|
806
825
|
namespaces?: string[];
|
|
807
826
|
}
|
|
808
827
|
|
|
@@ -926,6 +945,7 @@ export interface CronJobSchedulingEvidence {
|
|
|
926
945
|
}
|
|
927
946
|
|
|
928
947
|
export interface SubjectIssuesResponse {
|
|
948
|
+
node_certificate_report?: NodeCertificateReport;
|
|
929
949
|
scheduling_report?: CronJobSchedulingEvidence;
|
|
930
950
|
issues: Issue[];
|
|
931
951
|
coverage: "ok" | "syncing" | "notWatched" | "unknownKind";
|
|
@@ -935,6 +955,19 @@ export interface SubjectIssuesResponse {
|
|
|
935
955
|
unchecked_sources?: UncheckedSource[];
|
|
936
956
|
}
|
|
937
957
|
|
|
958
|
+
export interface NodeCertificateReport {
|
|
959
|
+
uid: string;
|
|
960
|
+
event_id?: string;
|
|
961
|
+
state: 'reported' | 'unverified' | 'ok';
|
|
962
|
+
reason: string;
|
|
963
|
+
message: string;
|
|
964
|
+
last_reported_at: string;
|
|
965
|
+
expires_at?: string;
|
|
966
|
+
not_before?: string;
|
|
967
|
+
history_incomplete?: boolean;
|
|
968
|
+
validity_unknown?: boolean;
|
|
969
|
+
}
|
|
970
|
+
|
|
938
971
|
export function useSubjectIssues(
|
|
939
972
|
subject: { kind: string; group: string; namespace: string; name: string; uid?: string } | null,
|
|
940
973
|
enabled: boolean,
|
|
@@ -1129,7 +1162,8 @@ export interface OpenCostNamespaceCost {
|
|
|
1129
1162
|
hourlyCost: number;
|
|
1130
1163
|
cpuCost: number;
|
|
1131
1164
|
memoryCost: number;
|
|
1132
|
-
|
|
1165
|
+
// null: the namespace has volumes whose cost could not be calculated.
|
|
1166
|
+
storageCost?: number | null;
|
|
1133
1167
|
cpuUsageCost?: number;
|
|
1134
1168
|
memoryUsageCost?: number;
|
|
1135
1169
|
efficiency?: number;
|
|
@@ -1164,7 +1198,8 @@ export interface OpenCostSummary {
|
|
|
1164
1198
|
currency?: string;
|
|
1165
1199
|
window?: string;
|
|
1166
1200
|
totalHourlyCost?: number;
|
|
1167
|
-
|
|
1201
|
+
// null: at least one namespace's storage cost is unknown.
|
|
1202
|
+
totalStorageCost?: number | null;
|
|
1168
1203
|
totalIdleCost?: number;
|
|
1169
1204
|
clusterEfficiency?: number;
|
|
1170
1205
|
namespaceScope?: string[];
|
|
@@ -1861,6 +1896,12 @@ export interface VersionInfo {
|
|
|
1861
1896
|
releaseNotes?: string;
|
|
1862
1897
|
installMethod: InstallMethod;
|
|
1863
1898
|
updateCommand?: string;
|
|
1899
|
+
/**
|
|
1900
|
+
* Desktop install that cannot update itself, and how the user updates instead:
|
|
1901
|
+
* a new AppImage, a new .deb/.rpm through the package manager, or a download
|
|
1902
|
+
* because Radar can't write to its folder. Absent: Update Now works.
|
|
1903
|
+
*/
|
|
1904
|
+
manualUpdate?: 'appimage' | 'package' | 'download';
|
|
1864
1905
|
error?: string;
|
|
1865
1906
|
productHuntLaunch?: { enabled: boolean; url: string; start: string; end: string };
|
|
1866
1907
|
}
|
|
@@ -3900,7 +3941,8 @@ export type RightsizingFit =
|
|
|
3900
3941
|
| "oversized"
|
|
3901
3942
|
| "under_requested"
|
|
3902
3943
|
| "missing_request"
|
|
3903
|
-
| "insufficient_history"
|
|
3944
|
+
| "insufficient_history"
|
|
3945
|
+
| "pod_level_request";
|
|
3904
3946
|
export type RightsizingConfidence = "low" | "medium" | "high";
|
|
3905
3947
|
export type RightsizingOwnerCoverage = "ksm_history" | "current_pods";
|
|
3906
3948
|
|
|
@@ -3913,6 +3955,9 @@ export interface RightsizingRow {
|
|
|
3913
3955
|
currentRequestValue?: number;
|
|
3914
3956
|
currentLimit?: string;
|
|
3915
3957
|
currentLimitValue?: number;
|
|
3958
|
+
/** The pod's fixed pod-level request (spec.resources), set when fit is pod_level_request. */
|
|
3959
|
+
podLevelRequest?: string;
|
|
3960
|
+
podLevelRequestValue?: number;
|
|
3916
3961
|
observed?: {
|
|
3917
3962
|
name: "P95" | "P99" | "Max";
|
|
3918
3963
|
value: number;
|
|
@@ -5362,8 +5407,7 @@ export function useRestartWorkload() {
|
|
|
5362
5407
|
},
|
|
5363
5408
|
);
|
|
5364
5409
|
if (!response.ok) {
|
|
5365
|
-
|
|
5366
|
-
throw new Error(error.error || `HTTP ${response.status}`);
|
|
5410
|
+
throw new Error(restartErrorMessage(await readErrorBody(response), response.status));
|
|
5367
5411
|
}
|
|
5368
5412
|
return response.json();
|
|
5369
5413
|
},
|
|
@@ -5380,6 +5424,63 @@ export function useRestartWorkload() {
|
|
|
5380
5424
|
});
|
|
5381
5425
|
}
|
|
5382
5426
|
|
|
5427
|
+
function useSetDeploymentPaused(
|
|
5428
|
+
action: "pause" | "resume",
|
|
5429
|
+
meta: { errorMessage: string; successMessage: string },
|
|
5430
|
+
) {
|
|
5431
|
+
const queryClient = useQueryClient();
|
|
5432
|
+
const { guard } = useRadarFeature("deploymentPause");
|
|
5433
|
+
|
|
5434
|
+
return useMutation({
|
|
5435
|
+
mutationFn: ({
|
|
5436
|
+
kind,
|
|
5437
|
+
namespace,
|
|
5438
|
+
name,
|
|
5439
|
+
}: {
|
|
5440
|
+
kind: string;
|
|
5441
|
+
namespace: string;
|
|
5442
|
+
name: string;
|
|
5443
|
+
}) =>
|
|
5444
|
+
guard(async () => {
|
|
5445
|
+
const response = await apiFetch(
|
|
5446
|
+
`${getApiBase()}/workloads/${kind}/${namespace}/${name}/${action}`,
|
|
5447
|
+
{
|
|
5448
|
+
method: "POST",
|
|
5449
|
+
},
|
|
5450
|
+
);
|
|
5451
|
+
if (!response.ok) {
|
|
5452
|
+
const error = await readErrorBody(response);
|
|
5453
|
+
throw new Error(error.error || `HTTP ${response.status}`);
|
|
5454
|
+
}
|
|
5455
|
+
return response.json();
|
|
5456
|
+
}),
|
|
5457
|
+
meta,
|
|
5458
|
+
onSuccess: (_, variables) => {
|
|
5459
|
+
queryClient.invalidateQueries({
|
|
5460
|
+
queryKey: ["resources", variables.kind],
|
|
5461
|
+
});
|
|
5462
|
+
queryClient.invalidateQueries({
|
|
5463
|
+
queryKey: ["resource", variables.kind, variables.namespace, variables.name],
|
|
5464
|
+
});
|
|
5465
|
+
queryClient.invalidateQueries({ queryKey: ["topology"] });
|
|
5466
|
+
},
|
|
5467
|
+
});
|
|
5468
|
+
}
|
|
5469
|
+
|
|
5470
|
+
export function usePauseDeployment() {
|
|
5471
|
+
return useSetDeploymentPaused("pause", {
|
|
5472
|
+
errorMessage: "Failed to pause rollout",
|
|
5473
|
+
successMessage: "Rollout paused",
|
|
5474
|
+
});
|
|
5475
|
+
}
|
|
5476
|
+
|
|
5477
|
+
export function useResumeDeployment() {
|
|
5478
|
+
return useSetDeploymentPaused("resume", {
|
|
5479
|
+
errorMessage: "Failed to resume rollout",
|
|
5480
|
+
successMessage: "Rollout resumed",
|
|
5481
|
+
});
|
|
5482
|
+
}
|
|
5483
|
+
|
|
5383
5484
|
export function fetchWorkloadImages(
|
|
5384
5485
|
kind: string,
|
|
5385
5486
|
namespace: string,
|
|
@@ -5547,6 +5648,46 @@ export function useWorkloadRevisions(
|
|
|
5547
5648
|
});
|
|
5548
5649
|
}
|
|
5549
5650
|
|
|
5651
|
+
// A rollout can start long after its request returned, as when a resume releases
|
|
5652
|
+
// a held template, so nothing in the request says when its revision exists. The
|
|
5653
|
+
// controller records the Deployment's revision only after creating that ReplicaSet.
|
|
5654
|
+
// deploymentRevision is undefined until the resource loads, and empty on a loaded
|
|
5655
|
+
// Deployment with no revision yet, which is how one created paused starts out.
|
|
5656
|
+
export function useRefreshRevisionsOnNewRollout(
|
|
5657
|
+
kind: string,
|
|
5658
|
+
namespace: string,
|
|
5659
|
+
name: string,
|
|
5660
|
+
deploymentRevision: string | undefined,
|
|
5661
|
+
) {
|
|
5662
|
+
const queryClient = useQueryClient();
|
|
5663
|
+
const seen = useRef(deploymentRevision);
|
|
5664
|
+
|
|
5665
|
+
useEffect(() => {
|
|
5666
|
+
const previous = seen.current;
|
|
5667
|
+
seen.current = deploymentRevision;
|
|
5668
|
+
if (previous === undefined || deploymentRevision === undefined || previous === deploymentRevision) return;
|
|
5669
|
+
queryClient.invalidateQueries({
|
|
5670
|
+
queryKey: ["workload-revisions", kind, namespace, name],
|
|
5671
|
+
});
|
|
5672
|
+
}, [queryClient, kind, namespace, name, deploymentRevision]);
|
|
5673
|
+
}
|
|
5674
|
+
|
|
5675
|
+
// The server's paused-refusal text is written for API and agent callers; in the
|
|
5676
|
+
// UI the way out is the Resume rollout button on the same page.
|
|
5677
|
+
export function rollbackErrorMessage(body: { error?: string; error_code?: string }, status: number): string {
|
|
5678
|
+
if (body.error_code === "workload_paused") {
|
|
5679
|
+
return "This Deployment is paused. Click Resume rollout, then roll back.";
|
|
5680
|
+
}
|
|
5681
|
+
return body.error || `HTTP ${status}`;
|
|
5682
|
+
}
|
|
5683
|
+
|
|
5684
|
+
export function restartErrorMessage(body: { error?: string; error_code?: string }, status: number): string {
|
|
5685
|
+
if (body.error_code === "workload_paused") {
|
|
5686
|
+
return "This Deployment is paused. Click Resume rollout, then restart.";
|
|
5687
|
+
}
|
|
5688
|
+
return body.error || `HTTP ${status}`;
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5550
5691
|
export function useRollbackWorkload() {
|
|
5551
5692
|
const queryClient = useQueryClient();
|
|
5552
5693
|
return useMutation({
|
|
@@ -5570,8 +5711,7 @@ export function useRollbackWorkload() {
|
|
|
5570
5711
|
},
|
|
5571
5712
|
);
|
|
5572
5713
|
if (!response.ok) {
|
|
5573
|
-
|
|
5574
|
-
throw new Error(error.error || `HTTP ${response.status}`);
|
|
5714
|
+
throw new Error(rollbackErrorMessage(await readErrorBody(response), response.status));
|
|
5575
5715
|
}
|
|
5576
5716
|
return response.json();
|
|
5577
5717
|
},
|
|
@@ -6121,13 +6261,59 @@ function helmNamespaceParams(namespaces: string[] = []) {
|
|
|
6121
6261
|
return namespaces.length > 0 ? `?namespaces=${namespaces.join(",")}` : "";
|
|
6122
6262
|
}
|
|
6123
6263
|
|
|
6124
|
-
//
|
|
6125
|
-
|
|
6264
|
+
// Objects still loading clear on their own, so the list shouldn't wait for a
|
|
6265
|
+
// manual refresh to fill in. Some gaps outlast any quick retry, such as
|
|
6266
|
+
// permission checks spread over many namespaces, so polling slows rather than
|
|
6267
|
+
// repeating a full object read every few seconds.
|
|
6268
|
+
const HELM_INVENTORY_FAST_POLLS = 24;
|
|
6269
|
+
|
|
6270
|
+
export function helmInventoryRefetchInterval(inventory: Pick<HelmInventory, "objectCoverage"> | undefined, updates: number): number | false {
|
|
6271
|
+
const settling = inventory?.objectCoverage?.gaps.some((gap) => gap.action === "retry" || gap.action === "wait");
|
|
6272
|
+
if (!settling) return false;
|
|
6273
|
+
return updates < HELM_INVENTORY_FAST_POLLS ? 5000 : 60000;
|
|
6274
|
+
}
|
|
6275
|
+
|
|
6276
|
+
// The Helm list as far as the caller's access reaches. An older Radar has no
|
|
6277
|
+
// inventory route: its list is the whole answer, and a denial stays a 403.
|
|
6278
|
+
export function useHelmInventory(namespaces: string[] = []) {
|
|
6126
6279
|
const params = helmNamespaceParams(namespaces);
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6280
|
+
const { isPending: capabilitiesPending } = useCapabilities();
|
|
6281
|
+
const { support } = useRadarFeature("helmInventory");
|
|
6282
|
+
const hasInventory = support === "supported";
|
|
6283
|
+
return useQuery<HelmInventory>({
|
|
6284
|
+
queryKey: ["helm-releases", namespaces, hasInventory],
|
|
6285
|
+
queryFn: async () =>
|
|
6286
|
+
hasInventory
|
|
6287
|
+
? fetchJSON<HelmInventory>(`/helm/inventory${params}`)
|
|
6288
|
+
: { releases: await fetchJSON<HelmRelease[]>(`/helm/releases${params}`), observed: [] },
|
|
6289
|
+
enabled: !capabilitiesPending,
|
|
6130
6290
|
staleTime: 30000, // 30 seconds
|
|
6291
|
+
refetchInterval: (query) => helmInventoryRefetchInterval(query.state.data, query.state.dataUpdateCount),
|
|
6292
|
+
});
|
|
6293
|
+
}
|
|
6294
|
+
|
|
6295
|
+
// Kubernetes refused the caller's own read of Helm's storage. Other 403s on the
|
|
6296
|
+
// same route mean something else, and a Radar without inventory sends no code.
|
|
6297
|
+
export function isHelmReleaseReadDenied(error: unknown): boolean {
|
|
6298
|
+
return isForbiddenError(error) && (error as ApiError).data?.error_code === "release_read_denied";
|
|
6299
|
+
}
|
|
6300
|
+
|
|
6301
|
+
// Each observed read walks every object the caller can see, so an open drawer
|
|
6302
|
+
// follows the list's schedule while objects settle and otherwise refreshes
|
|
6303
|
+
// once a minute. A retryable error retries sooner.
|
|
6304
|
+
export function observedHelmReleaseRefetchInterval(detail: ObservedHelmReleaseDetail | undefined, updates: number, error: unknown): number | false {
|
|
6305
|
+
if (error) return isStableClientError(error) ? false : 15000
|
|
6306
|
+
return helmInventoryRefetchInterval(detail, updates) || 60000
|
|
6307
|
+
}
|
|
6308
|
+
|
|
6309
|
+
// One release built from the stamps on its objects, for a caller who can't read
|
|
6310
|
+
// Helm's storage.
|
|
6311
|
+
export function useObservedHelmRelease(namespace: string, name: string) {
|
|
6312
|
+
return useQuery<ObservedHelmReleaseDetail>({
|
|
6313
|
+
queryKey: ["helm-observed-release", namespace, name],
|
|
6314
|
+
queryFn: () => fetchJSON(`/helm/inventory/${namespace}/${name}`),
|
|
6315
|
+
staleTime: 5000,
|
|
6316
|
+
refetchInterval: (query) => observedHelmReleaseRefetchInterval(query.state.data, query.state.dataUpdateCount, query.state.error),
|
|
6131
6317
|
});
|
|
6132
6318
|
}
|
|
6133
6319
|
|
|
@@ -6142,7 +6328,9 @@ export function useHelmRelease(
|
|
|
6142
6328
|
queryFn: () => fetchJSON(`/helm/releases/${namespace}/${name}`),
|
|
6143
6329
|
enabled: Boolean(namespace && name) && (options?.enabled ?? true),
|
|
6144
6330
|
staleTime: 5000,
|
|
6145
|
-
|
|
6331
|
+
// Poll for live resource status updates (post-upgrade/rollback); a refusal
|
|
6332
|
+
// would only repeat.
|
|
6333
|
+
refetchInterval: (query) => (isForbiddenError(query.state.error) ? false : 10000),
|
|
6146
6334
|
});
|
|
6147
6335
|
}
|
|
6148
6336
|
|
|
@@ -7472,8 +7660,20 @@ export function useSwitchContext() {
|
|
|
7472
7660
|
// ============================================================================
|
|
7473
7661
|
|
|
7474
7662
|
export interface NamespaceScope {
|
|
7663
|
+
/**
|
|
7664
|
+
* This tab's pick. Outside --namespace-scope it is the tab's own (see
|
|
7665
|
+
* utils/namespacePick); the server's remembered pick only seeds it.
|
|
7666
|
+
*/
|
|
7475
7667
|
actives: string[];
|
|
7476
7668
|
kubeconfigNamespace: string;
|
|
7669
|
+
/** Context the scope was read under. Absent from servers older than per-tab picks. */
|
|
7670
|
+
context?: string;
|
|
7671
|
+
/**
|
|
7672
|
+
* True when the server drops its own pick to `accessibleNamespaces` on this
|
|
7673
|
+
* read; a tab drops its pick under the same rule. Absent from servers older
|
|
7674
|
+
* than per-tab picks.
|
|
7675
|
+
*/
|
|
7676
|
+
accessChecked?: boolean;
|
|
7477
7677
|
/**
|
|
7478
7678
|
* 'cluster-wide' — no per-user pick; user can list across namespaces.
|
|
7479
7679
|
* 'namespace' — per-user view filter pinned to one or more namespaces.
|
|
@@ -7497,7 +7697,11 @@ export interface NamespaceScope {
|
|
|
7497
7697
|
export function useNamespaceScope() {
|
|
7498
7698
|
return useQuery<NamespaceScope>({
|
|
7499
7699
|
queryKey: ["namespace-scope"],
|
|
7500
|
-
queryFn: () =>
|
|
7700
|
+
queryFn: async ({ signal }) => {
|
|
7701
|
+
const apiBase = getApiBase();
|
|
7702
|
+
const scope = await fetchJSON<NamespaceScope>("/cluster/namespace-scope", signal);
|
|
7703
|
+
return applyTabPick(scope, apiBase);
|
|
7704
|
+
},
|
|
7501
7705
|
staleTime: 30000,
|
|
7502
7706
|
});
|
|
7503
7707
|
}
|
|
@@ -7560,9 +7764,34 @@ export async function refreshAfterNamespaceSwitch(
|
|
|
7560
7764
|
await queryClient.invalidateQueries({ predicate: notScope }, { cancelRefetch: false });
|
|
7561
7765
|
}
|
|
7562
7766
|
|
|
7767
|
+
// Per apiBase, the last namespace switch this tab started, and the newest one
|
|
7768
|
+
// whose answer it applied. Answers can arrive out of order: an older switch
|
|
7769
|
+
// must not overwrite a newer one that already landed, but it still applies
|
|
7770
|
+
// while the newer one is in flight, in case that one is refused.
|
|
7771
|
+
const startedNamespaceSwitch = new Map<string, number>();
|
|
7772
|
+
const appliedNamespaceSwitch = new Map<string, number>();
|
|
7773
|
+
|
|
7774
|
+
export interface NamespaceSwitchStart {
|
|
7775
|
+
seq: number;
|
|
7776
|
+
apiBase: string;
|
|
7777
|
+
context: string | undefined;
|
|
7778
|
+
}
|
|
7779
|
+
|
|
7780
|
+
/** True while `start` is the newest namespace switch this tab has applied. */
|
|
7781
|
+
export function isAppliedNamespaceSwitch(start: NamespaceSwitchStart | undefined): boolean {
|
|
7782
|
+
return !start || appliedNamespaceSwitch.get(start.apiBase) === start.seq;
|
|
7783
|
+
}
|
|
7784
|
+
|
|
7785
|
+
/** Records `start` as applied unless a newer switch already landed. */
|
|
7786
|
+
function claimNamespaceSwitch(start: NamespaceSwitchStart): boolean {
|
|
7787
|
+
if (start.seq < (appliedNamespaceSwitch.get(start.apiBase) ?? 0)) return false;
|
|
7788
|
+
appliedNamespaceSwitch.set(start.apiBase, start.seq);
|
|
7789
|
+
return true;
|
|
7790
|
+
}
|
|
7791
|
+
|
|
7563
7792
|
export function useSetActiveNamespace() {
|
|
7564
7793
|
const queryClient = useQueryClient();
|
|
7565
|
-
return useMutation<NamespaceScope, Error, { namespaces: string[] }>({
|
|
7794
|
+
return useMutation<NamespaceScope, Error, { namespaces: string[] }, NamespaceSwitchStart>({
|
|
7566
7795
|
meta: {
|
|
7567
7796
|
// Surface 403s (RBAC drift, denied bookmark) and network errors via the
|
|
7568
7797
|
// global toast. Without this, App.tsx call sites that mutate without
|
|
@@ -7606,7 +7835,9 @@ export function useSetActiveNamespace() {
|
|
|
7606
7835
|
const error = await readErrorBody(response);
|
|
7607
7836
|
throw new Error(error.error || `HTTP ${response.status}`);
|
|
7608
7837
|
}
|
|
7609
|
-
|
|
7838
|
+
// Awaited so a body lost in transfer reaches the catch below.
|
|
7839
|
+
const scope: NamespaceScope = await response.json();
|
|
7840
|
+
return scope;
|
|
7610
7841
|
} catch (error) {
|
|
7611
7842
|
clearTimeout(timeoutId);
|
|
7612
7843
|
debugNamespaceLog("mutation:error", {
|
|
@@ -7629,10 +7860,45 @@ export function useSetActiveNamespace() {
|
|
|
7629
7860
|
{ cause: error },
|
|
7630
7861
|
);
|
|
7631
7862
|
}
|
|
7863
|
+
// A network failure can hide a write the server already made; its
|
|
7864
|
+
// scope says whether the pick landed. A refused pick (HTTP error) did
|
|
7865
|
+
// not land.
|
|
7866
|
+
if (!isRescope && error instanceof TypeError) {
|
|
7867
|
+
const applied = await reconcileNamespaceSwitch(namespaces);
|
|
7868
|
+
if (applied) {
|
|
7869
|
+
debugNamespaceLog("mutation:network-error-but-applied", { namespaces });
|
|
7870
|
+
return applied;
|
|
7871
|
+
}
|
|
7872
|
+
}
|
|
7632
7873
|
throw error;
|
|
7633
7874
|
}
|
|
7634
7875
|
},
|
|
7635
|
-
|
|
7876
|
+
onMutate: () => {
|
|
7877
|
+
const apiBase = getApiBase();
|
|
7878
|
+
const seq = (startedNamespaceSwitch.get(apiBase) ?? 0) + 1;
|
|
7879
|
+
startedNamespaceSwitch.set(apiBase, seq);
|
|
7880
|
+
const context = queryClient.getQueryData<NamespaceScope>(["namespace-scope"])?.context;
|
|
7881
|
+
return { seq, apiBase, context };
|
|
7882
|
+
},
|
|
7883
|
+
onSuccess: (response, { namespaces }, start) => {
|
|
7884
|
+
let scope = response;
|
|
7885
|
+
if (ownsTabPick(response)) {
|
|
7886
|
+
// The response renders the server's stored pick after the write, which
|
|
7887
|
+
// another tab can change in between, and its context is read after the
|
|
7888
|
+
// write too. Record what this tab asked for, under the context it
|
|
7889
|
+
// asked in.
|
|
7890
|
+
const context = start.context ?? response.context;
|
|
7891
|
+
const cached = queryClient.getQueryData<NamespaceScope>(["namespace-scope"]);
|
|
7892
|
+
// A context switch landed meanwhile: the tab starts again from the
|
|
7893
|
+
// server's pick for the new context.
|
|
7894
|
+
if (getApiBase() !== start.apiBase || (cached && cached.context !== context) || response.context !== context) return;
|
|
7895
|
+
if (!claimNamespaceSwitch(start)) return;
|
|
7896
|
+
const picked = pruneTabPick(response, cleanPick(namespaces));
|
|
7897
|
+
writeTabPick(start.apiBase, context, picked);
|
|
7898
|
+
scope = withActives(response, picked);
|
|
7899
|
+
} else {
|
|
7900
|
+
claimNamespaceSwitch(start);
|
|
7901
|
+
}
|
|
7636
7902
|
debugNamespaceLog("mutation:success-before-scope-cache-write", {
|
|
7637
7903
|
actives: scope.actives,
|
|
7638
7904
|
mode: scope.mode,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { ApiError, helmInventoryRefetchInterval, observedHelmReleaseRefetchInterval, useHelmInventory } from './client'
|
|
7
|
+
import type { HelmInventory, ObservedHelmReleaseDetail } from '../types'
|
|
8
|
+
|
|
9
|
+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
|
10
|
+
|
|
11
|
+
vi.mock('../context/ConnectionContext', () => ({ useClusterConnected: () => true, useConnection: () => ({ connection: { state: 'connected' } }) }))
|
|
12
|
+
|
|
13
|
+
type Seen = { data?: HelmInventory; error: unknown }
|
|
14
|
+
|
|
15
|
+
const json = (status: number, body: unknown) => new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } })
|
|
16
|
+
|
|
17
|
+
let root: Root | undefined
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
act(() => root?.unmount())
|
|
21
|
+
root = undefined
|
|
22
|
+
vi.unstubAllGlobals()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
async function readInventory(features: Record<string, boolean>, routes: Record<string, () => Response>) {
|
|
26
|
+
const paths: string[] = []
|
|
27
|
+
vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL) => {
|
|
28
|
+
const path = new URL(String(input), 'http://radar.test').pathname
|
|
29
|
+
paths.push(path)
|
|
30
|
+
if (path.endsWith('/capabilities')) return json(200, { features })
|
|
31
|
+
const route = Object.keys(routes).find((key) => path.endsWith(key))
|
|
32
|
+
return route ? routes[route]() : json(200, {})
|
|
33
|
+
}))
|
|
34
|
+
const seen: Seen = { error: null }
|
|
35
|
+
function Probe() {
|
|
36
|
+
const { data, error } = useHelmInventory([])
|
|
37
|
+
seen.data = data
|
|
38
|
+
seen.error = error
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
42
|
+
root = createRoot(document.createElement('div'))
|
|
43
|
+
await act(async () => {
|
|
44
|
+
root!.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>)
|
|
45
|
+
})
|
|
46
|
+
await vi.waitFor(() => expect(seen.data !== undefined || seen.error !== null).toBe(true))
|
|
47
|
+
return { seen, paths }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('useHelmInventory', () => {
|
|
51
|
+
it('reads the inventory from a Radar that advertises it', async () => {
|
|
52
|
+
const inventory: HelmInventory = { releases: [], observed: [{ name: 'api', namespace: 'apps', resourceCount: 1 }], storageDenied: { extent: 'all' } }
|
|
53
|
+
const { seen, paths } = await readInventory({ helmInventory: true }, { '/helm/inventory': () => json(200, inventory) })
|
|
54
|
+
expect(seen.data).toEqual(inventory)
|
|
55
|
+
expect(paths.some((path) => path.endsWith('/helm/releases'))).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('reads the release list from an older Radar, which is the whole answer', async () => {
|
|
59
|
+
const release = { name: 'api', namespace: 'apps', chart: 'c', chartVersion: '1', appVersion: '1', status: 'deployed', revision: 1, updated: '2026-01-01T00:00:00Z' }
|
|
60
|
+
const { seen, paths } = await readInventory({}, { '/helm/releases': () => json(200, [release]) })
|
|
61
|
+
expect(seen.data).toEqual({ releases: [release], observed: [] })
|
|
62
|
+
expect(paths.some((path) => path.includes('/helm/inventory'))).toBe(false)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('keeps an older Radar’s denial an error', async () => {
|
|
66
|
+
const { seen } = await readInventory({}, { '/helm/releases': () => json(403, { error: 'insufficient permissions to list Helm releases' }) })
|
|
67
|
+
expect(seen.data).toBeUndefined()
|
|
68
|
+
expect((seen.error as { status?: number }).status).toBe(403)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('helmInventoryRefetchInterval', () => {
|
|
73
|
+
const withGap = (action: string): HelmInventory => ({ releases: [], observed: [], objectCoverage: { gaps: [{ code: 'x', action }] } as unknown as HelmInventory['objectCoverage'] })
|
|
74
|
+
|
|
75
|
+
it('leaves a settled list alone', () => {
|
|
76
|
+
expect(helmInventoryRefetchInterval(undefined, 0)).toBe(false)
|
|
77
|
+
expect(helmInventoryRefetchInterval({}, 0)).toBe(false)
|
|
78
|
+
expect(helmInventoryRefetchInterval(withGap('grant_access'), 0)).toBe(false)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('follows both gaps that can clear by themselves', () => {
|
|
82
|
+
expect(helmInventoryRefetchInterval(withGap('retry'), 0)).toBe(5000)
|
|
83
|
+
expect(helmInventoryRefetchInterval(withGap('wait'), 0)).toBe(5000)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('slows down, without stopping, once a gap outlasts the quick retries', () => {
|
|
87
|
+
expect(helmInventoryRefetchInterval(withGap('retry'), 24)).toBe(60000)
|
|
88
|
+
expect(helmInventoryRefetchInterval(withGap('wait'), 500)).toBe(60000)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('observedHelmReleaseRefetchInterval', () => {
|
|
93
|
+
const detail = (action?: string) =>
|
|
94
|
+
({ name: 'web', namespace: 'apps', resourceCount: 1, objectCoverage: { gaps: action ? [{ code: 'x', action }] : [] } }) as unknown as ObservedHelmReleaseDetail
|
|
95
|
+
|
|
96
|
+
it('rereads a settled drawer only once a minute, since each read walks every object', () => {
|
|
97
|
+
expect(observedHelmReleaseRefetchInterval(detail(), 3, null)).toBe(60000)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('follows the list while objects settle', () => {
|
|
101
|
+
expect(observedHelmReleaseRefetchInterval(detail('retry'), 0, null)).toBe(5000)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('retries a retryable error and stops on a stable one', () => {
|
|
105
|
+
expect(observedHelmReleaseRefetchInterval(undefined, 0, new ApiError('busy', 503))).toBe(15000)
|
|
106
|
+
expect(observedHelmReleaseRefetchInterval(undefined, 0, new ApiError('gone', 404))).toBe(false)
|
|
107
|
+
})
|
|
108
|
+
})
|