-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
replicasets.store.ts
56 lines (45 loc) · 1.6 KB
/
replicasets.store.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
import { observable } from "mobx";
import { autobind } from "../../utils";
import { KubeObjectStore } from "../../kube-object.store";
import { Deployment, IPodMetrics, podsApi, ReplicaSet, replicaSetApi } from "../../api/endpoints";
import { podsStore } from "../+workloads-pods/pods.store";
import { apiManager } from "../../api/api-manager";
import { PodStatus } from "../../api/endpoints/pods.api";
@autobind()
export class ReplicaSetStore extends KubeObjectStore<ReplicaSet> {
api = replicaSetApi;
@observable metrics: IPodMetrics = null;
async loadMetrics(replicaSet: ReplicaSet) {
const pods = this.getChildPods(replicaSet);
this.metrics = await podsApi.getMetrics(pods, replicaSet.getNs(), "");
}
getChildPods(replicaSet: ReplicaSet) {
return podsStore.getPodsByOwnerId(replicaSet.getId());
}
getStatuses(replicaSets: ReplicaSet[]) {
const status = { failed: 0, pending: 0, running: 0 };
replicaSets.forEach(replicaSet => {
const pods = this.getChildPods(replicaSet);
if (pods.some(pod => pod.getStatus() === PodStatus.FAILED)) {
status.failed++;
}
else if (pods.some(pod => pod.getStatus() === PodStatus.PENDING)) {
status.pending++;
}
else {
status.running++;
}
});
return status;
}
getReplicaSetsByOwner(deployment: Deployment) {
return this.items.filter(replicaSet =>
!!replicaSet.getOwnerRefs().find(owner => owner.uid === deployment.getId())
);
}
reset() {
this.metrics = null;
}
}
export const replicaSetStore = new ReplicaSetStore();
apiManager.registerStore(replicaSetStore);