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 networksQuery = useNetworksForSelector();
|
||||||
|
|
||||||
const fromContainerQuery = useContainer(environmentId, from, {
|
const fromContainerQuery = useContainer(environmentId, from, nodeName, {
|
||||||
enabled: !submitting,
|
enabled: !submitting,
|
||||||
});
|
});
|
||||||
|
|
||||||
const runningContainersQuery = useContainers(environmentId, {
|
const runningContainersQuery = useContainers(environmentId, {
|
||||||
enabled: !!from,
|
enabled: !!from,
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,10 +8,10 @@ import { Link } from '@@/Link';
|
||||||
|
|
||||||
export function LogView() {
|
export function LogView() {
|
||||||
const {
|
const {
|
||||||
params: { endpointId: environmentId, id: containerId },
|
params: { endpointId: environmentId, id: containerId, nodeName },
|
||||||
} = useCurrentStateAndParams();
|
} = useCurrentStateAndParams();
|
||||||
|
|
||||||
const containerQuery = useContainer(environmentId, containerId);
|
const containerQuery = useContainer(environmentId, containerId, nodeName);
|
||||||
if (!containerQuery.data || containerQuery.isLoading) {
|
if (!containerQuery.data || containerQuery.isLoading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
MountPoint,
|
MountPoint,
|
||||||
NetworkSettings,
|
NetworkSettings,
|
||||||
} from 'docker-types/generated/1.41';
|
} from 'docker-types/generated/1.41';
|
||||||
|
import { RawAxiosRequestHeaders } from 'axios';
|
||||||
|
|
||||||
import { PortainerResponse } from '@/react/docker/types';
|
import { PortainerResponse } from '@/react/docker/types';
|
||||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||||
|
@ -75,11 +76,15 @@ export interface ContainerJSON {
|
||||||
export function useContainer(
|
export function useContainer(
|
||||||
environmentId: EnvironmentId,
|
environmentId: EnvironmentId,
|
||||||
containerId?: ContainerId,
|
containerId?: ContainerId,
|
||||||
|
nodeName?: string,
|
||||||
{ enabled }: { enabled?: boolean } = {}
|
{ enabled }: { enabled?: boolean } = {}
|
||||||
) {
|
) {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
containerId ? queryKeys.container(environmentId, containerId) : [],
|
containerId ? queryKeys.container(environmentId, containerId) : [],
|
||||||
() => (containerId ? getContainer(environmentId, containerId) : undefined),
|
() =>
|
||||||
|
containerId
|
||||||
|
? getContainer(environmentId, containerId, nodeName)
|
||||||
|
: undefined,
|
||||||
{
|
{
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Failure',
|
title: 'Failure',
|
||||||
|
@ -103,11 +108,19 @@ export type ContainerResponse = PortainerResponse<ContainerJSON>;
|
||||||
|
|
||||||
async function getContainer(
|
async function getContainer(
|
||||||
environmentId: EnvironmentId,
|
environmentId: EnvironmentId,
|
||||||
containerId: ContainerId
|
containerId: ContainerId,
|
||||||
|
nodeName?: string
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
const headers: RawAxiosRequestHeaders = {};
|
||||||
|
|
||||||
|
if (nodeName) {
|
||||||
|
headers['X-PortainerAgent-Target'] = nodeName;
|
||||||
|
}
|
||||||
|
|
||||||
const { data } = await axios.get<ContainerResponse>(
|
const { data } = await axios.get<ContainerResponse>(
|
||||||
urlBuilder(environmentId, containerId, 'json')
|
urlBuilder(environmentId, containerId, 'json'),
|
||||||
|
{ headers }
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in New Issue