mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
e810eab39f
commit
b7974827d2
786 files changed
+14567
-24066
No files matched your search
@@ -0,0 +1,19 @@
|
||||
|
||||
.CronJobDetails {
|
||||
.job {
|
||||
.title {
|
||||
margin-top: $margin * 2;
|
||||
margin-bottom: $margin;
|
||||
|
||||
a {
|
||||
color: $colorInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.conditions {
|
||||
.Badge {
|
||||
@include job-condition-bgs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import "./cronjob-details.scss";
|
||||
|
||||
import React from "react";
|
||||
import kebabCase from "lodash/kebabCase";
|
||||
import { observer } from "mobx-react";
|
||||
import { Trans } from "@lingui/macro";
|
||||
import { DrawerItem, DrawerTitle } from "../drawer";
|
||||
import { Badge } from "../badge/badge";
|
||||
import { jobStore } from "../+workloads-jobs/job.store";
|
||||
import { Link } from "react-router-dom";
|
||||
import { KubeEventDetails } from "../+events/kube-event-details";
|
||||
import { cronJobStore } from "./cronjob.store";
|
||||
import { getDetailsUrl } from "../../navigation";
|
||||
import { KubeObjectDetailsProps } from "../kube-object";
|
||||
import { CronJob, cronJobApi, Job } from "../../api/endpoints";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<CronJob> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class CronJobDetails extends React.Component<Props> {
|
||||
async componentDidMount() {
|
||||
if (!jobStore.isLoaded) {
|
||||
jobStore.loadAll();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { object: cronJob } = this.props;
|
||||
if (!cronJob) return null;
|
||||
const childJobs = jobStore.getJobsByOwner(cronJob)
|
||||
return (
|
||||
<div className="CronJobDetails">
|
||||
<KubeObjectMeta object={cronJob}/>
|
||||
<DrawerItem name={<Trans>Schedule</Trans>}>
|
||||
{cronJob.isNeverRun() ? (
|
||||
<>
|
||||
<Trans>never</Trans> ({cronJob.getSchedule()})
|
||||
</>
|
||||
) : cronJob.getSchedule()}
|
||||
</DrawerItem>
|
||||
<DrawerItem name={<Trans>Active</Trans>}>
|
||||
{cronJobStore.getActiveJobsNum(cronJob)}
|
||||
</DrawerItem>
|
||||
<DrawerItem name={<Trans>Suspend</Trans>}>
|
||||
{cronJob.getSuspendFlag()}
|
||||
</DrawerItem>
|
||||
<DrawerItem name={<Trans>Last schedule</Trans>}>
|
||||
{cronJob.getLastScheduleTime()}
|
||||
</DrawerItem>
|
||||
{childJobs.length > 0 &&
|
||||
<>
|
||||
<DrawerTitle title={<Trans>Jobs</Trans>}/>
|
||||
{childJobs.map((job: Job) => {
|
||||
const selectors = job.getSelectors()
|
||||
const condition = job.getCondition()
|
||||
return (
|
||||
<div className="job" key={job.getId()}>
|
||||
<div className="title">
|
||||
<Link to={getDetailsUrl(job.selfLink)}>
|
||||
{job.getName()}
|
||||
</Link>
|
||||
</div>
|
||||
<DrawerItem name={<Trans>Condition</Trans>} className="conditions" labelsOnly>
|
||||
{condition && (
|
||||
<Badge
|
||||
label={condition.type}
|
||||
className={kebabCase(condition.type)}
|
||||
/>
|
||||
)}
|
||||
</DrawerItem>
|
||||
<DrawerItem name={<Trans>Selector</Trans>} labelsOnly>
|
||||
{
|
||||
selectors.map(label => <Badge key={label} label={label}/>)
|
||||
}
|
||||
</DrawerItem>
|
||||
</div>
|
||||
)})
|
||||
}
|
||||
</>
|
||||
}
|
||||
<KubeEventDetails object={cronJob}/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
apiManager.registerViews(cronJobApi, {
|
||||
Details: CronJobDetails,
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { autobind } from "../../utils";
|
||||
import { CronJob, cronJobApi } from "../../api/endpoints/cron-job.api";
|
||||
import { jobStore } from "../+workloads-jobs/job.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
|
||||
@autobind()
|
||||
export class CronJobStore extends KubeObjectStore<CronJob> {
|
||||
api = cronJobApi
|
||||
|
||||
getStatuses(cronJobs?: CronJob[]) {
|
||||
const status = { failed: 0, running: 0 }
|
||||
cronJobs.forEach(cronJob => {
|
||||
if (cronJob.spec.suspend) {
|
||||
status.failed++
|
||||
}
|
||||
else {
|
||||
status.running++
|
||||
}
|
||||
})
|
||||
return status
|
||||
}
|
||||
|
||||
getActiveJobsNum(cronJob: CronJob) {
|
||||
// Active jobs are jobs without any condition 'Complete' nor 'Failed'
|
||||
const jobs = jobStore.getJobsByOwner(cronJob);
|
||||
if (!jobs.length) return 0;
|
||||
return jobs.filter(job => !job.getCondition()).length;
|
||||
}
|
||||
}
|
||||
|
||||
export const cronJobStore = new CronJobStore();
|
||||
apiManager.registerStore(cronJobApi, cronJobStore);
|
||||
@@ -0,0 +1,7 @@
|
||||
.CronJobs {
|
||||
.TableCell {
|
||||
&.warning {
|
||||
@include table-cell-warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import "./cronjobs.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { RouteComponentProps } from "react-router";
|
||||
import { Trans } from "@lingui/macro";
|
||||
import { CronJob, cronJobApi } from "../../api/endpoints/cron-job.api";
|
||||
import { cronJobStore } from "./cronjob.store";
|
||||
import { jobStore } from "../+workloads-jobs/job.store";
|
||||
import { eventStore } from "../+events/event.store";
|
||||
import { KubeObjectMenu, KubeObjectMenuProps } from "../kube-object/kube-object-menu";
|
||||
import { ICronJobsRouteParams } from "../+workloads";
|
||||
import { KubeObjectListLayout } from "../kube-object";
|
||||
import { KubeEventIcon } from "../+events/kube-event-icon";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
|
||||
enum sortBy {
|
||||
name = "name",
|
||||
namespace = "namespace",
|
||||
suspend = "suspend",
|
||||
active = "active",
|
||||
lastSchedule = "schedule",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
interface Props extends RouteComponentProps<ICronJobsRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class CronJobs extends React.Component<Props> {
|
||||
render() {
|
||||
return (
|
||||
<KubeObjectListLayout
|
||||
className="CronJobs" store={cronJobStore}
|
||||
dependentStores={[jobStore, eventStore]}
|
||||
sortingCallbacks={{
|
||||
[sortBy.name]: (cronJob: CronJob) => cronJob.getName(),
|
||||
[sortBy.namespace]: (cronJob: CronJob) => cronJob.getNs(),
|
||||
[sortBy.suspend]: (cronJob: CronJob) => cronJob.getSuspendFlag(),
|
||||
[sortBy.active]: (cronJob: CronJob) => cronJobStore.getActiveJobsNum(cronJob),
|
||||
[sortBy.lastSchedule]: (cronJob: CronJob) => cronJob.getLastScheduleTime(),
|
||||
[sortBy.age]: (cronJob: CronJob) => cronJob.metadata.creationTimestamp,
|
||||
}}
|
||||
searchFilters={[
|
||||
(cronJob: CronJob) => cronJob.getSearchFields(),
|
||||
(cronJob: CronJob) => cronJob.getSchedule(),
|
||||
]}
|
||||
renderHeaderTitle={<Trans>Cron Jobs</Trans>}
|
||||
renderTableHeader={[
|
||||
{ title: <Trans>Name</Trans>, className: "name", sortBy: sortBy.name },
|
||||
{ className: "warning" },
|
||||
{ title: <Trans>Namespace</Trans>, className: "namespace", sortBy: sortBy.namespace },
|
||||
{ title: <Trans>Schedule</Trans>, className: "schedule" },
|
||||
{ title: <Trans>Suspend</Trans>, className: "suspend", sortBy: sortBy.suspend },
|
||||
{ title: <Trans>Active</Trans>, className: "active", sortBy: sortBy.active },
|
||||
{ title: <Trans>Last schedule</Trans>, className: "last-schedule", sortBy: sortBy.lastSchedule },
|
||||
{ title: <Trans>Age</Trans>, className: "age", sortBy: sortBy.age },
|
||||
]}
|
||||
renderTableContents={(cronJob: CronJob) => [
|
||||
cronJob.getName(),
|
||||
<KubeEventIcon object={cronJob} filterEvents={events => {
|
||||
if (!cronJob.isNeverRun()) return events;
|
||||
return events.filter(event => event.reason != "FailedNeedsStart");
|
||||
}
|
||||
}/>,
|
||||
cronJob.getNs(),
|
||||
cronJob.isNeverRun() ? <Trans>never</Trans> : cronJob.getSchedule(),
|
||||
cronJob.getSuspendFlag(),
|
||||
cronJobStore.getActiveJobsNum(cronJob),
|
||||
cronJob.getLastScheduleTime(),
|
||||
cronJob.getAge(),
|
||||
]}
|
||||
renderItemMenu={(item: CronJob) => {
|
||||
return <CronJobMenu object={item}/>
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function CronJobMenu(props: KubeObjectMenuProps<CronJob>) {
|
||||
return (
|
||||
<KubeObjectMenu {...props}/>
|
||||
)
|
||||
}
|
||||
|
||||
apiManager.registerViews(cronJobApi, {
|
||||
Menu: CronJobMenu,
|
||||
})
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./cronjobs"
|
||||
export * from "./cronjob-details"
|
||||
Reference in new issue
Block a user