-
Notifications
You must be signed in to change notification settings - Fork 703
/
types.ts
494 lines (446 loc) · 13 KB
/
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
// Copyright 2018-2022 the Kubeapps contributors.
// SPDX-License-Identifier: Apache-2.0
import { JSONSchemaType, ErrorObject } from "ajv";
import { RouterState } from "connected-react-router";
import {
AvailablePackageDetail,
AvailablePackageSummary,
GetAvailablePackageSummariesResponse,
InstalledPackageDetail,
InstalledPackageSummary,
PackageAppVersion,
ResourceRef,
} from "gen/kubeappsapis/core/packages/v1alpha1/packages";
import {
DockerCredentials,
OpaqueCredentials,
PackageRepositoryAuth_PackageRepositoryAuthType,
SshCredentials,
TlsCertKey,
UsernamePassword,
} from "gen/kubeappsapis/core/packages/v1alpha1/repositories";
import { Plugin } from "gen/kubeappsapis/core/plugins/v1alpha1/plugins";
import { FluxPackageRepositoryCustomDetail } from "gen/kubeappsapis/plugins/fluxv2/packages/v1alpha1/fluxv2";
import { HelmPackageRepositoryCustomDetail } from "gen/kubeappsapis/plugins/helm/packages/v1alpha1/helm";
import { KappControllerPackageRepositoryCustomDetail } from "gen/kubeappsapis/plugins/kapp_controller/packages/v1alpha1/kapp_controller";
import { IOperatorsState } from "reducers/operators";
import { Subscription } from "rxjs";
import { IAuthState } from "../reducers/auth";
import { IClustersState } from "../reducers/cluster";
import { IConfigState } from "../reducers/config";
import { IPackageRepositoryState } from "../reducers/repos";
import { RpcError } from "./RpcError";
export class CustomError extends Error {
public causes: Error[] | undefined;
// The constructor is defined so we can later on compare the returned object
// via err.constructor == FOO
constructor(message?: string, causes?: Error[]) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
this.causes = causes;
this.checkCauses();
}
// Workaround used until RPC code (unary) throws a custom rpc error
// Check if any RPC error is among the causes
private checkCauses() {
if (!this.causes) return;
for (let i = 0; i < this.causes.length; i++) {
const cause = this.causes[i];
if (RpcError.isRpcError(cause)) {
this.causes[i] = new RpcError(cause);
}
}
}
}
// For 4XX HTTP-alike errors
export class ClientNetworkError extends CustomError {}
// 400
export class BadRequestNetworkError extends ClientNetworkError {}
// 401
export class UnauthorizedNetworkError extends ClientNetworkError {}
// 403
export class ForbiddenNetworkError extends ClientNetworkError {}
// 404
export class NotFoundNetworkError extends ClientNetworkError {}
// 408
export class RequestTimeoutNetworkError extends ClientNetworkError {}
// 409
export class ConflictNetworkError extends ClientNetworkError {}
// 422
export class UnprocessableEntityError extends ClientNetworkError {}
// 429
export class TooManyRequestsNetworkError extends ClientNetworkError {}
// For 5XX HTTP-alike errors
export class ServerNetworkError extends CustomError {}
// 500
export class InternalServerNetworkError extends ServerNetworkError {}
// 501
export class NotImplementedNetworkError extends ServerNetworkError {}
// 503
export class ServerUnavailableNetworkError extends ServerNetworkError {}
// 504
export class GatewayTimeoutNetworkError extends ServerNetworkError {}
// Application-level errors
export class FetchError extends CustomError {}
export class FetchWarning extends CustomError {}
export class CreateError extends CustomError {}
export class UpgradeError extends CustomError {}
export class RollbackError extends CustomError {}
export class DeleteError extends CustomError {}
export type DeploymentEvent = "install" | "upgrade";
export interface IReceivePackagesActionPayload {
response: GetAvailablePackageSummariesResponse;
paginationToken: string;
}
export interface IPackageState {
isFetching: boolean;
hasFinishedFetching: boolean;
nextPageToken: string;
selected: {
error?: FetchError | Error;
availablePackageDetail?: AvailablePackageDetail;
pkgVersion?: string;
appVersion?: string;
versions: PackageAppVersion[];
readme?: string;
readmeError?: string;
values?: string;
schema?: JSONSchemaType<any>;
};
items: AvailablePackageSummary[];
categories: string[];
size: number;
}
export interface IServiceSpec {
ports: IPort[];
clusterIP: string;
type: string;
}
export interface IServiceStatus {
loadBalancer: {
ingress?: Array<{ ip?: string; hostname?: string }>;
};
}
export interface IPort {
name: string;
port: number;
protocol: string;
targetPort: string;
nodePort: string;
}
export interface IHTTPIngressPath {
path: string;
}
export interface IIngressHTTP {
paths: IHTTPIngressPath[];
}
export interface IIngressRule {
host: string;
http: IIngressHTTP;
}
export interface IIngressTLS {
hosts: string[];
}
export interface IIngressSpec {
rules: IIngressRule[];
tls?: IIngressTLS[];
backend?: {
serviceName: string;
servicePort: number;
};
}
export interface IResourceMetadata {
name: string;
namespace: string;
annotations: { [key: string]: string };
ownerReferences?: Array<{
apiVersion: string;
blockOwnerDeletion: string;
kind: string;
name: string;
uid: string;
}>;
creationTimestamp: string;
selfLink: string;
resourceVersion: string;
deletionTimestamp?: string;
uid: string;
}
export interface IResource {
apiVersion: string;
kind: string;
type: string;
spec: any;
status: any;
metadata: IResourceMetadata;
}
export interface ISecret {
apiVersion: string;
kind: string;
type: string;
data: { [s: string]: string };
metadata: IResourceMetadata;
}
export interface IPackageManifestChannel {
name: string;
currentCSV: string;
currentCSVDesc: {
annotations: {
"alm-examples": string;
capabilities: string;
categories: string;
certified: string;
containerImage: string;
createdAt: string;
description: string;
repository: string;
support: string;
};
description: string;
displayName: string;
provider: {
name: string;
};
version: string;
installModes: [
{ supported: boolean; type: "OwnNamespace" },
{ supported: boolean; type: "SingleNamespace" },
{ supported: boolean; type: "MultiNamespace" },
{ supported: boolean; type: "AllNamespaces" },
];
customresourcedefinitions: {
owned: Array<{
description: string;
displayName: string;
kind: string;
name: string;
version: string;
}>;
};
};
}
export interface IPackageManifestStatus {
catalogSource: string;
catalogSourceDisplayName: string;
catalogSourceNamespace: string;
catalogSourcePublisher: string;
provider: {
name: string;
};
defaultChannel: string;
channels: IPackageManifestChannel[];
}
export interface IPackageManifest extends IResource {
status: IPackageManifestStatus;
}
export interface IClusterServiceVersionCRDResource {
kind: string;
name: string;
version: string;
}
export interface IClusterServiceVersionCRD {
description: string;
displayName: string;
kind: string;
name: string;
version: string;
resources: IClusterServiceVersionCRDResource[];
specDescriptors: Array<{
description: string;
displayName: string;
path: string;
"x-descriptors": string[];
}>;
statusDescriptors: Array<{
description: string;
displayName: string;
path: string;
"x-descriptors": string[];
}>;
}
export interface IClusterServiceVersionSpec {
apiservicedefinitions: any;
customresourcedefinitions: {
owned?: IClusterServiceVersionCRD[];
};
description: string;
displayName: string;
icon: Array<{
base64data: string;
mediatype: string;
}>;
install: any;
installModes: [
{ supported: boolean; type: "OwnNamespace" },
{ supported: boolean; type: "SingleNamespace" },
{ supported: boolean; type: "MultiNamespace" },
{ supported: boolean; type: "AllNamespaces" },
];
keywords: string[];
labels: any;
links: Array<{
name: string;
url: string;
}>;
maintainers: Array<{
email: string;
name: string;
}>;
maturity: string;
provider: {
name: string;
};
selector: any;
version: string;
}
export interface IClusterServiceVersion extends IResource {
spec: IClusterServiceVersionSpec;
}
export interface IPkgRepositoryFilter {
jq: string;
variables?: { [key: string]: string };
}
export interface IInstalledPackageState {
isFetching: boolean;
error?: FetchError | CreateError | UpgradeError | RollbackError | DeleteError;
items: InstalledPackageDetail[];
listOverview?: InstalledPackageSummary[];
selected?: CustomInstalledPackageDetail;
// TODO(agamez): add tests for this new state field
selectedDetails?: AvailablePackageDetail;
resourceRefs?: ResourceRef[];
}
export interface IStoreState {
router: RouterState;
apps: IInstalledPackageState;
auth: IAuthState;
packages: IPackageState;
config: IConfigState;
kube: IKubeState;
repos: IPackageRepositoryState;
clusters: IClustersState;
operators: IOperatorsState;
}
interface IK8sResource {
apiVersion: string;
kind: string;
}
/** @see https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#lists-and-simple-kinds */
export interface IK8sList<I, M> extends IK8sResource {
items: I[];
metadata?: {
resourceVersion?: string;
selfLink?: string; // Not in docs, but seems to exist everywhere
} & M;
}
export interface IRBACRole {
apiGroup: string;
namespace?: string;
clusterWide?: boolean;
resource: string;
verbs: string[];
}
export interface IKubeItem<T> {
isFetching: boolean;
item?: T;
error?: Error;
}
export interface IKind {
apiVersion: string;
plural: string;
namespaced: boolean;
}
export interface IKubeState {
items: { [s: string]: IKubeItem<IResource | IK8sList<IResource, {}>> };
subscriptions: { [s: string]: Subscription };
// TODO(minelson): Remove kinds and kindsError once the operator support is
// removed from the dashboard or replaced with a plugin.
kinds: { [kind: string]: IKind };
kindsError?: Error;
}
// We extend the JSONSchema properties to include the default/deployed values as well as
// other useful information for rendering each param in the UI
export type IBasicFormParam = JSONSchemaType<any> & {
key: string;
title: string;
hasProperties: boolean;
params?: IBasicFormParam[];
enum?: string[];
defaultValue: any;
deployedValue: any;
currentValue: any;
schema: JSONSchemaType<any>;
isCustomComponent?: boolean;
};
// this type is encapsulating the result of a schema validation,
// including the errors returned by the library
export interface IAjvValidateResult {
valid: boolean;
errors: ErrorObject[] | null | undefined;
}
// type for handling Helm installed packages, which includes the revision,
// a field not present in other packages
export interface CustomInstalledPackageDetail extends InstalledPackageDetail {
revision: number;
}
// enum for the type of package repository storage
export enum RepositoryStorageTypes {
PACKAGE_REPOSITORY_STORAGE_HELM = "helm",
PACKAGE_REPOSITORY_STORAGE_OCI = "oci",
PACKAGE_REPOSITORY_STORAGE_CARVEL_INLINE = "inline",
PACKAGE_REPOSITORY_STORAGE_CARVEL_IMAGE = "image",
PACKAGE_REPOSITORY_STORAGE_CARVEL_IMGPKGBUNDLE = "imgpkgBundle",
PACKAGE_REPOSITORY_STORAGE_CARVEL_HTTP = "http",
PACKAGE_REPOSITORY_STORAGE_CARVEL_GIT = "git",
}
// enum for the current plugin names
export enum PluginNames {
PACKAGES_HELM = "helm.packages",
PACKAGES_FLUX = "fluxv2.packages",
PACKAGES_KAPP = "kapp_controller.packages",
}
// type holding the data used in the package repository form
export interface IPkgRepoFormData {
authMethod: PackageRepositoryAuth_PackageRepositoryAuthType;
// kubeapps-managed secrets
authHeader: string; // used if type == PACKAGE_REPOSITORY_AUTH_TYPE_BEARER || type == PACKAGE_REPOSITORY_AUTH_TYPE_AUTHORIZATION_HEADER
basicAuth: UsernamePassword; // used if type == PACKAGE_REPOSITORY_AUTH_TYPE_BASIC_AUTH
dockerRegCreds: DockerCredentials; // used if type == PACKAGE_REPOSITORY_AUTH_TYPE_DOCKER_CONFIG_JSON
sshCreds: SshCredentials; // used if type == PACKAGE_REPOSITORY_AUTH_TYPE_SSH
opaqueCreds: OpaqueCredentials; // used if type == PACKAGE_REPOSITORY_AUTH_TYPE_OPAQUE
tlsCertKey: TlsCertKey; // used if type == PACKAGE_REPOSITORY_AUTH_TYPE_TLS
// user-managed secrets
secretAuthName: string;
secretTLSName: string;
// rest of the parameters
customCA: string;
description: string;
interval: string;
name: string;
passCredentials: boolean;
plugin: Plugin;
skipTLS: boolean;
type: string;
url: string;
// add more types if necessary
customDetail?: Partial<
| HelmPackageRepositoryCustomDetail
| KappControllerPackageRepositoryCustomDetail
| FluxPackageRepositoryCustomDetail
>;
namespace: string;
isNamespaceScoped: boolean;
}
// Holds data about the permissions on any resource
export interface IResourcePermission {
list: boolean;
create: boolean;
update: boolean;
delete: boolean;
namespace: string;
}
export interface IPackageRepositoryPermission {
global?: IResourcePermission;
namespaced: IResourcePermission;
plugin: Plugin;
}