-
Notifications
You must be signed in to change notification settings - Fork 596
/
console-types.ts
706 lines (607 loc) · 16.9 KB
/
console-types.ts
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
import * as React from 'react';
import { ButtonProps } from '@patternfly/react-core';
import { ICell, OnSelect, SortByDirection, TableGridBreakpoint } from '@patternfly/react-table';
import { LocationDescriptor } from 'history';
import MonacoEditor from 'react-monaco-editor/lib/editor';
import { RouteComponentProps } from 'react-router';
import {
ExtensionK8sGroupKindModel,
K8sModel,
MatchLabels,
PrometheusEndpoint,
PrometheusLabels,
PrometheusValue,
ResolvedExtension,
Selector,
} from '../api/common-types';
import { Extension, ExtensionTypeGuard } from '../types';
import { CustomDataSource } from './dashboard-data-source';
export type OwnerReference = {
name: string;
kind: string;
uid: string;
apiVersion: string;
controller?: boolean;
blockOwnerDeletion?: boolean;
};
export type ObjectReference = {
kind?: string;
namespace?: string;
name?: string;
uid?: string;
apiVersion?: string;
resourceVersion?: string;
fieldPath?: string;
};
export type ObjectMetadata = {
annotations?: { [key: string]: string };
clusterName?: string;
creationTimestamp?: string;
deletionGracePeriodSeconds?: number;
deletionTimestamp?: string;
finalizers?: string[];
generateName?: string;
generation?: number;
labels?: { [key: string]: string };
managedFields?: any[];
name?: string;
namespace?: string;
ownerReferences?: OwnerReference[];
resourceVersion?: string;
uid?: string;
};
// Properties common to (almost) all Kubernetes resources.
export type K8sResourceCommon = {
apiVersion?: string;
kind?: string;
metadata?: ObjectMetadata;
};
export type K8sResourceKind = K8sResourceCommon & {
spec?: {
selector?: Selector | MatchLabels;
[key: string]: any;
};
status?: { [key: string]: any };
data?: { [key: string]: any };
};
export type K8sVerb =
| 'create'
| 'get'
| 'list'
| 'update'
| 'patch'
| 'delete'
| 'deletecollection'
| 'watch';
export type AccessReviewResourceAttributes = {
group?: string;
resource?: string;
subresource?: string;
verb?: K8sVerb;
name?: string;
namespace?: string;
};
/**
* @deprecated Use K8sGroupVersionKind type instead. Support for type K8sResourceKindReference will be removed in a future release.
* @see K8sGroupVersionKind
* GroupVersionKind unambiguously identifies a kind.
* https://godoc.org/k8s.io/apimachinery/pkg/runtime/schema#GroupVersionKind
* TODO: Change this to a regex-type if it ever becomes a thing (https://github.com/Microsoft/TypeScript/issues/6579)
*/
export type GroupVersionKind = string;
/**
* The canonical, unique identifier for a Kubernetes resource type.
* Maintains backwards-compatibility with references using the `kind` string field.
*/
export type K8sResourceKindReference = string;
export type K8sGroupVersionKind = { group?: string; version: string; kind: string };
enum InventoryStatusGroup {
WARN = 'WARN',
ERROR = 'ERROR',
PROGRESS = 'PROGRESS',
NOT_MAPPED = 'NOT_MAPPED',
UNKNOWN = 'UNKNOWN',
}
type StatusGroup = {
[key in InventoryStatusGroup | string]: {
filterType?: string;
statusIDs: string[];
count: number;
};
};
export type StatusGroupMapper<
T extends K8sResourceCommon = K8sResourceCommon,
R extends { [key: string]: K8sResourceCommon[] } = { [key: string]: K8sResourceCommon[] }
> = (resources: T[], additionalResources?: R) => StatusGroup;
export enum HealthState {
OK = 'OK',
ERROR = 'ERROR',
WARNING = 'WARNING',
LOADING = 'LOADING',
UNKNOWN = 'UNKNOWN',
UPDATING = 'UPDATING',
PROGRESS = 'PROGRESS',
UPGRADABLE = 'UPGRADABLE',
NOT_AVAILABLE = 'NOT_AVAILABLE',
}
// Only covers range and instant vector responses for now.
export type PrometheusResult = {
metric: PrometheusLabels;
values?: PrometheusValue[];
value?: PrometheusValue;
};
export type PrometheusData = {
resultType: 'matrix' | 'vector' | 'scalar' | 'string';
result: PrometheusResult[];
};
export type PrometheusResponse = {
status: string;
data: PrometheusData;
errorType?: string;
error?: string;
warnings?: string[];
};
export type PrometheusPollProps = {
/** Delay between polling requests */
delay?: number;
/** One of the well-defined Prometheus API endpoints */
endpoint: PrometheusEndpoint;
namespace?: string;
/** Prometheus query, polling is skipped when empty or undefined */
query?: string;
/** A search parameter */
timeout?: string;
/** A vector-query search parameter */
endTime?: number;
/** A vector-query search parameter */
samples?: number;
/** A vector-query search parameter */
timespan?: number;
/** An object used to facilitate fetching from different data sources. */
customDataSource?: CustomDataSource;
};
export type UsePrometheusPoll = (
props: PrometheusPollProps,
) => [PrometheusResponse | undefined, boolean, unknown];
export type WatchK8sResource = {
/** @deprecated Use groupVersionKind instead. The kind property will be removed in a future release. */
kind?: K8sResourceKindReference;
groupVersionKind?: K8sGroupVersionKind;
name?: string;
namespace?: string;
isList?: boolean;
selector?: Selector;
namespaced?: boolean;
limit?: number;
fieldSelector?: string;
optional?: boolean;
partialMetadata?: boolean;
};
export type ResourcesObject = { [key: string]: K8sResourceCommon | K8sResourceCommon[] };
export type WatchK8sResultsObject<R extends K8sResourceCommon | K8sResourceCommon[]> = {
data: R;
loaded: boolean;
loadError: any;
};
export type WatchK8sResults<R extends ResourcesObject> = {
[k in keyof R]: WatchK8sResultsObject<R[k]>;
};
export type WatchK8sResources<R extends ResourcesObject> = {
[k in keyof R]: WatchK8sResource;
};
export type WatchK8sResourcesGeneric = {
[key: string]: {
model?: ExtensionK8sGroupKindModel;
opts?: Partial<WatchK8sResource>;
};
};
export type FirehoseResource = {
kind: K8sResourceKindReference;
name?: string;
namespace?: string;
isList?: boolean;
selector?: Selector;
prop: string;
namespaced?: boolean;
optional?: boolean;
limit?: number;
fieldSelector?: string;
};
export type FirehoseResult<
R extends K8sResourceCommon | K8sResourceCommon[] = K8sResourceCommon[]
> = {
loaded: boolean;
loadError: string;
optional?: boolean;
data: R;
kind?: string;
};
export type FirehoseResourcesResult = {
[key: string]: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>;
};
export type WatchK8sResult<R extends K8sResourceCommon | K8sResourceCommon[]> = [R, boolean, any];
export type UseK8sWatchResource = <R extends K8sResourceCommon | K8sResourceCommon[]>(
initResource: WatchK8sResource | null,
) => WatchK8sResult<R>;
export type UseK8sWatchResources = <R extends ResourcesObject>(
initResources: WatchK8sResources<R>,
) => WatchK8sResults<R>;
export type UseResolvedExtensions = <E extends Extension>(
...typeGuards: ExtensionTypeGuard<E>[]
) => [ResolvedExtension<E>[], boolean, any[]];
export type ConsoleFetch = (
url: string,
options?: RequestInit,
timeout?: number,
) => Promise<Response>;
export type ConsoleFetchJSON<T = any> = {
(url: string, method?: string, options?: RequestInit, timeout?: number): Promise<T>;
delete(url: string, json?: any, options?: RequestInit, timeout?: number): Promise<T>;
post(url: string, json: any, options?: RequestInit, timeout?: number): Promise<T>;
put(url: string, json: any, options?: RequestInit, timeout?: number): Promise<T>;
patch(url: string, json: any, options?: RequestInit, timeout?: number): Promise<T>;
};
export type ConsoleFetchText = (...args: Parameters<ConsoleFetch>) => Promise<string>;
/* Horizontal Nav Types */
export type NavPage = {
href?: string;
path?: string;
name: string;
component: React.ComponentType<RouteComponentProps>;
};
export type HorizontalNavProps = {
resource?: K8sResourceCommon;
pages: NavPage[];
};
export type TableColumn<D> = ICell & {
title: string;
id: string;
additional?: boolean;
sort?: ((data: D[], sortDirection: SortByDirection) => D[]) | string;
};
export type RowProps<D, R extends any = {}> = {
obj: D;
rowData: R;
activeColumnIDs: Set<string>;
};
type VirtualizedTableProps<D, R extends any = {}> = {
data: D[];
unfilteredData: D[];
loaded: boolean;
loadError: any;
columns: TableColumn<D>[];
Row: React.ComponentType<RowProps<D, R>>;
NoDataEmptyMsg?: React.ComponentType<{}>;
EmptyMsg?: React.ComponentType<{}>;
scrollNode?: () => HTMLElement;
onSelect?: OnSelect;
label?: string;
'aria-label'?: string;
gridBreakPoint?: TableGridBreakpoint;
rowData?: R;
mock?: boolean;
};
export type VirtualizedTableFC = <D, R extends any = {}>(
props: VirtualizedTableProps<D, R>,
) => JSX.Element;
export type TableDataProps = {
id: string;
activeColumnIDs: Set<string>;
className?: string;
};
export type UseActiveColumns = <D = any>({
columns,
showNamespaceOverride,
columnManagementID,
}: {
columns: TableColumn<D>[];
showNamespaceOverride: boolean;
columnManagementID: string;
}) => [TableColumn<D>[], boolean];
export type ListPageHeaderProps = {
title: string;
helpText?: React.ReactNode;
badge?: React.ReactNode;
};
export type CreateWithPermissionsProps = {
createAccessReview?: {
groupVersionKind: K8sResourceKindReference | K8sGroupVersionKind;
namespace?: string;
};
};
export type ListPageCreateProps = CreateWithPermissionsProps & {
groupVersionKind: K8sResourceKindReference | K8sGroupVersionKind;
};
export type ListPageCreateLinkProps = CreateWithPermissionsProps & {
to: string;
};
export type ListPageCreateButtonProps = CreateWithPermissionsProps & ButtonProps;
export type ListPageCreateDropdownProps = CreateWithPermissionsProps & {
items: {
[key: string]: React.ReactNode;
};
onClick: (item: string) => void;
};
export type RowFilterItem = {
id: string;
title: string;
hideIfEmpty?: string;
};
export type FilterValue = {
selected?: string[];
all?: string[];
};
type RowFilterBase<R> = {
filterGroupName: string;
type: string;
items: RowFilterItem[];
filter: (input: FilterValue, obj: R) => boolean;
defaultSelected?: string[];
};
export type RowMatchFilter<R = any> = RowFilterBase<R> & {
isMatch: (obj: R, id: string) => boolean;
};
export type RowReducerFilter<R = any> = RowFilterBase<R> & {
reducer: (obj: R) => React.ReactText;
};
export type RowFilter<R = any> = RowMatchFilter<R> | RowReducerFilter<R>;
export type ColumnLayout = {
id: string;
columns: ManagedColumn[];
selectedColumns: Set<string>;
showNamespaceOverride?: boolean;
type: string;
};
export type ManagedColumn = {
id: string;
title: string;
additional?: boolean;
};
export type OnFilterChange = (type: string, value: FilterValue) => void;
export type ListPageFilterProps<D = any> = {
data: D;
loaded: boolean;
rowFilters?: RowFilter[];
labelFilter?: string;
labelPath?: string;
nameFilterTitle?: string;
nameFilterPlaceholder?: string;
labelFilterPlaceholder?: string;
hideNameLabelFilters?: boolean;
hideLabelFilter?: boolean;
columnLayout?: ColumnLayout;
onFilterChange: OnFilterChange;
hideColumnManagement?: boolean;
nameFilter?: string;
};
export type UseListPageFilter = <D, R>(
data: D[],
rowFilters?: RowFilter<R>[],
staticFilters?: { [key: string]: FilterValue },
) => [D[], D[], OnFilterChange];
export type ResourceLinkProps = {
/** @deprecated Use groupVersionKind instead. The kind property will be removed in a future release. */
kind?: K8sResourceKindReference;
groupVersionKind?: K8sGroupVersionKind;
className?: string;
displayName?: string;
inline?: boolean;
linkTo?: boolean;
name?: string;
namespace?: string;
hideIcon?: boolean;
title?: string;
dataTest?: string;
onClick?: () => void;
truncate?: boolean;
nameSuffix?: React.ReactNode;
children?: React.ReactNode;
};
export type ResourceIconProps = {
className?: string;
/** @deprecated Use groupVersionKind instead. The kind property will be removed in a future release. */
kind?: K8sResourceKindReference;
groupVersionKind?: K8sGroupVersionKind;
};
export type UseK8sModel = (
// Use K8sGroupVersionKind type instead of K8sResourceKindReference. Support for type K8sResourceKindReference will be removed in a future release.
groupVersionKind?: K8sResourceKindReference | K8sGroupVersionKind,
) => [K8sModel, boolean];
export type UseK8sModels = () => [{ [key: string]: K8sModel }, boolean];
export type PerspectiveType = string;
export type UseActivePerspective = () => [
PerspectiveType,
React.Dispatch<React.SetStateAction<PerspectiveType>>,
];
export type QueryParams = {
watch?: string;
labelSelector?: string;
fieldSelector?: string;
resourceVersion?: string;
[key: string]: string;
};
export type Patch = {
op: string;
path: string;
value?: any;
};
export type Cause = {
field: string;
message: string;
reason: string;
};
export type Status = {
apiVersion: 'v1';
kind: 'Status';
details: {
causes: Cause[];
group: string;
kind: string;
};
message: string;
metadata: any;
reason: string;
status: string;
};
export type StatusComponentProps = {
title?: string;
iconOnly?: boolean;
noTooltip?: boolean;
className?: string;
popoverTitle?: string;
};
export type OverviewProps = {
className?: string;
children: React.ReactNode;
};
export enum GridPosition {
MAIN = 'MAIN',
LEFT = 'LEFT',
RIGHT = 'RIGHT',
}
export type OverviewCardSpan = 4 | 6 | 12;
export type OverviewGridCard = {
Card: React.ComponentType<any>;
span?: OverviewCardSpan;
};
export type OverviewGridProps = {
mainCards: OverviewGridCard[];
leftCards?: OverviewGridCard[];
rightCards?: OverviewGridCard[];
};
export type InventoryItemTitleProps = {
children: React.ReactNode;
};
export type InventoryItemBodyProps = {
error?: any;
};
export type InventoryItemStatusProps = {
count: number;
icon: React.ReactNode;
linkTo?: string;
};
export type HumanizeResult = {
string: string;
value: number;
unit: string;
};
export type Humanize = (
value: string | number,
initialUnit?: string,
preferredUnit?: string,
) => HumanizeResult;
export enum LIMIT_STATE {
'ERROR' = 'ERROR',
'WARN' = 'WARN',
'OK' = 'OK',
}
export type TopConsumerPopoverProps = {
current: string;
total?: string;
available?: string;
limit?: string;
limitState?: LIMIT_STATE;
requested?: string;
requestedState?: LIMIT_STATE;
};
export type QueryWithDescription = {
query: string;
desc: string;
};
export type SelfSubjectAccessReviewKind = {
apiVersion: string;
kind: string;
metadata?: ObjectMetadata;
spec: {
resourceAttributes?: AccessReviewResourceAttributes;
};
status?: {
allowed: boolean;
denied?: boolean;
reason?: string;
evaluationError?: string;
};
};
export type CodeEditorProps = {
value?: string;
language?: string;
options?: object;
minHeight?: string | number;
showShortcuts?: boolean;
showMiniMap?: boolean;
toolbarLinks?: React.ReactNodeArray;
onChange?: (newValue, event) => void;
onSave?: () => void;
};
export type CodeEditorRef = {
editor?: MonacoEditor['editor'];
};
export type ResourceYAMLEditorProps = {
initialResource: string | { [key: string]: any };
header?: string;
onSave?: (content: string) => void;
};
export type ResourceEventStreamProps = {
resource: K8sResourceCommon;
};
export type TimestampProps = {
timestamp: string | number | Date;
simple?: boolean;
omitSuffix?: boolean;
className?: string;
};
export type NamespaceBarProps = {
onNamespaceChange?: (namespace: string) => void;
isDisabled?: boolean;
children?: React.ReactNode;
};
export type ErrorBoundaryFallbackProps = {
errorMessage: string;
componentStack: string;
stack: string;
title: string;
};
export type FormatSeriesTitle = (labels: PrometheusLabels, i?: number) => string;
export type QueryBrowserProps = {
customDataSource?: CustomDataSource;
defaultSamples?: number;
defaultTimespan?: number;
disabledSeries?: PrometheusLabels[][];
disableZoom?: boolean;
filterLabels?: PrometheusLabels;
fixedEndTime?: number;
formatSeriesTitle?: FormatSeriesTitle;
GraphLink?: React.ComponentType<{}>;
hideControls?: boolean;
isStack?: boolean;
namespace?: string;
onZoom?: (from: number, to: number) => void;
pollInterval?: number;
queries: string[];
showLegend?: boolean;
showStackedControl?: boolean;
timespan?: number;
units?: string;
};
export type StorageClass = K8sResourceCommon & {
provisioner: string;
parameters: object;
reclaimPolicy?: string;
volumeBindingMode?: string;
allowVolumeExpansion?: boolean;
};
export type UseAnnotationsModal = (resource: K8sResourceCommon) => () => void;
export type UseDeleteModal = (
resource: K8sResourceCommon,
redirectTo?: LocationDescriptor,
message?: JSX.Element,
btnText?: React.ReactNode,
deleteAllResources?: () => Promise<K8sResourceKind[]>,
) => () => void;
export type UseLabelsModal = (resource: K8sResourceCommon) => () => void;
export type UseValuesForNamespaceContext = () => {
namespace: string;
setNamespace: (ns: string) => void;
loaded: boolean;
};
export type UseActiveNamespace = () => [string, (ns: string) => void];