mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(kubernetes): move react codebase [EE-3349] (#7953)
This commit is contained in:
parent
2868da296a
commit
77c29ff87e
33 changed files with 18 additions and 21 deletions
27
app/react/kubernetes/networks/services/queries.ts
Normal file
27
app/react/kubernetes/networks/services/queries.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { error as notifyError } from '@/portainer/services/notifications';
|
||||
|
||||
import { getServices } from './service';
|
||||
import { Service } from './types';
|
||||
|
||||
export function useServices(environmentId: EnvironmentId, namespace: string) {
|
||||
return useQuery(
|
||||
[
|
||||
'environments',
|
||||
environmentId,
|
||||
'kubernetes',
|
||||
'namespaces',
|
||||
namespace,
|
||||
'services',
|
||||
],
|
||||
() =>
|
||||
namespace ? getServices(environmentId, namespace) : ([] as Service[]),
|
||||
{
|
||||
onError: (err) => {
|
||||
notifyError('Failure', err as Error, 'Unable to get services');
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
23
app/react/kubernetes/networks/services/service.ts
Normal file
23
app/react/kubernetes/networks/services/service.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { Service } from './types';
|
||||
|
||||
export async function getServices(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string
|
||||
) {
|
||||
try {
|
||||
const { data: services } = await axios.get<Service[]>(
|
||||
buildUrl(environmentId, namespace)
|
||||
);
|
||||
return services;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to retrieve services');
|
||||
}
|
||||
}
|
||||
|
||||
function buildUrl(environmentId: EnvironmentId, namespace: string) {
|
||||
const url = `kubernetes/${environmentId}/namespaces/${namespace}/services`;
|
||||
return url;
|
||||
}
|
33
app/react/kubernetes/networks/services/types.ts
Normal file
33
app/react/kubernetes/networks/services/types.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
export interface Port {
|
||||
Name: string;
|
||||
Protocol: string;
|
||||
Port: number;
|
||||
TargetPort: number;
|
||||
NodePort?: number;
|
||||
}
|
||||
|
||||
export interface IngressIP {
|
||||
IP: string;
|
||||
}
|
||||
|
||||
export interface LoadBalancer {
|
||||
Ingress: IngressIP[];
|
||||
}
|
||||
|
||||
export interface Status {
|
||||
LoadBalancer: LoadBalancer;
|
||||
}
|
||||
|
||||
export interface Service {
|
||||
Annotations?: Document;
|
||||
CreationTimestamp?: string;
|
||||
Labels?: Document;
|
||||
Name: string;
|
||||
Namespace: string;
|
||||
UID: string;
|
||||
AllocateLoadBalancerNodePorts?: boolean;
|
||||
Ports: Port[];
|
||||
Selector?: Document;
|
||||
Type: string;
|
||||
Status?: Status;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue