mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { observable } from "mobx";
|
|
import { autobind } from "../../utils";
|
|
import { KubeObjectStore } from "../../kube-object.store";
|
|
import { IPodMetrics, podsApi, PodStatus, StatefulSet, statefulSetApi } from "../../api/endpoints";
|
|
import { podsStore } from "../+workloads-pods/pods.store";
|
|
import { apiManager } from "../../api/api-manager";
|
|
import { addLensKubeObjectMenuItem } from "../../../extensions/registries";
|
|
import { OpenWith, Remove, Update } from "@material-ui/icons";
|
|
import { editResourceTab } from "../dock/edit-resource.store";
|
|
import { StatefulSetScaleDialog } from "./statefulset-scale-dialog";
|
|
|
|
@autobind()
|
|
export class StatefulSetStore extends KubeObjectStore<StatefulSet> {
|
|
api = statefulSetApi;
|
|
@observable metrics: IPodMetrics = null;
|
|
|
|
async loadMetrics(statefulSet: StatefulSet) {
|
|
const pods = this.getChildPods(statefulSet);
|
|
|
|
this.metrics = await podsApi.getMetrics(pods, statefulSet.getNs(), "");
|
|
}
|
|
|
|
getChildPods(statefulSet: StatefulSet) {
|
|
return podsStore.getPodsByOwnerId(statefulSet.getId());
|
|
}
|
|
|
|
getStatuses(statefulSets: StatefulSet[]) {
|
|
const status = { failed: 0, pending: 0, running: 0 };
|
|
|
|
statefulSets.forEach(statefulSet => {
|
|
const pods = this.getChildPods(statefulSet);
|
|
|
|
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;
|
|
}
|
|
|
|
reset() {
|
|
this.metrics = null;
|
|
}
|
|
}
|
|
|
|
export const statefulSetStore = new StatefulSetStore();
|
|
apiManager.registerStore(statefulSetStore);
|
|
|
|
addLensKubeObjectMenuItem({
|
|
Object: StatefulSet,
|
|
Icon: Remove,
|
|
onClick: sa => statefulSetStore.remove(sa),
|
|
text: "Delete",
|
|
});
|
|
|
|
addLensKubeObjectMenuItem({
|
|
Object: StatefulSet,
|
|
Icon: Update,
|
|
onClick: editResourceTab,
|
|
text: "Update",
|
|
});
|
|
|
|
addLensKubeObjectMenuItem({
|
|
Object: StatefulSet,
|
|
apiVersions: ["apps/v1"],
|
|
text: "Scale",
|
|
Icon: OpenWith,
|
|
onClick: StatefulSetScaleDialog.open,
|
|
});
|