@skyhook-io/radar-app 1.21.6 → 1.21.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -4
- package/src/RadarApp.tsx +8 -2
- package/src/api/client.discoverMetrics.test.tsx +69 -0
- package/src/api/client.issueCorrelation.test.tsx +244 -0
- package/src/api/client.issueRowChanges.test.tsx +129 -0
- package/src/api/client.pendingOwnership.test.tsx +197 -0
- package/src/api/client.prometheusStatus.test.ts +4 -0
- package/src/api/client.restartError.test.ts +36 -1
- package/src/api/client.stopWorkflow.test.tsx +133 -0
- package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
- package/src/api/client.ts +582 -114
- package/src/api/connectionBinding.test.tsx +3 -1
- package/src/api/connectionBinding.ts +14 -2
- package/src/api/gitOpsPermissions.render.test.tsx +155 -0
- package/src/api/gitOpsPermissions.test.ts +90 -0
- package/src/api/gitOpsPermissions.ts +51 -0
- package/src/api/httpErrors.test.ts +30 -1
- package/src/api/httpErrors.ts +17 -0
- package/src/api/openobserveSetup.ts +85 -0
- package/src/api/podDebug.test.tsx +137 -0
- package/src/api/podDebug.ts +82 -0
- package/src/api/prometheusCharts.test.ts +23 -0
- package/src/api/prometheusCharts.ts +25 -0
- package/src/api/radarFeatures.render.test.tsx +43 -2
- package/src/api/radarFeatures.test.ts +18 -1
- package/src/api/radarFeatures.ts +17 -4
- package/src/api/reviewedActionMutation.ts +9 -2
- package/src/api/workloadMetrics.ts +2 -0
- package/src/components/NamespaceSwitcher.tsx +6 -2
- package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +127 -173
- package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
- package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
- package/src/components/cnpg/host.test.tsx +1 -1
- package/src/components/cnpg/host.tsx +0 -2
- package/src/components/dock/BottomDock.tsx +7 -3
- package/src/components/dock/MissingShellDebug.test.tsx +193 -0
- package/src/components/dock/MissingShellDebug.tsx +114 -0
- package/src/components/dock/PodDebugSession.test.tsx +60 -0
- package/src/components/dock/PodDebugSession.tsx +96 -0
- package/src/components/dock/TerminalTab.test.tsx +48 -4
- package/src/components/dock/TerminalTab.tsx +47 -25
- package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
- package/src/components/dock/WorkloadLogsTab.tsx +16 -0
- package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
- package/src/components/execution/BatchExecutionView.tsx +88 -5
- package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
- package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
- package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
- package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
- package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
- package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
- package/src/components/gitops/GitOpsView.tsx +93 -32
- package/src/components/helm/OwnedResources.tsx +1 -0
- package/src/components/home/HomeView.tsx +9 -1
- package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +78 -2
- package/src/components/issues/IssuesPane.tsx +49 -6
- package/src/components/issues/useIssueExpansion.ts +91 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
- package/src/components/resource/MetricsNotConnected.tsx +114 -0
- package/src/components/resource/PVCUsageBar.tsx +2 -1
- package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
- package/src/components/resource/PrometheusCharts.tsx +14 -2
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
- package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
- package/src/components/resource/RestartChart.tsx +4 -3
- package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
- package/src/components/resource/RightsizingStrip.tsx +5 -3
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
- package/src/components/resource/nameMatchedScope.ts +9 -3
- package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
- package/src/components/resources/PodDebugAction.test.tsx +157 -0
- package/src/components/resources/PodDebugAction.tsx +207 -0
- package/src/components/resources/PodDebugPermission.tsx +21 -0
- package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
- package/src/components/resources/ResourcesView.tsx +39 -5
- package/src/components/resources/namespaceHint.test.ts +34 -0
- package/src/components/resources/namespaceHint.ts +19 -0
- package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
- package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +12 -5
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
- package/src/components/settings/FormSaveActions.tsx +6 -2
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +165 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +384 -0
- package/src/components/settings/OpenObserveSetup.tsx +328 -0
- package/src/components/settings/SettingsDialog.tsx +21 -7
- package/src/components/settings/openobserveStatus.test.ts +34 -0
- package/src/components/settings/openobserveStatus.ts +55 -0
- package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
- package/src/components/timeline/TimelineList.test.ts +18 -0
- package/src/components/timeline/TimelineList.tsx +19 -5
- package/src/components/timeline/TimelineView.tsx +2 -0
- package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
- package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +103 -16
- package/src/components/workspace/WorkspaceConditions.tsx +56 -0
- package/src/components/workspace/layout.test.tsx +20 -0
- package/src/components/workspace/layout.tsx +1 -1
- package/src/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +5 -1
- package/src/hooks/useResourceCounts.ts +2 -1
- package/src/hooks/useWorkflowStopAction.ts +31 -0
- package/src/index.css +1 -0
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -2
- package/src/k8s-ui-exports.test.ts +10 -0
- package/src/utils/page-links.ts +15 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
package/src/api/client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasPrometheusCharts, metricsSourceUnavailable } from './prometheusCharts'
|
|
1
2
|
import type { RightsizingRow, WorkloadRightsizingEvidence } from '@skyhook-io/k8s-ui/types/rightsizing'
|
|
2
3
|
import { followSwitch, switchFinished, switchInProgress, type ContextSwitchOperation } from './contextSwitch'
|
|
3
4
|
import { createListRefetchInterval, normalizeResourceList, type ResourceListBody, type ResourceListResult } from './resourceLists'
|
|
@@ -8,8 +9,8 @@ import type { ReadGap, ReadGapSet } from '@skyhook-io/k8s-ui/types/read-coverage
|
|
|
8
9
|
import type { ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
|
|
9
10
|
import type { WorkloadHistoryCoverage } from '@skyhook-io/k8s-ui/utils/workload-history-notes'
|
|
10
11
|
import { knownKindForPluralWithGroup, pluralToKind } from '@skyhook-io/k8s-ui/utils/navigation'
|
|
11
|
-
import { useEffect, useRef, useCallback, useMemo } from 'react'
|
|
12
|
-
import { argoSyncOptionsForRequest } from '@skyhook-io/k8s-ui'
|
|
12
|
+
import { useEffect, useRef, useCallback, useMemo, useState } from 'react'
|
|
13
|
+
import { argoSyncOptionsForRequest, issueOccurrence, issueRowKey, type IssueRowChange } from '@skyhook-io/k8s-ui'
|
|
13
14
|
import { useClusterConnected } from '../context/clusterConnected'
|
|
14
15
|
import type { KueueAdmissionResponse, KueuePositionResponse } from '@skyhook-io/k8s-ui/types/scheduling'
|
|
15
16
|
import type { KueueQueueMembership, KueueQueueWorkloadsResponse } from '@skyhook-io/k8s-ui/types/kueue-queues'
|
|
@@ -17,6 +18,7 @@ import { kueueQueueRetryable } from '@skyhook-io/k8s-ui/utils/kueue-queue-worklo
|
|
|
17
18
|
import { canonicalReadCode, readActionFor } from '@skyhook-io/k8s-ui/utils/read-actions'
|
|
18
19
|
import type { SearchCoverage } from '@skyhook-io/k8s-ui/types/read-coverage'
|
|
19
20
|
import type { GitOpsWriteEvidence } from '@skyhook-io/k8s-ui/utils/gitops-write-guard'
|
|
21
|
+
import { isAmbiguousSubmitError, type SubmittedWorkflow, type WorkflowTemplateSubmission } from '@skyhook-io/k8s-ui/utils/workflow-template-submit'
|
|
20
22
|
import type {
|
|
21
23
|
AppHistory,
|
|
22
24
|
AppRow,
|
|
@@ -36,10 +38,11 @@ import type {
|
|
|
36
38
|
YamlDocumentIdentity,
|
|
37
39
|
YamlSchemaLoadResult,
|
|
38
40
|
} from '@skyhook-io/k8s-ui'
|
|
39
|
-
import { focusManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
41
|
+
import { focusManager, onlineManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
40
42
|
import { showApiError, showApiSuccess, showApiNotice } from '../components/ui/Toast'
|
|
41
43
|
import { useIsAuthEnabled, useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
|
|
42
44
|
import { applyTabPick, cleanPick, ownsTabPick, pruneTabPick, withActives, writeTabPick } from '../utils/namespacePick'
|
|
45
|
+
import { parseContextName } from '../utils/context-name'
|
|
43
46
|
import type {
|
|
44
47
|
Topology,
|
|
45
48
|
ClusterInfo,
|
|
@@ -81,9 +84,10 @@ import type {
|
|
|
81
84
|
} from '../types'
|
|
82
85
|
import type { GitOpsOperationResponse } from '../types/gitops'
|
|
83
86
|
import { apiUrl, automaticRequestHeaders, getApiBase, getAuthHeaders, getCredentialsMode, getBasename, routePath, stripBasename } from './config'
|
|
84
|
-
import { CONNECTION_HEADER, connectionHeaderValue } from './connectionBinding'
|
|
85
|
-
import { httpStatusMessage, markShownInline, readErrorBody, readErrorResponse } from './httpErrors'
|
|
87
|
+
import { CONNECTION_HEADER, connectionHeaderValue, useCurrentConnectionId } from './connectionBinding'
|
|
88
|
+
import { GitOpsActionError, httpStatusMessage, markShownInline, readErrorBody, readErrorResponse } from './httpErrors'
|
|
86
89
|
import {
|
|
90
|
+
isRadarFeatureUnsupported,
|
|
87
91
|
RadarFeatureUnsupportedError,
|
|
88
92
|
guardRadarFeature,
|
|
89
93
|
radarControlBlocked,
|
|
@@ -94,6 +98,7 @@ import {
|
|
|
94
98
|
type RadarFeature,
|
|
95
99
|
} from './radarFeatures'
|
|
96
100
|
import { useRadarUpgradeHost } from '../context/RadarUpgradeHost'
|
|
101
|
+
import { isGitOpsActionTarget, gitOpsActionPermissions, gitOpsDisabledReasons, type GitOpsActionCapabilities } from './gitOpsPermissions'
|
|
97
102
|
import { apiVersionToGroup } from '../utils/navigation'
|
|
98
103
|
import { isBadgeWorthy } from '../utils/auditBadges'
|
|
99
104
|
import type { DeploymentMode } from '../types'
|
|
@@ -854,7 +859,8 @@ export interface IssuesResponse {
|
|
|
854
859
|
recent_changes_guidance?: string
|
|
855
860
|
recent_changes_truncated?: boolean
|
|
856
861
|
// Present when the recent-changes window starts before the history Radar
|
|
857
|
-
// holds; complete_since is sent only to callers
|
|
862
|
+
// holds; when events were evicted, complete_since is sent only to callers
|
|
863
|
+
// who can read every namespace.
|
|
858
864
|
recent_changes_history_coverage?: {
|
|
859
865
|
incomplete: boolean
|
|
860
866
|
complete_since?: string
|
|
@@ -1049,6 +1055,100 @@ export function useSubjectIssues(
|
|
|
1049
1055
|
});
|
|
1050
1056
|
}
|
|
1051
1057
|
|
|
1058
|
+
export interface CorrelatedIssuesResponse extends SubjectIssuesResponse {
|
|
1059
|
+
/** Set when the correlated issue isn't in this answer. not_found: resolved,
|
|
1060
|
+
* or outside what the caller may see. user_forbidden / read_error: a native
|
|
1061
|
+
* Helm release whose storage read, which serves both the issue and its
|
|
1062
|
+
* history, was refused or failed. */
|
|
1063
|
+
correlation_status?: 'not_found' | 'user_forbidden' | 'read_error';
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
const ISSUE_CORRELATION_REFRESH_INTERVAL_MS = 60_000;
|
|
1067
|
+
|
|
1068
|
+
// One issue's recent changes: the per-resource lookup for the issue's subject,
|
|
1069
|
+
// with ?correlate=<id> so Radar correlates that issue only and returns it with
|
|
1070
|
+
// its timing corrected. Hosts enable it for the open row only. An older Radar
|
|
1071
|
+
// ignores the parameter rather than failing, so the request waits for
|
|
1072
|
+
// capabilities and is sent only when the flag says the server reads it.
|
|
1073
|
+
export function useIssueCorrelation(issue: Issue | null, enabled: boolean) {
|
|
1074
|
+
const capabilities = useCapabilities();
|
|
1075
|
+
const { gatedKey, guard } = useRadarFeature('issueCorrelation');
|
|
1076
|
+
const pathNs = issue?.namespace ? encodeURIComponent(issue.namespace) : "_";
|
|
1077
|
+
const params = new URLSearchParams({ coverage: "1" });
|
|
1078
|
+
if (issue?.group) params.set("group", issue.group);
|
|
1079
|
+
if (issue) params.set("correlate", issue.id);
|
|
1080
|
+
return useQuery<CorrelatedIssuesResponse>({
|
|
1081
|
+
// The occurrence is in the key: an issue's id survives recurrence, and a
|
|
1082
|
+
// cached answer for the earlier occurrence would describe the wrong window.
|
|
1083
|
+
queryKey: ["issues", "correlation", issue?.kind ?? "", issue?.group ?? "", issue?.namespace ?? "", issue?.name ?? "", issue?.id ?? "", issue ? issueOccurrence(issue) : "", ...gatedKey],
|
|
1084
|
+
queryFn: () => {
|
|
1085
|
+
if (!capabilities.data && capabilities.error) throw capabilities.error;
|
|
1086
|
+
return guard(() => fetchJSON<CorrelatedIssuesResponse>(`/issues/resource/${encodeURIComponent(issue!.kind)}/${pathNs}/${encodeURIComponent(issue!.name)}?${params}`));
|
|
1087
|
+
},
|
|
1088
|
+
retry: shouldRetryRadarQuery,
|
|
1089
|
+
staleTime: 30000,
|
|
1090
|
+
refetchInterval: (q) => q.state.error instanceof RadarFeatureUnsupportedError ? false : ISSUE_CORRELATION_REFRESH_INTERVAL_MS,
|
|
1091
|
+
refetchIntervalInBackground: false,
|
|
1092
|
+
enabled: enabled && !!issue && !capabilities.isPending,
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
export interface IssueRecentChangesResponse {
|
|
1097
|
+
/** Per issue id, the one change its row names. An issue with nothing to
|
|
1098
|
+
* name is absent, whatever the reason; absence is never "no changes". */
|
|
1099
|
+
changes: Record<string, IssueRowChange>;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/** The server's cap on issues per batched row lookup. */
|
|
1103
|
+
export const ISSUE_ROW_CHANGES_MAX = 50;
|
|
1104
|
+
|
|
1105
|
+
/** One issue= value: <id>/<kind>/<namespace>/<name>[/<group>], "_" for a
|
|
1106
|
+
* cluster-scoped subject's namespace. */
|
|
1107
|
+
export function issueRowChangeParam(issue: Issue): string {
|
|
1108
|
+
const value = [issue.id, issue.kind, issue.namespace || "_", issue.name].map(encodeURIComponent).join("/");
|
|
1109
|
+
return issue.group ? `${value}/${encodeURIComponent(issue.group)}` : value;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// The one change each issue row on screen names, from one batched lookup
|
|
1113
|
+
// (GET /api/issues/recent-changes), polled like an open issue's recent
|
|
1114
|
+
// changes. Like the per-issue correlation, it waits for capabilities and goes
|
|
1115
|
+
// out only when the server advertises issueCorrelation. The previous answer
|
|
1116
|
+
// stays while a new set of rows loads, so rows on screen before and after a
|
|
1117
|
+
// scroll keep their note. Keyed by issueRowKey.
|
|
1118
|
+
export function useIssueRowChanges(issues: Issue[]): ReadonlyMap<string, IssueRowChange> | undefined {
|
|
1119
|
+
const capabilities = useCapabilities();
|
|
1120
|
+
const { gatedKey, guard, support } = useRadarFeature('issueCorrelation');
|
|
1121
|
+
const rows = useMemo(() => issues.slice(0, ISSUE_ROW_CHANGES_MAX), [issues]);
|
|
1122
|
+
const params = useMemo(() => {
|
|
1123
|
+
const p = new URLSearchParams();
|
|
1124
|
+
for (const issue of rows) p.append("issue", issueRowChangeParam(issue));
|
|
1125
|
+
return p.toString();
|
|
1126
|
+
}, [rows]);
|
|
1127
|
+
const query = useQuery<IssueRecentChangesResponse>({
|
|
1128
|
+
queryKey: ["issues", "row-changes", params, ...gatedKey],
|
|
1129
|
+
queryFn: () => {
|
|
1130
|
+
if (!capabilities.data && capabilities.error) throw capabilities.error;
|
|
1131
|
+
return guard(() => fetchJSON<IssueRecentChangesResponse>(`/issues/recent-changes?${params}`));
|
|
1132
|
+
},
|
|
1133
|
+
retry: shouldRetryRadarQuery,
|
|
1134
|
+
staleTime: 30000,
|
|
1135
|
+
placeholderData: (previous) => previous,
|
|
1136
|
+
refetchInterval: (q) => q.state.error instanceof RadarFeatureUnsupportedError ? false : ISSUE_CORRELATION_REFRESH_INTERVAL_MS,
|
|
1137
|
+
refetchIntervalInBackground: false,
|
|
1138
|
+
enabled: rows.length > 0 && !capabilities.isPending && support !== "unsupported",
|
|
1139
|
+
});
|
|
1140
|
+
const changes = query.data?.changes;
|
|
1141
|
+
return useMemo(() => {
|
|
1142
|
+
if (!changes || rows.length === 0) return undefined;
|
|
1143
|
+
const out = new Map<string, IssueRowChange>();
|
|
1144
|
+
for (const issue of rows) {
|
|
1145
|
+
const change = changes[issue.id];
|
|
1146
|
+
if (change) out.set(issueRowKey(issue), change);
|
|
1147
|
+
}
|
|
1148
|
+
return out;
|
|
1149
|
+
}, [changes, rows]);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1052
1152
|
import type { Trace as NetworkTrace, InClusterCapability, DrainPlan, DrainPlanPod } from '@skyhook-io/k8s-ui'
|
|
1053
1153
|
|
|
1054
1154
|
// useTrace polls the static path-shaped diagnosis for one network entry
|
|
@@ -1940,6 +2040,11 @@ export function useClusterInfo() {
|
|
|
1940
2040
|
return query;
|
|
1941
2041
|
}
|
|
1942
2042
|
|
|
2043
|
+
function cachedContextName(queryClient: QueryClient): string | undefined {
|
|
2044
|
+
return queryClient.getQueryData<ClusterInfo>(["cluster-info"])?.context
|
|
2045
|
+
?? queryClient.getQueryData<{ context: string }>(["connection-status"])?.context;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
1943
2048
|
// Version check
|
|
1944
2049
|
export type InstallMethod =
|
|
1945
2050
|
"homebrew" | "krew" | "scoop" | "direct" | "desktop";
|
|
@@ -2065,13 +2170,10 @@ export function useVersionCheck() {
|
|
|
2065
2170
|
|
|
2066
2171
|
/**
|
|
2067
2172
|
* Guards a fetch for an endpoint the connected Radar may predate (see
|
|
2068
|
-
* radarFeatures.ts).
|
|
2069
|
-
*
|
|
2070
|
-
*
|
|
2071
|
-
* sections render as an upgrade note
|
|
2072
|
-
*
|
|
2073
|
-
* Nothing waits on /version-check: an agent that advertises the feature flag
|
|
2074
|
-
* is fetched immediately, and an unknown version falls through to the fetch.
|
|
2173
|
+
* radarFeatures.ts). Features requiring affirmative support wait for the
|
|
2174
|
+
* flag. Others can probe while support is unknown. A known-old version or
|
|
2175
|
+
* an unknown-route 404 from a probe raises RadarFeatureUnsupportedError,
|
|
2176
|
+
* which sections render as an upgrade note.
|
|
2075
2177
|
*
|
|
2076
2178
|
* Spread `gatedKey` into the query key. A gate decided from early information
|
|
2077
2179
|
* (a host-supplied version before /capabilities answers) can lift later, and
|
|
@@ -2776,6 +2878,12 @@ export function useTopology(
|
|
|
2776
2878
|
});
|
|
2777
2879
|
}
|
|
2778
2880
|
|
|
2881
|
+
interface ApplicationsResponse {
|
|
2882
|
+
applications: AppRow[];
|
|
2883
|
+
/** Absent when Radar could not establish inventory coverage. */
|
|
2884
|
+
access?: { restricted: boolean };
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2779
2887
|
export function useApplications(
|
|
2780
2888
|
namespaces: string[],
|
|
2781
2889
|
options?: { enabled?: boolean },
|
|
@@ -2786,11 +2894,11 @@ export function useApplications(
|
|
|
2786
2894
|
|
|
2787
2895
|
const enabled = options?.enabled !== false;
|
|
2788
2896
|
const { guard, gatedKey } = useRadarFeature("applications");
|
|
2789
|
-
return useQuery<
|
|
2897
|
+
return useQuery<ApplicationsResponse>({
|
|
2790
2898
|
queryKey: ["applications", namespaces, ...gatedKey],
|
|
2791
2899
|
queryFn: () =>
|
|
2792
2900
|
guard(() =>
|
|
2793
|
-
fetchJSON<
|
|
2901
|
+
fetchJSON<ApplicationsResponse>(
|
|
2794
2902
|
`/applications${queryString ? `?${queryString}` : ""}`,
|
|
2795
2903
|
),
|
|
2796
2904
|
),
|
|
@@ -3210,29 +3318,90 @@ export function useResourceAvailability(kind: string, namespace: string, name: s
|
|
|
3210
3318
|
});
|
|
3211
3319
|
}
|
|
3212
3320
|
|
|
3321
|
+
function hasPendingOwnership(data?: ResourceWithRelationships): boolean {
|
|
3322
|
+
const coverage = data?.relationships?.ownership;
|
|
3323
|
+
if (!coverage) return false;
|
|
3324
|
+
const pending = "kind_sync_pending";
|
|
3325
|
+
return coverage.unavailableReason === pending ||
|
|
3326
|
+
coverage.ownerReason === pending ||
|
|
3327
|
+
coverage.manager?.stop?.reason === pending ||
|
|
3328
|
+
coverage.manages?.unavailableReason === pending ||
|
|
3329
|
+
!!coverage.managers?.notChecked?.some(gap => gap.reason === pending) ||
|
|
3330
|
+
!!coverage.children?.notChecked?.some(gap => gap.reason === pending);
|
|
3331
|
+
}
|
|
3332
|
+
|
|
3213
3333
|
// Hook that returns full response with relationships explicitly
|
|
3214
3334
|
export function useResourceWithRelationships<T>(
|
|
3215
3335
|
kind: string,
|
|
3216
3336
|
namespace: string,
|
|
3217
3337
|
name: string,
|
|
3218
3338
|
group?: string,
|
|
3219
|
-
options?: { cacheScope?: string },
|
|
3339
|
+
options?: { cacheScope?: string; pollPendingOwnership?: boolean },
|
|
3220
3340
|
) {
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3341
|
+
const client = useQueryClient();
|
|
3342
|
+
const cacheScope = options?.cacheScope;
|
|
3343
|
+
const resourceOptions = useMemo(
|
|
3344
|
+
() => resourceQueryOptions<T>(kind, namespace, name, group, { cacheScope }),
|
|
3345
|
+
[kind, namespace, name, group, cacheScope],
|
|
3346
|
+
);
|
|
3347
|
+
const query = useQuery<ResourceWithRelationships<T>>({ ...resourceOptions, refetchIntervalInBackground: false });
|
|
3348
|
+
const { refetch } = query;
|
|
3349
|
+
const poll = options?.pollPendingOwnership;
|
|
3350
|
+
const apiBase = getApiBase();
|
|
3351
|
+
|
|
3352
|
+
useEffect(() => {
|
|
3353
|
+
if (!poll || !resourceOptions.enabled) return;
|
|
3354
|
+
const cache = client.getQueryCache();
|
|
3355
|
+
const { queryHash } = client.defaultQueryOptions(resourceOptions);
|
|
3356
|
+
let attempts = 0;
|
|
3357
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
3358
|
+
|
|
3359
|
+
function schedule() {
|
|
3360
|
+
clearTimeout(timer);
|
|
3361
|
+
timer = undefined;
|
|
3362
|
+
const state = cache.get<ResourceWithRelationships<T>>(queryHash)?.state;
|
|
3363
|
+
if (!state || state.error || !hasPendingOwnership(state.data)) {
|
|
3364
|
+
attempts = 0;
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
// A hidden or offline view waits without timers; focus and reconnect
|
|
3368
|
+
// resume it below.
|
|
3369
|
+
if (!focusManager.isFocused() || !onlineManager.isOnline()) return;
|
|
3370
|
+
if (state.fetchStatus !== "idle" || attempts >= 8) return;
|
|
3371
|
+
timer = setTimeout(() => {
|
|
3372
|
+
timer = undefined;
|
|
3373
|
+
if (apiBase !== getApiBase()) return;
|
|
3374
|
+
attempts++;
|
|
3375
|
+
void refetch({ cancelRefetch: false });
|
|
3376
|
+
}, Math.min(5000 * 2 ** attempts, 30_000));
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
// Other observers and SSE can change this answer, including after the last
|
|
3380
|
+
// poll. Only this view's timer spends attempts; a settled answer resets them.
|
|
3381
|
+
const unsubscribe = cache.subscribe(event => {
|
|
3382
|
+
if ((event.type === "updated" || event.type === "removed") && event.query.queryHash === queryHash) schedule();
|
|
3383
|
+
});
|
|
3384
|
+
// Redundant focus or online events must not restart a running countdown.
|
|
3385
|
+
const resume = () => {
|
|
3386
|
+
if (!focusManager.isFocused() || !onlineManager.isOnline()) {
|
|
3387
|
+
clearTimeout(timer);
|
|
3388
|
+
timer = undefined;
|
|
3389
|
+
} else if (timer === undefined) {
|
|
3390
|
+
schedule();
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
const unsubscribeFocus = focusManager.subscribe(resume);
|
|
3394
|
+
const unsubscribeOnline = onlineManager.subscribe(resume);
|
|
3395
|
+
schedule();
|
|
3396
|
+
return () => {
|
|
3397
|
+
unsubscribe();
|
|
3398
|
+
unsubscribeFocus();
|
|
3399
|
+
unsubscribeOnline();
|
|
3400
|
+
clearTimeout(timer);
|
|
3401
|
+
};
|
|
3402
|
+
}, [poll, apiBase, client, resourceOptions, refetch]);
|
|
3403
|
+
|
|
3404
|
+
return query;
|
|
3236
3405
|
}
|
|
3237
3406
|
|
|
3238
3407
|
export interface ResourceListOptions {
|
|
@@ -4033,6 +4202,7 @@ export function useTopNodeMetrics(options?: { enabled?: boolean }) {
|
|
|
4033
4202
|
|
|
4034
4203
|
// Prometheus types
|
|
4035
4204
|
export interface PrometheusStatus {
|
|
4205
|
+
gkeSystemMetrics?: boolean;
|
|
4036
4206
|
available: boolean;
|
|
4037
4207
|
connected: boolean;
|
|
4038
4208
|
/** A discovery run is in flight for the current configuration. Never true alongside connected. */
|
|
@@ -4046,6 +4216,30 @@ export interface PrometheusStatus {
|
|
|
4046
4216
|
};
|
|
4047
4217
|
contextName?: string;
|
|
4048
4218
|
error?: string;
|
|
4219
|
+
/** Set when metrics come from a backend other than plain Prometheus. */
|
|
4220
|
+
source?: MetricsSource;
|
|
4221
|
+
/** How this install can get OpenObserve metrics: Radar Hub selects the source, or local Settings → Metrics. */
|
|
4222
|
+
openobserve?: "hub" | "local";
|
|
4223
|
+
}
|
|
4224
|
+
|
|
4225
|
+
/**
|
|
4226
|
+
* Where metrics come from when not a plain Prometheus. With `matchedBy`
|
|
4227
|
+
* unset and `unavailable` false, the source is not serving this context and
|
|
4228
|
+
* `error`/`warning` explain why (the cluster's own Prometheus, if any, serves).
|
|
4229
|
+
*/
|
|
4230
|
+
export interface MetricsSource {
|
|
4231
|
+
kind: "openobserve";
|
|
4232
|
+
via?: "local" | "hub";
|
|
4233
|
+
matchedBy?: "id" | "name";
|
|
4234
|
+
clusterLabel?: { name: string; value: string };
|
|
4235
|
+
dialect?: "standard" | "collector";
|
|
4236
|
+
warning?: string;
|
|
4237
|
+
versionWarning?: string;
|
|
4238
|
+
missingFamilies?: string[];
|
|
4239
|
+
unavailable?: boolean;
|
|
4240
|
+
/** The match is still running; poll until it settles. */
|
|
4241
|
+
pending?: boolean;
|
|
4242
|
+
error?: string;
|
|
4049
4243
|
}
|
|
4050
4244
|
|
|
4051
4245
|
// Time-series sample types live in @skyhook-io/k8s-ui (shared with library
|
|
@@ -4066,6 +4260,7 @@ export interface PrometheusQueryResult {
|
|
|
4066
4260
|
}
|
|
4067
4261
|
|
|
4068
4262
|
export interface PrometheusResourceMetrics {
|
|
4263
|
+
source?: "gke";
|
|
4069
4264
|
kind: string;
|
|
4070
4265
|
namespace?: string;
|
|
4071
4266
|
name: string;
|
|
@@ -4165,8 +4360,8 @@ export function prometheusStatusRefetchInterval(
|
|
|
4165
4360
|
status: PrometheusStatus | undefined,
|
|
4166
4361
|
): number {
|
|
4167
4362
|
if (!status) return PROM_STATUS_POLL_IDLE_MS;
|
|
4168
|
-
const settled = status
|
|
4169
|
-
return status.discovering || !settled
|
|
4363
|
+
const settled = hasPrometheusCharts(status) || !!status.error;
|
|
4364
|
+
return status.discovering || !settled || status.source?.pending
|
|
4170
4365
|
? PROM_STATUS_POLL_DISCOVERING_MS
|
|
4171
4366
|
: PROM_STATUS_POLL_IDLE_MS;
|
|
4172
4367
|
}
|
|
@@ -4235,6 +4430,39 @@ export function usePrometheusConnect() {
|
|
|
4235
4430
|
});
|
|
4236
4431
|
}
|
|
4237
4432
|
|
|
4433
|
+
export type MetricsDiscoveryOutcome = "connected" | "collector" | "none";
|
|
4434
|
+
|
|
4435
|
+
// Discover metrics on an install that can also read OpenObserve. The connect
|
|
4436
|
+
// call asks Radar Hub for the source first (when connected to it), then looks
|
|
4437
|
+
// for Prometheus; with nothing found, it reports whether an OpenObserve
|
|
4438
|
+
// collector runs. The outcome and any failure are shown in place, so there
|
|
4439
|
+
// are no toasts. A 502 means discovery found no usable Prometheus, whose
|
|
4440
|
+
// reason the status error then shows; any other failure ends discovery.
|
|
4441
|
+
export function useDiscoverMetrics() {
|
|
4442
|
+
const queryClient = useQueryClient();
|
|
4443
|
+
return useMutation({
|
|
4444
|
+
mutationFn: async (): Promise<MetricsDiscoveryOutcome> => {
|
|
4445
|
+
const resp = await apiFetch(`${getApiBase()}/prometheus/connect`, {
|
|
4446
|
+
method: "POST",
|
|
4447
|
+
});
|
|
4448
|
+
if (!resp.ok && resp.status !== 502) {
|
|
4449
|
+
const body = await readErrorBody(resp);
|
|
4450
|
+
throw new Error(body.error || `HTTP ${resp.status}`);
|
|
4451
|
+
}
|
|
4452
|
+
if (resp.ok && hasPrometheusCharts((await resp.json()) as PrometheusStatus)) return "connected";
|
|
4453
|
+
try {
|
|
4454
|
+
const presence = await fetchJSON<{ detected: boolean }>("/metrics/openobserve/collector");
|
|
4455
|
+
return presence.detected ? "collector" : "none";
|
|
4456
|
+
} catch {
|
|
4457
|
+
return "none";
|
|
4458
|
+
}
|
|
4459
|
+
},
|
|
4460
|
+
onSettled: () => {
|
|
4461
|
+
queryClient.invalidateQueries({ queryKey: ["prometheus-status"] });
|
|
4462
|
+
},
|
|
4463
|
+
});
|
|
4464
|
+
}
|
|
4465
|
+
|
|
4238
4466
|
// Auto-discover Prometheus on first mount of any Prom-backed view, and
|
|
4239
4467
|
// auto-reconnect across radar restarts on subsequent mounts.
|
|
4240
4468
|
//
|
|
@@ -4270,6 +4498,8 @@ export function useAutoPromConnect(): void {
|
|
|
4270
4498
|
const queryClient = useQueryClient();
|
|
4271
4499
|
const { data: clusterInfo } = useClusterInfo();
|
|
4272
4500
|
const { data: status, isLoading: statusLoading } = usePrometheusStatus();
|
|
4501
|
+
const chartsAvailable = hasPrometheusCharts(status);
|
|
4502
|
+
const sourceUnavailable = metricsSourceUnavailable(status);
|
|
4273
4503
|
const attemptedRef = useRef<string | null>(null);
|
|
4274
4504
|
|
|
4275
4505
|
useEffect(() => {
|
|
@@ -4278,7 +4508,7 @@ export function useAutoPromConnect(): void {
|
|
|
4278
4508
|
if (!context || statusLoading) return;
|
|
4279
4509
|
|
|
4280
4510
|
// Persist the "we've connected here before" signal once a connection lands.
|
|
4281
|
-
if (
|
|
4511
|
+
if (chartsAvailable) {
|
|
4282
4512
|
try {
|
|
4283
4513
|
window.localStorage.setItem(promAutoConnectKey(context), "1");
|
|
4284
4514
|
} catch {
|
|
@@ -4287,6 +4517,9 @@ export function useAutoPromConnect(): void {
|
|
|
4287
4517
|
return;
|
|
4288
4518
|
}
|
|
4289
4519
|
|
|
4520
|
+
// An OpenObserve connection that can't answer is the source in use;
|
|
4521
|
+
// discovering Prometheus would not stand in for it.
|
|
4522
|
+
if (sourceUnavailable) return;
|
|
4290
4523
|
if (attemptedRef.current === context) return;
|
|
4291
4524
|
let cached: string | null = null;
|
|
4292
4525
|
try {
|
|
@@ -4317,7 +4550,7 @@ export function useAutoPromConnect(): void {
|
|
|
4317
4550
|
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
|
4318
4551
|
const nextStatus = (await resp.json()) as PrometheusStatus;
|
|
4319
4552
|
queryClient.setQueryData(["prometheus-status"], nextStatus);
|
|
4320
|
-
if (!nextStatus
|
|
4553
|
+
if (!hasPrometheusCharts(nextStatus))
|
|
4321
4554
|
throw new Error(nextStatus.error || "Prometheus unavailable");
|
|
4322
4555
|
queryClient.invalidateQueries({ queryKey: ["prometheus-status"] });
|
|
4323
4556
|
})
|
|
@@ -4339,7 +4572,7 @@ export function useAutoPromConnect(): void {
|
|
|
4339
4572
|
});
|
|
4340
4573
|
}, delay);
|
|
4341
4574
|
return () => window.clearTimeout(timeout);
|
|
4342
|
-
}, [clusterInfo?.context,
|
|
4575
|
+
}, [clusterInfo?.context, chartsAvailable, sourceUnavailable, statusLoading, queryClient]);
|
|
4343
4576
|
}
|
|
4344
4577
|
|
|
4345
4578
|
// Fetch Prometheus metrics for a resource
|
|
@@ -5513,6 +5746,107 @@ export function useResumeCronJob() {
|
|
|
5513
5746
|
});
|
|
5514
5747
|
}
|
|
5515
5748
|
|
|
5749
|
+
// ============================================================================
|
|
5750
|
+
// Argo Workflow stop
|
|
5751
|
+
// ============================================================================
|
|
5752
|
+
|
|
5753
|
+
export type WorkflowStopStrategy = "Stop" | "Terminate";
|
|
5754
|
+
|
|
5755
|
+
/** What POST /workflows/{ns}/{name}/stop settled to, as the UI reports it. */
|
|
5756
|
+
export type WorkflowStopOutcome =
|
|
5757
|
+
| { state: "requested"; shutdown: string }
|
|
5758
|
+
| { state: "already"; shutdown: string }
|
|
5759
|
+
| { state: "notStored"; shutdown: string }
|
|
5760
|
+
| { state: "finished" };
|
|
5761
|
+
|
|
5762
|
+
// A stored Terminate satisfies either strategy. Anything else that doesn't
|
|
5763
|
+
// match the request means admission rewrote or dropped it, whatever `changed`
|
|
5764
|
+
// says: `changed` compares with the value before the patch, not the request.
|
|
5765
|
+
export function workflowStopOutcome(requested: WorkflowStopStrategy, response: { shutdown: string; changed: boolean }): WorkflowStopOutcome {
|
|
5766
|
+
const { shutdown, changed } = response;
|
|
5767
|
+
if (shutdown !== requested && shutdown !== "Terminate") return { state: "notStored", shutdown };
|
|
5768
|
+
// A Stop that admission stored as Terminate interrupts exit handlers the user meant to run.
|
|
5769
|
+
if (changed && shutdown !== requested) return { state: "notStored", shutdown };
|
|
5770
|
+
return changed ? { state: "requested", shutdown } : { state: "already", shutdown };
|
|
5771
|
+
}
|
|
5772
|
+
|
|
5773
|
+
export function workflowStopErrorMessage(body: { error?: string; error_code?: string }, status: number): string {
|
|
5774
|
+
if (body.error_code === "workflow_replaced") {
|
|
5775
|
+
return "A different Workflow now has this name, so nothing was stopped. Open it again to review the current run.";
|
|
5776
|
+
}
|
|
5777
|
+
return body.error || `HTTP ${status}`;
|
|
5778
|
+
}
|
|
5779
|
+
|
|
5780
|
+
/** The request named a run that no longer exists under this name. */
|
|
5781
|
+
export function isWorkflowStopTargetGone(error: unknown): boolean {
|
|
5782
|
+
return error instanceof ApiError && (error.status === 404 || error.data?.error_code === "workflow_replaced");
|
|
5783
|
+
}
|
|
5784
|
+
|
|
5785
|
+
export function reportWorkflowStopOutcome(outcome: WorkflowStopOutcome): void {
|
|
5786
|
+
if (outcome.state === "finished") {
|
|
5787
|
+
showApiNotice("Workflow already finished", "Nothing was stopped.", "info");
|
|
5788
|
+
} else if (outcome.state === "already") {
|
|
5789
|
+
showApiNotice(outcome.shutdown === "Terminate" ? "Workflow is already terminating" : "Workflow is already stopping", undefined, "info");
|
|
5790
|
+
} else if (outcome.state === "notStored") {
|
|
5791
|
+
showApiNotice(
|
|
5792
|
+
"Stop not stored",
|
|
5793
|
+
outcome.shutdown
|
|
5794
|
+
? `Kubernetes accepted the change but stored shutdown "${outcome.shutdown}". An admission policy may have changed it.`
|
|
5795
|
+
: "Kubernetes accepted the change but stored no shutdown, so the Workflow keeps running. An admission policy may have removed it.",
|
|
5796
|
+
"warning",
|
|
5797
|
+
);
|
|
5798
|
+
} else if (outcome.shutdown === "Stop") {
|
|
5799
|
+
showApiSuccess("Stop requested", "Argo ends the running steps, then runs the exit handlers.");
|
|
5800
|
+
} else {
|
|
5801
|
+
showApiSuccess("Terminate requested", "Argo ends the running steps, including any exit handler, and starts no more.");
|
|
5802
|
+
}
|
|
5803
|
+
}
|
|
5804
|
+
|
|
5805
|
+
// The request names the reviewed run by UID only. A running Workflow's
|
|
5806
|
+
// resourceVersion moves with every controller status update, so pinning it
|
|
5807
|
+
// would refuse nearly every stop; the server still refuses a replaced run.
|
|
5808
|
+
export function useStopWorkflow() {
|
|
5809
|
+
const queryClient = useQueryClient();
|
|
5810
|
+
|
|
5811
|
+
return useMutation({
|
|
5812
|
+
mutationFn: async ({
|
|
5813
|
+
namespace,
|
|
5814
|
+
name,
|
|
5815
|
+
uid,
|
|
5816
|
+
strategy,
|
|
5817
|
+
}: {
|
|
5818
|
+
namespace: string;
|
|
5819
|
+
name: string;
|
|
5820
|
+
uid: string;
|
|
5821
|
+
strategy: WorkflowStopStrategy;
|
|
5822
|
+
}): Promise<WorkflowStopOutcome> => {
|
|
5823
|
+
const response = await apiFetch(
|
|
5824
|
+
`${getApiBase()}/workflows/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/stop`,
|
|
5825
|
+
{
|
|
5826
|
+
method: "POST",
|
|
5827
|
+
headers: { "Content-Type": "application/json" },
|
|
5828
|
+
body: JSON.stringify({ uid, strategy }),
|
|
5829
|
+
},
|
|
5830
|
+
);
|
|
5831
|
+
if (!response.ok) {
|
|
5832
|
+
const body = await readErrorBody(response);
|
|
5833
|
+
// The run ended before the request reached it: what the user wanted holds.
|
|
5834
|
+
if (response.status === 409 && body.error_code === "workflow_finished") return { state: "finished" };
|
|
5835
|
+
throw new ApiError(workflowStopErrorMessage(body, response.status), response.status, body);
|
|
5836
|
+
}
|
|
5837
|
+
return workflowStopOutcome(strategy, await response.json());
|
|
5838
|
+
},
|
|
5839
|
+
meta: { errorMessage: "Failed to stop Workflow" },
|
|
5840
|
+
onSuccess: reportWorkflowStopOutcome,
|
|
5841
|
+
onSettled: (_data, _error, variables) => {
|
|
5842
|
+
queryClient.invalidateQueries({ queryKey: ["resource", "workflows", variables.namespace, variables.name] });
|
|
5843
|
+
queryClient.invalidateQueries({ queryKey: ["resources", "workflows"] });
|
|
5844
|
+
queryClient.invalidateQueries({ queryKey: ["workload-runs"] });
|
|
5845
|
+
queryClient.invalidateQueries({ queryKey: ["topology"] });
|
|
5846
|
+
},
|
|
5847
|
+
});
|
|
5848
|
+
}
|
|
5849
|
+
|
|
5516
5850
|
// ============================================================================
|
|
5517
5851
|
// Workload operations
|
|
5518
5852
|
// ============================================================================
|
|
@@ -5520,33 +5854,42 @@ export function useResumeCronJob() {
|
|
|
5520
5854
|
// Restart a workload (Deployment, StatefulSet, DaemonSet, Rollout)
|
|
5521
5855
|
export function useRestartWorkload() {
|
|
5522
5856
|
const queryClient = useQueryClient();
|
|
5857
|
+
const { support, guard } = useRadarFeature("workloadRestartPreconditions");
|
|
5858
|
+
const apiBase = getApiBase();
|
|
5523
5859
|
|
|
5524
5860
|
return useMutation({
|
|
5525
5861
|
mutationFn: async ({
|
|
5526
5862
|
kind,
|
|
5527
5863
|
namespace,
|
|
5528
5864
|
name,
|
|
5865
|
+
uid,
|
|
5529
5866
|
}: {
|
|
5530
5867
|
kind: string;
|
|
5531
5868
|
namespace: string;
|
|
5532
5869
|
name: string;
|
|
5870
|
+
uid?: string;
|
|
5533
5871
|
}) => {
|
|
5534
|
-
const
|
|
5535
|
-
|
|
5536
|
-
{
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5872
|
+
const url = apiUrl(`/workloads/${kind}/${namespace}/${name}/restart`, apiBase);
|
|
5873
|
+
const response = support === "unsupported"
|
|
5874
|
+
? await apiFetch(url, { method: "POST" })
|
|
5875
|
+
: await guard(() => {
|
|
5876
|
+
if (!uid) throw new Error("The workload UID is unavailable. Refresh and try again.");
|
|
5877
|
+
return apiFetch(url, {
|
|
5878
|
+
method: "POST",
|
|
5879
|
+
headers: { "Content-Type": "application/json" },
|
|
5880
|
+
body: JSON.stringify({ uid }),
|
|
5881
|
+
});
|
|
5882
|
+
});
|
|
5540
5883
|
if (!response.ok) {
|
|
5541
5884
|
throw new Error(restartErrorMessage(await readErrorBody(response), response.status));
|
|
5542
5885
|
}
|
|
5543
|
-
return response.json()
|
|
5886
|
+
return response.json() as Promise<RestartResult>;
|
|
5544
5887
|
},
|
|
5545
5888
|
meta: {
|
|
5546
5889
|
errorMessage: "Failed to restart workload",
|
|
5547
|
-
successMessage: "Workload restarting",
|
|
5548
5890
|
},
|
|
5549
|
-
onSuccess: (
|
|
5891
|
+
onSuccess: (result, variables) => {
|
|
5892
|
+
reportRestart(result);
|
|
5550
5893
|
queryClient.invalidateQueries({
|
|
5551
5894
|
queryKey: ["resources", variables.kind],
|
|
5552
5895
|
});
|
|
@@ -5817,9 +6160,42 @@ export function rollbackErrorMessage(body: { error?: string; error_code?: string
|
|
|
5817
6160
|
return body.error || `HTTP ${status}`;
|
|
5818
6161
|
}
|
|
5819
6162
|
|
|
6163
|
+
export interface RestartResult {
|
|
6164
|
+
message?: string;
|
|
6165
|
+
restartedAt?: string;
|
|
6166
|
+
changed?: boolean;
|
|
6167
|
+
}
|
|
6168
|
+
|
|
6169
|
+
// changed:false means the workload already carried a restart request at or after
|
|
6170
|
+
// now (a repeated click, or a Rollout's future restartAt), so nothing new was written.
|
|
6171
|
+
export function restartOutcome(result: RestartResult | undefined): { title: string; detail?: string; repeated: boolean } {
|
|
6172
|
+
if (result?.changed !== false) return { title: "Workload restarting", repeated: false };
|
|
6173
|
+
const at = result.restartedAt ? new Date(result.restartedAt) : undefined;
|
|
6174
|
+
return {
|
|
6175
|
+
title: "Restart already requested",
|
|
6176
|
+
detail: at && !Number.isNaN(at.getTime()) ? `Requested for ${at.toLocaleString()}.` : undefined,
|
|
6177
|
+
repeated: true,
|
|
6178
|
+
};
|
|
6179
|
+
}
|
|
6180
|
+
|
|
6181
|
+
function reportRestart(result: RestartResult | undefined): void {
|
|
6182
|
+
const { title, detail, repeated } = restartOutcome(result);
|
|
6183
|
+
if (repeated) showApiNotice(title, detail, "info");
|
|
6184
|
+
else showApiSuccess(title, detail);
|
|
6185
|
+
}
|
|
6186
|
+
|
|
5820
6187
|
export function restartErrorMessage(body: { error?: string; error_code?: string }, status: number): string {
|
|
5821
|
-
|
|
5822
|
-
|
|
6188
|
+
switch (body.error_code) {
|
|
6189
|
+
case "workload_paused":
|
|
6190
|
+
return "This Deployment is paused. Click Resume rollout, then restart.";
|
|
6191
|
+
case "workload_changed":
|
|
6192
|
+
return "This workload changed or was replaced since you opened it. Refresh and try again.";
|
|
6193
|
+
case "restart_not_applicable":
|
|
6194
|
+
return body.error || "This workload’s update strategy won’t restart all pods.";
|
|
6195
|
+
case "workload_terminating":
|
|
6196
|
+
return "This workload is being deleted and cannot be restarted.";
|
|
6197
|
+
case "restart_not_stored":
|
|
6198
|
+
return "Kubernetes admission changed or removed the restart marker.";
|
|
5823
6199
|
}
|
|
5824
6200
|
return body.error || `HTTP ${status}`;
|
|
5825
6201
|
}
|
|
@@ -6220,8 +6596,7 @@ export function useDrainNode(nodeUID = "") {
|
|
|
6220
6596
|
return response.json();
|
|
6221
6597
|
},
|
|
6222
6598
|
onMutate: ({ name }) => {
|
|
6223
|
-
const contextName = queryClient
|
|
6224
|
-
?? queryClient.getQueryData<{ context: string }>(["connection-status"])?.context;
|
|
6599
|
+
const contextName = cachedContextName(queryClient);
|
|
6225
6600
|
const activity: NodeDrainActivity = {
|
|
6226
6601
|
status: "pending",
|
|
6227
6602
|
requestId: ++nextNodeDrainRequestId,
|
|
@@ -7337,6 +7712,81 @@ export function useArtifactHubChart(
|
|
|
7337
7712
|
// GitOps Mutation Factory
|
|
7338
7713
|
// ============================================================================
|
|
7339
7714
|
|
|
7715
|
+
type GitOpsConnection = { apiBase: string; connectionId?: string };
|
|
7716
|
+
type GitOpsTargetVars = ArgoAppVars & { kind?: string; expectedConnection?: GitOpsConnection };
|
|
7717
|
+
|
|
7718
|
+
function gitOpsRequestTarget(queryClient: QueryClient, { namespace, name, kind }: GitOpsTargetVars): string {
|
|
7719
|
+
const clusterId = /^\/c\/([^/]+)$/.exec(getBasename())?.[1];
|
|
7720
|
+
const context = cachedContextName(queryClient);
|
|
7721
|
+
const cluster = clusterId ?? (context && context !== "in-cluster" ? parseContextName(context).clusterName : undefined);
|
|
7722
|
+
const resource = `${kind ? pluralToKind(kind) : "Application"} ${namespace}/${name}`;
|
|
7723
|
+
return cluster ? `${resource} on ${cluster}` : resource;
|
|
7724
|
+
}
|
|
7725
|
+
|
|
7726
|
+
const GITOPS_PERMISSION_MAX_AGE = 120_000;
|
|
7727
|
+
|
|
7728
|
+
type CachedGitOpsActionCapabilities = GitOpsActionCapabilities & {
|
|
7729
|
+
confirmedAt: Record<string, number>;
|
|
7730
|
+
};
|
|
7731
|
+
|
|
7732
|
+
export function useGitOpsActionCapabilities(kind: string, group: string | undefined, namespace: string, name: string, enabled = true) {
|
|
7733
|
+
const active = isGitOpsActionTarget(kind, group);
|
|
7734
|
+
const queryClient = useQueryClient();
|
|
7735
|
+
const { support, guard, gatedKey } = useRadarFeature("gitopsActionCapabilities");
|
|
7736
|
+
const apiBase = getApiBase();
|
|
7737
|
+
const connection = useCurrentConnectionId(apiBase);
|
|
7738
|
+
const queryKey = ["gitops-action-capabilities", apiBase, connection, kind, group, namespace, name, ...gatedKey];
|
|
7739
|
+
const [, setExpiryTime] = useState(0);
|
|
7740
|
+
const query = useQuery<CachedGitOpsActionCapabilities>({
|
|
7741
|
+
queryKey,
|
|
7742
|
+
queryFn: ({ signal }) => guard(async () => {
|
|
7743
|
+
const next = await fetchJSON<GitOpsActionCapabilities>(`/gitops/capabilities/${encodeURIComponent(kind)}/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}`, signal);
|
|
7744
|
+
const previous = queryClient.getQueryData<CachedGitOpsActionCapabilities>(queryKey);
|
|
7745
|
+
const now = Date.now();
|
|
7746
|
+
const confirmedAt: Record<string, number> = {};
|
|
7747
|
+
for (const [action, capability] of Object.entries(next.actions)) {
|
|
7748
|
+
if (capability.allowed !== undefined || capability.unsupported) {
|
|
7749
|
+
confirmedAt[action] = now;
|
|
7750
|
+
} else if (!capability.unsupported && previous?.confirmedAt[action] !== undefined && now - previous.confirmedAt[action] < GITOPS_PERMISSION_MAX_AGE) {
|
|
7751
|
+
next.actions[action] = previous.actions[action];
|
|
7752
|
+
confirmedAt[action] = previous.confirmedAt[action];
|
|
7753
|
+
}
|
|
7754
|
+
}
|
|
7755
|
+
return { ...next, confirmedAt };
|
|
7756
|
+
}),
|
|
7757
|
+
enabled: enabled && active && Boolean(namespace && name) && support !== 'unsupported',
|
|
7758
|
+
staleTime: 15_000,
|
|
7759
|
+
refetchInterval: query => enabled && active && !isRadarFeatureUnsupported(query.state.error, 'gitopsActionCapabilities') ? 30_000 : false,
|
|
7760
|
+
});
|
|
7761
|
+
const now = Date.now();
|
|
7762
|
+
const expiries = Object.values(query.data?.confirmedAt ?? {}).map(time => time + GITOPS_PERMISSION_MAX_AGE).filter(time => time > now);
|
|
7763
|
+
const nextExpiry = expiries.length ? Math.min(...expiries) : undefined;
|
|
7764
|
+
useEffect(() => {
|
|
7765
|
+
if (nextExpiry === undefined) return;
|
|
7766
|
+
const timer = setTimeout(() => setExpiryTime(Date.now()), Math.max(0, nextExpiry - Date.now()));
|
|
7767
|
+
return () => clearTimeout(timer);
|
|
7768
|
+
}, [nextExpiry]);
|
|
7769
|
+
const data: GitOpsActionCapabilities | undefined = query.data && {
|
|
7770
|
+
actions: Object.fromEntries(Object.entries(query.data.actions).map(([action, capability]) => [action,
|
|
7771
|
+
(capability.allowed !== undefined || capability.unsupported) && now - query.data!.confirmedAt[action] >= GITOPS_PERMISSION_MAX_AGE
|
|
7772
|
+
? { reason: "Couldn't check your permissions — retrying" }
|
|
7773
|
+
: capability,
|
|
7774
|
+
])),
|
|
7775
|
+
};
|
|
7776
|
+
const featureUnsupported = isRadarFeatureUnsupported(query.error, 'gitopsActionCapabilities');
|
|
7777
|
+
const permissions = active ? gitOpsActionPermissions(support, data, featureUnsupported) : undefined;
|
|
7778
|
+
const permissionCheckUnavailable = active && support !== 'unsupported' && !featureUnsupported && (
|
|
7779
|
+
(!data && query.isError) || Object.values(permissions ?? {}).some(capability => capability.allowed === undefined && !capability.unsupported && !!capability.reason)
|
|
7780
|
+
);
|
|
7781
|
+
return {
|
|
7782
|
+
...query,
|
|
7783
|
+
data,
|
|
7784
|
+
permissions,
|
|
7785
|
+
permissionCheckUnavailable,
|
|
7786
|
+
disabledReasons: active ? gitOpsDisabledReasons(support, data, featureUnsupported) : {},
|
|
7787
|
+
};
|
|
7788
|
+
}
|
|
7789
|
+
|
|
7340
7790
|
interface GitOpsMutationConfig<TVariables, TContext = undefined> {
|
|
7341
7791
|
getPath: (variables: TVariables) => string;
|
|
7342
7792
|
// Called by the hook on every render (so it may call hooks); its value is
|
|
@@ -7344,6 +7794,7 @@ interface GitOpsMutationConfig<TVariables, TContext = undefined> {
|
|
|
7344
7794
|
useRequestContext?: () => TContext;
|
|
7345
7795
|
getBody?: (variables: TVariables, context: TContext) => unknown;
|
|
7346
7796
|
errorMessage: string;
|
|
7797
|
+
isErrorShownInline?: (variables: TVariables) => boolean;
|
|
7347
7798
|
successMessage?: string;
|
|
7348
7799
|
getSuccessMessage?: (data: GitOpsOperationResponse, variables: TVariables) => string;
|
|
7349
7800
|
getInvalidateKeys: (variables: TVariables) => (string | undefined)[][];
|
|
@@ -7353,36 +7804,46 @@ interface GitOpsMutationConfig<TVariables, TContext = undefined> {
|
|
|
7353
7804
|
* Factory function for creating GitOps mutation hooks with consistent patterns.
|
|
7354
7805
|
* Handles fetch, error handling, meta messages, and query invalidation.
|
|
7355
7806
|
*/
|
|
7356
|
-
function createGitOpsMutation<TVariables, TContext = undefined>(
|
|
7807
|
+
function createGitOpsMutation<TVariables extends GitOpsTargetVars, TContext = undefined>(
|
|
7357
7808
|
config: GitOpsMutationConfig<TVariables, TContext>,
|
|
7358
7809
|
) {
|
|
7359
|
-
return function useGitOpsMutation() {
|
|
7810
|
+
return function useGitOpsMutation(options?: { reportErrors?: boolean }) {
|
|
7360
7811
|
const queryClient = useQueryClient();
|
|
7361
7812
|
const requestContext = config.useRequestContext?.() as TContext;
|
|
7362
|
-
return useMutation<GitOpsOperationResponse,
|
|
7813
|
+
return useMutation<GitOpsOperationResponse, GitOpsActionError, TVariables>({
|
|
7363
7814
|
mutationFn: async (
|
|
7364
7815
|
variables: TVariables,
|
|
7365
7816
|
): Promise<GitOpsOperationResponse> => {
|
|
7366
|
-
const
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
:
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7817
|
+
const target = gitOpsRequestTarget(queryClient, variables);
|
|
7818
|
+
try {
|
|
7819
|
+
const expected = variables.expectedConnection;
|
|
7820
|
+
if (expected && (getApiBase() !== expected.apiBase || connectionHeaderValue(expected.apiBase) !== expected.connectionId)) {
|
|
7821
|
+
throw new Error("The cluster connection changed before syncing. Return to the original cluster to retry.");
|
|
7822
|
+
}
|
|
7823
|
+
const response = await apiFetch(
|
|
7824
|
+
apiUrl(config.getPath(variables)),
|
|
7825
|
+
{
|
|
7826
|
+
method: "POST",
|
|
7827
|
+
headers: config.getBody
|
|
7828
|
+
? { "Content-Type": "application/json" }
|
|
7829
|
+
: undefined,
|
|
7830
|
+
body: config.getBody
|
|
7831
|
+
? JSON.stringify(config.getBody(variables, requestContext))
|
|
7832
|
+
: undefined,
|
|
7833
|
+
},
|
|
7834
|
+
);
|
|
7835
|
+
if (!response.ok) {
|
|
7836
|
+
const error = await readErrorBody(response);
|
|
7837
|
+
throw new GitOpsActionError(error, response.status, target);
|
|
7838
|
+
}
|
|
7839
|
+
return await response.json() as GitOpsOperationResponse;
|
|
7840
|
+
} catch (error) {
|
|
7841
|
+
if (error instanceof Error && config.isErrorShownInline?.(variables)) markShownInline(error);
|
|
7842
|
+
throw error;
|
|
7381
7843
|
}
|
|
7382
|
-
return response.json() as Promise<GitOpsOperationResponse>;
|
|
7383
7844
|
},
|
|
7384
7845
|
meta: {
|
|
7385
|
-
errorMessage: config.errorMessage,
|
|
7846
|
+
errorMessage: options?.reportErrors === false ? undefined : config.errorMessage,
|
|
7386
7847
|
successMessage: config.successMessage,
|
|
7387
7848
|
},
|
|
7388
7849
|
onSuccess: (data, variables) => {
|
|
@@ -7405,6 +7866,8 @@ type ArgoAppVars = { namespace: string; name: string };
|
|
|
7405
7866
|
// useArgoSync sends these — splitting the type prevents callers from passing
|
|
7406
7867
|
// resources/revision/prune to mutations that would silently drop them.
|
|
7407
7868
|
export type ArgoSyncVars = ArgoAppVars & {
|
|
7869
|
+
expectedConnection?: GitOpsConnection;
|
|
7870
|
+
isErrorShownInline?: () => boolean;
|
|
7408
7871
|
resources?: Array<{
|
|
7409
7872
|
group?: string;
|
|
7410
7873
|
kind: string;
|
|
@@ -7565,6 +8028,7 @@ export const useArgoSync = createGitOpsMutation<ArgoSyncVars, boolean>({
|
|
|
7565
8028
|
useRequestContext: useArgoSyncInheritance,
|
|
7566
8029
|
getBody: argoSyncRequestBody,
|
|
7567
8030
|
errorMessage: "Failed to trigger sync",
|
|
8031
|
+
isErrorShownInline: (variables) => variables.isErrorShownInline?.() ?? false,
|
|
7568
8032
|
getSuccessMessage: (_data, v) => (v.dryRun ? "Dry run started" : "Sync initiated"),
|
|
7569
8033
|
getInvalidateKeys: argoInvalidateKeys,
|
|
7570
8034
|
});
|
|
@@ -7572,10 +8036,10 @@ export const useArgoSync = createGitOpsMutation<ArgoSyncVars, boolean>({
|
|
|
7572
8036
|
export function useArgoResourceValidation() {
|
|
7573
8037
|
const queryClient = useQueryClient();
|
|
7574
8038
|
const serverInheritsOptions = useArgoSyncInheritance();
|
|
7575
|
-
return useMutation<ArgoResourceValidationResult,
|
|
8039
|
+
return useMutation<ArgoResourceValidationResult, GitOpsActionError, ArgoSyncVars>({
|
|
7576
8040
|
mutationFn: async (variables) => {
|
|
7577
8041
|
const response = await apiFetch(
|
|
7578
|
-
|
|
8042
|
+
apiUrl(`/argo/applications/${variables.namespace}/${variables.name}/validate-resource`),
|
|
7579
8043
|
{
|
|
7580
8044
|
method: "POST",
|
|
7581
8045
|
headers: { "Content-Type": "application/json" },
|
|
@@ -7592,7 +8056,7 @@ export function useArgoResourceValidation() {
|
|
|
7592
8056
|
);
|
|
7593
8057
|
if (!response.ok) {
|
|
7594
8058
|
const error = await readErrorBody(response);
|
|
7595
|
-
throw new
|
|
8059
|
+
throw new GitOpsActionError(error, response.status);
|
|
7596
8060
|
}
|
|
7597
8061
|
return response.json() as Promise<ArgoResourceValidationResult>;
|
|
7598
8062
|
},
|
|
@@ -7633,48 +8097,12 @@ export const useArgoResume = createGitOpsMutation<ArgoAppVars>({
|
|
|
7633
8097
|
getInvalidateKeys: argoInvalidateKeys,
|
|
7634
8098
|
});
|
|
7635
8099
|
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
namespace,
|
|
7643
|
-
name,
|
|
7644
|
-
hard = false,
|
|
7645
|
-
}: {
|
|
7646
|
-
namespace: string;
|
|
7647
|
-
name: string;
|
|
7648
|
-
hard?: boolean;
|
|
7649
|
-
}) => {
|
|
7650
|
-
const params = hard ? "?type=hard" : "";
|
|
7651
|
-
const response = await apiFetch(
|
|
7652
|
-
`${getApiBase()}/argo/applications/${namespace}/${name}/refresh${params}`,
|
|
7653
|
-
{
|
|
7654
|
-
method: "POST",
|
|
7655
|
-
},
|
|
7656
|
-
);
|
|
7657
|
-
if (!response.ok) {
|
|
7658
|
-
const error = await readErrorBody(response);
|
|
7659
|
-
throw new Error(error.error || `HTTP ${response.status}`);
|
|
7660
|
-
}
|
|
7661
|
-
return response.json();
|
|
7662
|
-
},
|
|
7663
|
-
meta: {
|
|
7664
|
-
errorMessage: "Failed to refresh application",
|
|
7665
|
-
successMessage: "Application refreshed",
|
|
7666
|
-
},
|
|
7667
|
-
onSuccess: (_, variables) => {
|
|
7668
|
-
// Match the standard Argo invalidation set so the GitOps detail page
|
|
7669
|
-
// (insights strip, resource tree) refetches after Refresh / Hard
|
|
7670
|
-
// Refresh — without these two extra keys the user clicks Refresh and
|
|
7671
|
-
// sees stale insight/tree data until the next staleTime tick.
|
|
7672
|
-
argoInvalidateKeys(variables).forEach((key) =>
|
|
7673
|
-
queryClient.invalidateQueries({ queryKey: key }),
|
|
7674
|
-
);
|
|
7675
|
-
},
|
|
7676
|
-
});
|
|
7677
|
-
}
|
|
8100
|
+
export const useArgoRefresh = createGitOpsMutation<ArgoAppVars & { hard?: boolean }>({
|
|
8101
|
+
getPath: ({ namespace, name, hard }) => `/argo/applications/${namespace}/${name}/refresh${hard ? "?type=hard" : ""}`,
|
|
8102
|
+
errorMessage: "Failed to refresh application",
|
|
8103
|
+
successMessage: "Application refreshed",
|
|
8104
|
+
getInvalidateKeys: argoInvalidateKeys,
|
|
8105
|
+
});
|
|
7678
8106
|
|
|
7679
8107
|
// ============================================================================
|
|
7680
8108
|
// Context Switching API hooks
|
|
@@ -8258,6 +8686,46 @@ export function useWorkloadPods(
|
|
|
8258
8686
|
});
|
|
8259
8687
|
}
|
|
8260
8688
|
|
|
8689
|
+
// POST /api/workflowtemplates/{namespace}/{name}/submit
|
|
8690
|
+
//
|
|
8691
|
+
// Creates a Workflow that runs the template, as the caller. When the request
|
|
8692
|
+
// fails without a definite answer (network error, timeout or 5xx), refreshes
|
|
8693
|
+
// the template's run list so the user can check whether the run started.
|
|
8694
|
+
export function useSubmitWorkflowTemplate() {
|
|
8695
|
+
const queryClient = useQueryClient();
|
|
8696
|
+
const { guard } = useRadarFeature("workflowTemplateSubmit");
|
|
8697
|
+
return useMutation({
|
|
8698
|
+
mutationFn: ({ namespace, name, runName, parameters }: WorkflowTemplateSubmission) =>
|
|
8699
|
+
guard(() =>
|
|
8700
|
+
fetchJSON<SubmittedWorkflow>(
|
|
8701
|
+
`/workflowtemplates/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/submit`,
|
|
8702
|
+
{
|
|
8703
|
+
method: "POST",
|
|
8704
|
+
headers: { "Content-Type": "application/json" },
|
|
8705
|
+
body: JSON.stringify({
|
|
8706
|
+
...(runName ? { name: runName } : {}),
|
|
8707
|
+
...(Object.keys(parameters).length > 0 ? { parameters } : {}),
|
|
8708
|
+
}),
|
|
8709
|
+
},
|
|
8710
|
+
),
|
|
8711
|
+
),
|
|
8712
|
+
meta: { errorMessage: "Could not submit the workflow template" },
|
|
8713
|
+
onError: (error, variables) => {
|
|
8714
|
+
if (isAmbiguousSubmitError(error)) {
|
|
8715
|
+
void queryClient.invalidateQueries({
|
|
8716
|
+
queryKey: ["workload-runs", "workflowtemplates", variables.namespace, variables.name],
|
|
8717
|
+
});
|
|
8718
|
+
}
|
|
8719
|
+
},
|
|
8720
|
+
onSuccess: (run, variables) => {
|
|
8721
|
+
showApiSuccess("Workflow submitted", `${run.namespace}/${run.name}`);
|
|
8722
|
+
void queryClient.invalidateQueries({
|
|
8723
|
+
queryKey: ["workload-runs", "workflowtemplates", variables.namespace, variables.name],
|
|
8724
|
+
});
|
|
8725
|
+
},
|
|
8726
|
+
});
|
|
8727
|
+
}
|
|
8728
|
+
|
|
8261
8729
|
export function useWorkloadRuns(
|
|
8262
8730
|
kind: string,
|
|
8263
8731
|
namespace: string,
|