mirror of https://github.com/portainer/portainer
fix(container): specify node name when get a container EE-6981 (#11748)
parent
8a81d95253
commit
5f8fd99fe8
|
@ -66,9 +66,10 @@ export function useInitialValues(submitting: boolean, isWindows: boolean) {
|
|||
|
||||
const networksQuery = useNetworksForSelector();
|
||||
|
||||
const fromContainerQuery = useContainer(environmentId, from, {
|
||||
const fromContainerQuery = useContainer(environmentId, from, nodeName, {
|
||||
enabled: !submitting,
|
||||
});
|
||||
|
||||
const runningContainersQuery = useContainers(environmentId, {
|
||||
enabled: !!from,
|
||||
});
|
||||
|
|
|
@ -8,10 +8,10 @@ import { Link } from '@@/Link';
|
|||
|
||||
export function LogView() {
|
||||
const {
|
||||
params: { endpointId: environmentId, id: containerId },
|
||||
params: { endpointId: environmentId, id: containerId, nodeName },
|
||||
} = useCurrentStateAndParams();
|
||||
|
||||
const containerQuery = useContainer(environmentId, containerId);
|
||||
const containerQuery = useContainer(environmentId, containerId, nodeName);
|
||||
if (!containerQuery.data || containerQuery.isLoading) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
MountPoint,
|
||||
NetworkSettings,
|
||||
} from 'docker-types/generated/1.41';
|
||||
import { RawAxiosRequestHeaders } from 'axios';
|
||||
|
||||
import { PortainerResponse } from '@/react/docker/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
@ -75,11 +76,15 @@ export interface ContainerJSON {
|
|||
export function useContainer(
|
||||
environmentId: EnvironmentId,
|
||||
containerId?: ContainerId,
|
||||
nodeName?: string,
|
||||
{ enabled }: { enabled?: boolean } = {}
|
||||
) {
|
||||
return useQuery(
|
||||
containerId ? queryKeys.container(environmentId, containerId) : [],
|
||||
() => (containerId ? getContainer(environmentId, containerId) : undefined),
|
||||
() =>
|
||||
containerId
|
||||
? getContainer(environmentId, containerId, nodeName)
|
||||
: undefined,
|
||||
{
|
||||
meta: {
|
||||
title: 'Failure',
|
||||
|
@ -103,11 +108,19 @@ export type ContainerResponse = PortainerResponse<ContainerJSON>;
|
|||
|
||||
async function getContainer(
|
||||
environmentId: EnvironmentId,
|
||||
containerId: ContainerId
|
||||
containerId: ContainerId,
|
||||
nodeName?: string
|
||||
) {
|
||||
try {
|
||||
const headers: RawAxiosRequestHeaders = {};
|
||||
|
||||
if (nodeName) {
|
||||
headers['X-PortainerAgent-Target'] = nodeName;
|
||||
}
|
||||
|
||||
const { data } = await axios.get<ContainerResponse>(
|
||||
urlBuilder(environmentId, containerId, 'json')
|
||||
urlBuilder(environmentId, containerId, 'json'),
|
||||
{ headers }
|
||||
);
|
||||
return data;
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue