You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/kubernetes/cluster/kubernetesEndpoint.service.ts

36 lines
1.1 KiB

import { EndpointsList } from 'kubernetes-types/core/v1';
import { useQuery } from '@tanstack/react-query';
import axios from '@/portainer/services/axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { withError } from '@/react-tools/react-query';
import { parseKubernetesAxiosError } from '../axiosError';
async function getKubernetesEndpoints(environmentId: EnvironmentId) {
try {
const { data: endpointsList } = await axios.get<EndpointsList>(
`/endpoints/${environmentId}/kubernetes/api/v1/endpoints`
);
return endpointsList.items;
} catch (e) {
throw parseKubernetesAxiosError(e, 'Unable to retrieve endpoints');
}
}
export function useKubernetesEndpointsQuery(
environmentId: EnvironmentId,
options?: { autoRefreshRate?: number }
) {
return useQuery(
['environments', environmentId, 'kubernetes', 'endpoints'],
() => getKubernetesEndpoints(environmentId),
{
...withError('Unable to retrieve Kubernetes endpoints'),
refetchInterval() {
return options?.autoRefreshRate ?? false;
},
}
);
}