/
event.ts
101 lines (83 loc) · 2.29 KB
/
event.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
import { ResourceClasses } from '.';
import { apiFactoryWithNamespace } from './apiProxy';
import { request } from './apiProxy';
import { KubeMetadata, KubeObject, makeKubeObject } from './cluster';
export interface KubeEvent {
type: string;
reason: string;
message: string;
metadata: KubeMetadata;
involvedObject: {
kind: string;
namespace: string;
name: string;
uid: string;
apiVersion: string;
resourceVersion: string;
fieldPath: string;
};
[otherProps: string]: any;
}
class Event extends makeKubeObject<KubeEvent>('Event') {
static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'events');
get spec() {
return this.getValue('spec');
}
get status() {
return this.getValue('status');
}
get involvedObject() {
return this.getValue('involvedObject');
}
get type() {
return this.getValue('type');
}
get reason() {
return this.getValue('reason');
}
get message() {
return this.getValue('message');
}
static async objectEvents(object: KubeObject) {
const namespace = object.metadata.namespace;
const name = object.metadata.name;
const objectKind = object.kind;
let path = '/api/v1/events';
const fieldSelector: { [key: string]: string } = {
'involvedObject.kind': objectKind,
'involvedObject.name': name,
};
if (namespace) {
path = `/api/v1/namespaces/${namespace}/events`;
fieldSelector['involvedObject.namespace'] = namespace;
}
const queryParams = {
fieldSelector: Object.keys(fieldSelector)
.map(function (k) {
return `${k}=${fieldSelector[k]}`;
})
.join(','),
limit: '500',
};
const response = await request(path, {}, true, true, queryParams);
return response.items;
}
get involvedObjectInstance(): KubeObject | null {
if (!this.involvedObject) {
return null;
}
const InvolvedObjectClass = ResourceClasses[this.involvedObject.kind];
let objInstance: KubeObject | null = null;
if (!!InvolvedObjectClass) {
objInstance = new InvolvedObjectClass({
kind: this.involvedObject.kind,
metadata: {
name: this.involvedObject.name,
namespace: this.involvedObject.namespace,
},
});
}
return objInstance;
}
}
export default Event;