mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add suspend/resume button for CronJobs (#1860)
Signed-off-by: vshakirova <vshakirova@mirantis.com>
This commit is contained in:
parent
b7d97e6b5b
commit
fd63f2f4e3
@ -18,7 +18,7 @@ export class ApiManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getApiByKind(kind: string, apiVersion: string) {
|
getApiByKind(kind: string, apiVersion: string) {
|
||||||
return Array.from(this.apis.values()).find((api) => api.kind === kind && api.apiVersion === apiVersion);
|
return Array.from(this.apis.values()).find((api) => api.kind === kind && api.apiVersionWithGroup === apiVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerApi(apiBase: string, api: KubeApi) {
|
registerApi(apiBase: string, api: KubeApi) {
|
||||||
|
|||||||
@ -5,6 +5,38 @@ import { formatDuration } from "../../utils/formatDuration";
|
|||||||
import { autobind } from "../../utils";
|
import { autobind } from "../../utils";
|
||||||
import { KubeApi } from "../kube-api";
|
import { KubeApi } from "../kube-api";
|
||||||
|
|
||||||
|
export class CronJobApi extends KubeApi<CronJob> {
|
||||||
|
suspend(params: { namespace: string; name: string }) {
|
||||||
|
return this.request.patch(this.getUrl(params), {
|
||||||
|
data: {
|
||||||
|
spec: {
|
||||||
|
suspend: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/strategic-merge-patch+json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
resume(params: { namespace: string; name: string }) {
|
||||||
|
return this.request.patch(this.getUrl(params), {
|
||||||
|
data: {
|
||||||
|
spec: {
|
||||||
|
suspend: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/strategic-merge-patch+json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class CronJob extends KubeObject {
|
export class CronJob extends KubeObject {
|
||||||
static kind = "CronJob";
|
static kind = "CronJob";
|
||||||
@ -90,8 +122,12 @@ export class CronJob extends KubeObject {
|
|||||||
|
|
||||||
return day > daysInMonth[month - 1];
|
return day > daysInMonth[month - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSuspend() {
|
||||||
|
return this.spec.suspend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cronJobApi = new KubeApi({
|
export const cronJobApi = new CronJobApi({
|
||||||
objectConstructor: CronJob,
|
objectConstructor: CronJob,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import "./cronjobs.scss";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { RouteComponentProps } from "react-router";
|
import { RouteComponentProps } from "react-router";
|
||||||
import { CronJob } from "../../api/endpoints/cron-job.api";
|
import { CronJob, cronJobApi } from "../../api/endpoints/cron-job.api";
|
||||||
import { MenuItem } from "../menu";
|
import { MenuItem } from "../menu";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { cronJobStore } from "./cronjob.store";
|
import { cronJobStore } from "./cronjob.store";
|
||||||
@ -15,6 +15,8 @@ import { KubeObjectListLayout } from "../kube-object";
|
|||||||
import { CronJobTriggerDialog } from "./cronjob-trigger-dialog";
|
import { CronJobTriggerDialog } from "./cronjob-trigger-dialog";
|
||||||
import { kubeObjectMenuRegistry } from "../../../extensions/registries/kube-object-menu-registry";
|
import { kubeObjectMenuRegistry } from "../../../extensions/registries/kube-object-menu-registry";
|
||||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||||
|
import { ConfirmDialog } from "../confirm-dialog/confirm-dialog";
|
||||||
|
import { Notifications } from "../notifications/notifications";
|
||||||
|
|
||||||
enum sortBy {
|
enum sortBy {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -80,10 +82,50 @@ export function CronJobMenu(props: KubeObjectMenuProps<CronJob>) {
|
|||||||
const { object, toolbar } = props;
|
const { object, toolbar } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem onClick={() => CronJobTriggerDialog.open(object)}>
|
<>
|
||||||
<Icon material="play_circle_filled" title={`Trigger`} interactive={toolbar}/>
|
<MenuItem onClick={() => CronJobTriggerDialog.open(object)}>
|
||||||
<span className="title">Trigger</span>
|
<Icon material="play_circle_filled" title={`Trigger`} interactive={toolbar}/>
|
||||||
</MenuItem>
|
<span className="title">Trigger</span>
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
|
{object.isSuspend() ?
|
||||||
|
<MenuItem onClick={() => ConfirmDialog.open({
|
||||||
|
ok: async () => {
|
||||||
|
try {
|
||||||
|
await cronJobApi.resume({ namespace: object.getNs(), name: object.getName() });
|
||||||
|
} catch (err) {
|
||||||
|
Notifications.error(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
labelOk: `Resume`,
|
||||||
|
message: (
|
||||||
|
<p>
|
||||||
|
Resume CronJob <b>{object.getName()}</b>?
|
||||||
|
</p>),
|
||||||
|
})}>
|
||||||
|
<Icon material="play_circle_outline" title={`Resume`} interactive={toolbar}/>
|
||||||
|
<span className="title">Resume</span>
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
|
: <MenuItem onClick={() => ConfirmDialog.open({
|
||||||
|
ok: async () => {
|
||||||
|
try {
|
||||||
|
await cronJobApi.suspend({ namespace: object.getNs(), name: object.getName() });
|
||||||
|
} catch (err) {
|
||||||
|
Notifications.error(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
labelOk: `Suspend`,
|
||||||
|
message: (
|
||||||
|
<p>
|
||||||
|
Suspend CronJob <b>{object.getName()}</b>?
|
||||||
|
</p>),
|
||||||
|
})}>
|
||||||
|
<Icon material="pause_circle_filled" title={`Suspend`} interactive={toolbar}/>
|
||||||
|
<span className="title">Suspend</span>
|
||||||
|
</MenuItem>
|
||||||
|
}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user