Lens restructure (#540)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman authored and GitHub committed 2020-06-30 14:35:16 +03:00
1 parent e810eab39f
commit b7974827d2
786 files changed
+14567 -24066

No files matched your search

@@ -0,0 +1,55 @@
import { observable } from "mobx";
import { Deployment, deploymentApi, IPodMetrics, podsApi, PodStatus } from "../../api/endpoints";
import { KubeObjectStore } from "../../kube-object.store";
import { autobind } from "../../utils";
import { podsStore } from "../+workloads-pods/pods.store";
import { apiManager } from "../../api/api-manager";
@autobind()
export class DeploymentStore extends KubeObjectStore<Deployment> {
api = deploymentApi
@observable metrics: IPodMetrics = null;
protected sortItems(items: Deployment[]) {
return super.sortItems(items, [
item => item.getReplicas(),
], "desc");
}
loadMetrics(deployment: Deployment) {
const pods = this.getChildPods(deployment);
return podsApi.getMetrics(pods, deployment.getNs(), "").then(metrics =>
this.metrics = metrics
);
}
getStatuses(deployments?: Deployment[]) {
const status = { failed: 0, pending: 0, running: 0 }
deployments.forEach(deployment => {
const pods = this.getChildPods(deployment);
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
}
getChildPods(deployment: Deployment) {
return podsStore
.getByLabel(deployment.getTemplateLabels())
.filter(pod => pod.getNs() === deployment.getNs())
}
reset() {
this.metrics = null;
}
}
export const deploymentStore = new DeploymentStore();
apiManager.registerStore(deploymentApi, deploymentStore);