mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
feat(kubernetes): support for jobs and cron jobs - r8s-182 (#260)
Co-authored-by: James Carppe <85850129+jamescarppe@users.noreply.github.com> Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io> Co-authored-by: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Co-authored-by: Oscar Zhou <100548325+oscarzhou-portainer@users.noreply.github.com> Co-authored-by: Yajith Dayarathna <yajith.dayarathna@portainer.io> Co-authored-by: LP B <xAt0mZ@users.noreply.github.com> Co-authored-by: oscarzhou <oscar.zhou@portainer.io> Co-authored-by: testA113 <aliharriss1995@gmail.com>
This commit is contained in:
parent
24fdb1f600
commit
d32b0f8b7e
51 changed files with 1786 additions and 22 deletions
|
@ -0,0 +1,6 @@
|
|||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
export const queryKeys = {
|
||||
list: (environmentId: EnvironmentId) =>
|
||||
['environments', environmentId, 'kubernetes', 'cronJobs'] as const,
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { CronJob } from '../types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export function useCronJobs(
|
||||
environmentId: EnvironmentId,
|
||||
options?: { refetchInterval?: number; enabled?: boolean }
|
||||
) {
|
||||
return useQuery(
|
||||
queryKeys.list(environmentId),
|
||||
async () => getAllCronJobs(environmentId),
|
||||
{
|
||||
...withGlobalError('Unable to get cron jobs'),
|
||||
refetchInterval() {
|
||||
return options?.refetchInterval ?? false;
|
||||
},
|
||||
enabled: options?.enabled,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function getAllCronJobs(environmentId: EnvironmentId) {
|
||||
try {
|
||||
const { data: cronJobs } = await axios.get<CronJob[]>(
|
||||
`kubernetes/${environmentId}/cron_jobs`
|
||||
);
|
||||
|
||||
return cronJobs;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, 'Unable to get cron jobs');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { withGlobalError, withInvalidate } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export function useDeleteCronJobsMutation(environmentId: EnvironmentId) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(deleteCronJob, {
|
||||
...withInvalidate(queryClient, [queryKeys.list(environmentId)]),
|
||||
...withGlobalError('Unable to delete Cron Jobs'),
|
||||
});
|
||||
}
|
||||
|
||||
type NamespaceCronJobsMap = Record<string, string[]>;
|
||||
|
||||
export async function deleteCronJob({
|
||||
environmentId,
|
||||
data,
|
||||
}: {
|
||||
environmentId: EnvironmentId;
|
||||
data: NamespaceCronJobsMap;
|
||||
}) {
|
||||
try {
|
||||
return await axios.post(
|
||||
`kubernetes/${environmentId}/cron_jobs/delete`,
|
||||
data
|
||||
);
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, `Unable to delete Cron Jobs`);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue