mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
fix(configs): update unused badge logic [EE-6608] (#11500)
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
9b6779515e
commit
14a365045d
12 changed files with 590 additions and 113 deletions
|
@ -13,9 +13,10 @@ import {
|
|||
getApplicationRevisionList,
|
||||
} from './application.service';
|
||||
import type { AppKind, Application, ApplicationPatch } from './types';
|
||||
import { deletePod, getNamespacePods } from './pod.service';
|
||||
import { deletePod } from './pod.service';
|
||||
import { getNamespaceHorizontalPodAutoscalers } from './autoscaling.service';
|
||||
import { applicationIsKind, matchLabelsToLabelSelectorValue } from './utils';
|
||||
import { getNamespacePods } from './usePods';
|
||||
|
||||
const queryKeys = {
|
||||
applicationsForCluster: (environmentId: EnvironmentId) =>
|
||||
|
|
|
@ -15,7 +15,7 @@ import { isFulfilled } from '@/portainer/helpers/promise-utils';
|
|||
|
||||
import { parseKubernetesAxiosError } from '../axiosError';
|
||||
|
||||
import { getPod, getNamespacePods, patchPod } from './pod.service';
|
||||
import { getPod, patchPod } from './pod.service';
|
||||
import { filterRevisionsByOwnerUid, getNakedPods } from './utils';
|
||||
import {
|
||||
AppKind,
|
||||
|
@ -24,6 +24,7 @@ import {
|
|||
ApplicationPatch,
|
||||
} from './types';
|
||||
import { appRevisionAnnotation } from './constants';
|
||||
import { getNamespacePods } from './usePods';
|
||||
|
||||
// This file contains services for Kubernetes apps/v1 resources (Deployments, DaemonSets, StatefulSets)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Pod, PodList } from 'kubernetes-types/core/v1';
|
||||
import { Pod } from 'kubernetes-types/core/v1';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
@ -7,37 +7,6 @@ import { parseKubernetesAxiosError } from '../axiosError';
|
|||
|
||||
import { ApplicationPatch } from './types';
|
||||
|
||||
export async function getNamespacePods(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
labelSelector?: string
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<PodList>(
|
||||
buildUrl(environmentId, namespace),
|
||||
{
|
||||
params: {
|
||||
labelSelector,
|
||||
},
|
||||
}
|
||||
);
|
||||
const items = (data.items || []).map(
|
||||
(pod) =>
|
||||
<Pod>{
|
||||
...pod,
|
||||
kind: 'Pod',
|
||||
apiVersion: data.apiVersion,
|
||||
}
|
||||
);
|
||||
return items;
|
||||
} catch (e) {
|
||||
throw parseKubernetesAxiosError(
|
||||
e,
|
||||
`Unable to retrieve pods in namespace '${namespace}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPod<T extends Pod | string = Pod>(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
|
|
77
app/react/kubernetes/applications/useCronJobs.ts
Normal file
77
app/react/kubernetes/applications/useCronJobs.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
import { CronJob, CronJobList } from 'kubernetes-types/batch/v1';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import axios from '@/portainer/services/axios';
|
||||
|
||||
import { parseKubernetesAxiosError } from '../axiosError';
|
||||
|
||||
const queryKeys = {
|
||||
cronJobsForCluster: (environmentId: EnvironmentId) => [
|
||||
'environments',
|
||||
environmentId,
|
||||
'kubernetes',
|
||||
'cronjobs',
|
||||
],
|
||||
};
|
||||
|
||||
export function useCronJobs(
|
||||
environmentId: EnvironmentId,
|
||||
namespaces?: string[]
|
||||
) {
|
||||
return useQuery(
|
||||
queryKeys.cronJobsForCluster(environmentId),
|
||||
() => getCronJobsForCluster(environmentId, namespaces),
|
||||
{
|
||||
...withError('Unable to retrieve CronJobs'),
|
||||
enabled: !!namespaces?.length,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getCronJobsForCluster(
|
||||
environmentId: EnvironmentId,
|
||||
namespaceNames?: string[]
|
||||
) {
|
||||
if (!namespaceNames) {
|
||||
return [];
|
||||
}
|
||||
const jobs = await Promise.all(
|
||||
namespaceNames.map((namespace) =>
|
||||
getNamespaceCronJobs(environmentId, namespace)
|
||||
)
|
||||
);
|
||||
return jobs.flat();
|
||||
}
|
||||
|
||||
export async function getNamespaceCronJobs(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
labelSelector?: string
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<CronJobList>(
|
||||
`/endpoints/${environmentId}/kubernetes/apis/batch/v1/namespaces/${namespace}/cronjobs`,
|
||||
{
|
||||
params: {
|
||||
labelSelector,
|
||||
},
|
||||
}
|
||||
);
|
||||
const items = (data.items || []).map(
|
||||
(cronJob) =>
|
||||
<CronJob>{
|
||||
...cronJob,
|
||||
kind: 'CronJob',
|
||||
apiVersion: data.apiVersion,
|
||||
}
|
||||
);
|
||||
return items;
|
||||
} catch (e) {
|
||||
throw parseKubernetesAxiosError(
|
||||
e,
|
||||
`Unable to retrieve CronJobs in namespace '${namespace}'`
|
||||
);
|
||||
}
|
||||
}
|
74
app/react/kubernetes/applications/useJobs.ts
Normal file
74
app/react/kubernetes/applications/useJobs.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
import { Job, JobList } from 'kubernetes-types/batch/v1';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import axios from '@/portainer/services/axios';
|
||||
|
||||
import { parseKubernetesAxiosError } from '../axiosError';
|
||||
|
||||
const queryKeys = {
|
||||
jobsForCluster: (environmentId: EnvironmentId) => [
|
||||
'environments',
|
||||
environmentId,
|
||||
'kubernetes',
|
||||
'jobs',
|
||||
],
|
||||
};
|
||||
|
||||
export function useJobs(environmentId: EnvironmentId, namespaces?: string[]) {
|
||||
return useQuery(
|
||||
queryKeys.jobsForCluster(environmentId),
|
||||
() => getJobsForCluster(environmentId, namespaces),
|
||||
{
|
||||
...withError('Unable to retrieve Jobs'),
|
||||
enabled: !!namespaces?.length,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getJobsForCluster(
|
||||
environmentId: EnvironmentId,
|
||||
namespaceNames?: string[]
|
||||
) {
|
||||
if (!namespaceNames) {
|
||||
return [];
|
||||
}
|
||||
const jobs = await Promise.all(
|
||||
namespaceNames.map((namespace) =>
|
||||
getNamespaceJobs(environmentId, namespace)
|
||||
)
|
||||
);
|
||||
return jobs.flat();
|
||||
}
|
||||
|
||||
export async function getNamespaceJobs(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
labelSelector?: string
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<JobList>(
|
||||
`/endpoints/${environmentId}/kubernetes/apis/batch/v1/namespaces/${namespace}/jobs`,
|
||||
{
|
||||
params: {
|
||||
labelSelector,
|
||||
},
|
||||
}
|
||||
);
|
||||
const items = (data.items || []).map(
|
||||
(job) =>
|
||||
<Job>{
|
||||
...job,
|
||||
kind: 'Job',
|
||||
apiVersion: data.apiVersion,
|
||||
}
|
||||
);
|
||||
return items;
|
||||
} catch (e) {
|
||||
throw parseKubernetesAxiosError(
|
||||
e,
|
||||
`Unable to retrieve Jobs in namespace '${namespace}'`
|
||||
);
|
||||
}
|
||||
}
|
74
app/react/kubernetes/applications/usePods.ts
Normal file
74
app/react/kubernetes/applications/usePods.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Pod, PodList } from 'kubernetes-types/core/v1';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import axios from '@/portainer/services/axios';
|
||||
|
||||
import { parseKubernetesAxiosError } from '../axiosError';
|
||||
|
||||
const queryKeys = {
|
||||
podsForCluster: (environmentId: EnvironmentId) => [
|
||||
'environments',
|
||||
environmentId,
|
||||
'kubernetes',
|
||||
'pods',
|
||||
],
|
||||
};
|
||||
|
||||
export function usePods(environemtId: EnvironmentId, namespaces?: string[]) {
|
||||
return useQuery(
|
||||
queryKeys.podsForCluster(environemtId),
|
||||
() => getPodsForCluster(environemtId, namespaces),
|
||||
{
|
||||
...withError('Unable to retrieve Pods'),
|
||||
enabled: !!namespaces?.length,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPodsForCluster(
|
||||
environmentId: EnvironmentId,
|
||||
namespaceNames?: string[]
|
||||
) {
|
||||
if (!namespaceNames) {
|
||||
return [];
|
||||
}
|
||||
const pods = await Promise.all(
|
||||
namespaceNames.map((namespace) =>
|
||||
getNamespacePods(environmentId, namespace)
|
||||
)
|
||||
);
|
||||
return pods.flat();
|
||||
}
|
||||
|
||||
export async function getNamespacePods(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
labelSelector?: string
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<PodList>(
|
||||
`/endpoints/${environmentId}/kubernetes/api/v1/namespaces/${namespace}/pods`,
|
||||
{
|
||||
params: {
|
||||
labelSelector,
|
||||
},
|
||||
}
|
||||
);
|
||||
const items = (data.items || []).map(
|
||||
(pod) =>
|
||||
<Pod>{
|
||||
...pod,
|
||||
kind: 'Pod',
|
||||
apiVersion: data.apiVersion,
|
||||
}
|
||||
);
|
||||
return items;
|
||||
} catch (e) {
|
||||
throw parseKubernetesAxiosError(
|
||||
e,
|
||||
`Unable to retrieve Pods in namespace '${namespace}'`
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue