Repository navigation
Expand file tree
/
Copy pathresources.ts
More file actions
335 lines (306 loc) · 7.38 KB
/
Copy pathresources.ts
File metadata and controls
335 lines (306 loc) · 7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import type { UseQueryResult } from '@tanstack/react-query'
import type { Event, Pod } from 'kubernetes-types/core/v1.js'
export interface ResourceReference {
group: string
resource: string
scope?: 'Namespaced' | 'Cluster'
}
export interface ResourceMetadata {
name: string
namespace?: string
uid?: string
resourceVersion?: string
creationTimestamp?: string
labels?: Record<string, string>
annotations?: Record<string, string>
ownerReferences?: {
apiVersion: string
kind: string
name: string
uid: string
controller?: boolean
blockOwnerDeletion?: boolean
}[]
}
export interface KubernetesResource {
apiVersion?: string
kind?: string
metadata: ResourceMetadata
}
export interface ResourceQueryOptions {
cluster?: string
namespace?: string
enabled?: boolean
staleTime?: number
refreshInterval?: number
labelSelector?: string
fieldSelector?: string
reduce?: boolean
}
export interface ResourceScopeOptions {
cluster?: string
namespace?: string
signal?: AbortSignal
}
export interface ResourceDeleteOptions extends ResourceScopeOptions {
force?: boolean
wait?: boolean
}
export type DeepPartial<T> = T extends object
? { [P in keyof T]?: DeepPartial<T[P]> }
: T
export interface ApplyResourceResponse {
message: string
kind?: string
name?: string
namespace?: string
count?: number
resources?: Array<{
kind: string
name: string
namespace?: string
}>
}
export interface ResourceHistory {
id: number
clusterName: string
resourceType: string
resourceName: string
namespace: string
operationType: string
operationSource: string
resourceYaml: string
previousYaml: string
success: boolean
errorMessage: string
operatorId: number
operator: { username: string; provider: string }
createdAt: string
updatedAt: string
}
export interface ResourceHistoryResponse {
data: ResourceHistory[]
pagination: {
page: number
pageSize: number
total: number
totalPages: number
hasNextPage: boolean
hasPrevPage: boolean
}
}
export interface ResourceHistoryQueryOptions extends ResourceQueryOptions {
page?: number
pageSize?: number
}
export interface RelatedResource {
type: string
name: string
namespace?: string
apiVersion?: string
}
export interface ResourceTemplate {
id: number
name: string
description: string
yaml: string
}
export interface ImageTagInfo {
name: string
timestamp?: string
}
export type WorkloadRevisionResourceType =
'deployments' | 'statefulsets' | 'daemonsets'
export interface WorkloadRevisionItem {
revision: number
revisionObject: string
changeCause?: string
images: string[]
replicas?: number
createdAt: string
current: boolean
}
export interface WorkloadRevisionsResponse {
items: WorkloadRevisionItem[]
}
export interface FileInfo {
name: string
isDir: boolean
size: string
modTime: string
mode: string
uid: string
gid: string
}
export interface DrainNodeOptions {
force: boolean
gracePeriod: number
deleteLocalData: boolean
ignoreDaemonsets: boolean
}
export interface DrainNodeResponse {
message: string
node: string
pods: number
warnings?: string | string[]
}
export interface CordonNodeResponse {
message: string
node: string
unschedulable: boolean
}
export interface NodeTaint {
key: string
value: string
effect: 'NoSchedule' | 'PreferNoSchedule' | 'NoExecute'
}
export interface DebugPodRequest {
image: string
targetContainerName: string
command?: string[]
}
export interface CopyDebugPodRequest {
copyTo: string
targetContainerName: string
image?: string
command: string[]
}
export interface DebugPodResponse {
pod: Pod
containerName: string
}
export let useResources: <T = KubernetesResource>(
resource: ResourceReference,
options?: ResourceQueryOptions
) => UseQueryResult<T[], Error>
export let useResource: <T = KubernetesResource>(
resource: ResourceReference,
name: string,
options?: ResourceQueryOptions
) => UseQueryResult<T, Error>
export let useResourceEvents: (
resource: ResourceReference,
name: string,
options?: ResourceQueryOptions
) => UseQueryResult<Event[], Error>
export let useDescribe: (
resource: ResourceReference,
name: string,
options?: ResourceQueryOptions
) => UseQueryResult<{ result: string }, Error>
export let useResourceHistory: (
resource: ResourceReference,
name: string,
options?: ResourceHistoryQueryOptions
) => UseQueryResult<ResourceHistoryResponse, Error>
export let useRelatedResources: (
resource: ResourceReference,
name: string,
options?: ResourceQueryOptions
) => UseQueryResult<RelatedResource[], Error>
export let applyResource: (
yaml: string,
namespace?: string
) => Promise<ApplyResourceResponse>
export let updateResource: <T>(
resource: ResourceReference,
name: string,
body: T,
options?: ResourceScopeOptions
) => Promise<void>
/** Built-in resources only; use applyResource for custom resources. */
export let patchResource: <T>(
resource: ResourceReference,
name: string,
body: DeepPartial<T>,
options?: ResourceScopeOptions
) => Promise<void>
export let deleteResource: (
resource: ResourceReference,
name: string,
options?: ResourceDeleteOptions
) => Promise<void>
export let useTemplates: (options?: {
staleTime?: number
}) => UseQueryResult<ResourceTemplate[], Error>
export let useImageTags: (
image: string,
options?: { enabled?: boolean }
) => UseQueryResult<ImageTagInfo[], Error>
export let useWorkloadRevisions: (
resource: WorkloadRevisionResourceType,
namespace: string,
name: string,
options?: { enabled?: boolean; staleTime?: number }
) => UseQueryResult<WorkloadRevisionsResponse, Error>
export let usePodFiles: (
namespace: string,
podName: string,
container: string,
path: string,
options?: { enabled?: boolean }
) => UseQueryResult<FileInfo[], Error>
export let scaleDeployment: (
namespace: string,
name: string,
replicas: number
) => Promise<void>
export let restartWorkload: (
resource: 'deployments' | 'statefulsets',
name: string,
namespace: string
) => Promise<void>
export let rollbackWorkload: (
resource: WorkloadRevisionResourceType,
namespace: string,
name: string,
revision: number
) => Promise<{ message?: string; revision?: number }>
export let drainNode: (
nodeName: string,
options: DrainNodeOptions
) => Promise<DrainNodeResponse>
export let cordonNode: (nodeName: string) => Promise<CordonNodeResponse>
export let uncordonNode: (nodeName: string) => Promise<CordonNodeResponse>
export let taintNode: (
nodeName: string,
taint: NodeTaint
) => Promise<{ message: string; node: string; taint: unknown }>
export let untaintNode: (
nodeName: string,
key: string
) => Promise<{ message: string; node: string; removedTaintKey: string }>
export let resizePod: (
namespace: string,
name: string,
body: Partial<Pod>
) => Promise<void>
export let debugPod: (
namespace: string,
name: string,
body: DebugPodRequest
) => Promise<DebugPodResponse>
export let copyDebugPod: (
namespace: string,
name: string,
body: CopyDebugPodRequest
) => Promise<DebugPodResponse>
export let podDownloadFile: (
namespace: string,
podName: string,
container: string,
path: string
) => void
export let podPreviewFile: (
namespace: string,
podName: string,
container: string,
path: string
) => void
export let podUploadFile: (
namespace: string,
podName: string,
container: string,
path: string,
file: File
) => Promise<void>