From d7b412eccc878dcfbf1c02448d7438af5ad80b3a Mon Sep 17 00:00:00 2001 From: cmeng Date: Thu, 23 May 2024 09:13:49 +1200 Subject: [PATCH] fix(container): replace container using correct node name EE-7066 (#11847) --- .../containers/CreateView/useCreateMutation.tsx | 12 ++++++++---- app/react/docker/containers/queries/container.ts | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/react/docker/containers/CreateView/useCreateMutation.tsx b/app/react/docker/containers/CreateView/useCreateMutation.tsx index 7d4228678..9b931428b 100644 --- a/app/react/docker/containers/CreateView/useCreateMutation.tsx +++ b/app/react/docker/containers/CreateView/useCreateMutation.tsx @@ -161,7 +161,7 @@ async function replace({ ); await removeContainer(environment.Id, oldContainer.Id, { - nodeName: values.nodeName, + nodeName: oldContainer.NodeName, }); } @@ -178,13 +178,17 @@ async function renameAndCreate( ) { let renamed = false; try { - await stopContainerIfNeeded(environmentId, oldContainer, nodeName); + await stopContainerIfNeeded( + environmentId, + oldContainer, + oldContainer.NodeName + ); await renameContainer( environmentId, oldContainer.Id, `${oldContainer.Names[0]}-old`, - { nodeName } + { nodeName: oldContainer.NodeName } ); renamed = true; @@ -192,7 +196,7 @@ async function renameAndCreate( } catch (e) { if (renamed) { await renameContainer(environmentId, oldContainer.Id, name, { - nodeName, + nodeName: oldContainer.NodeName, }); } throw e; diff --git a/app/react/docker/containers/queries/container.ts b/app/react/docker/containers/queries/container.ts index 872c41ab7..e0cad153e 100644 --- a/app/react/docker/containers/queries/container.ts +++ b/app/react/docker/containers/queries/container.ts @@ -10,7 +10,10 @@ import { import { RawAxiosRequestHeaders } from 'axios'; import { PortainerResponse } from '@/react/docker/types'; -import axios, { parseAxiosError } from '@/portainer/services/axios'; +import axios, { + agentTargetHeader, + parseAxiosError, +} from '@/portainer/services/axios'; import { ContainerId } from '@/react/docker/containers/types'; import { EnvironmentId } from '@/react/portainer/environments/types'; import { queryClient } from '@/react-tools/react-query'; @@ -115,7 +118,7 @@ async function getContainer( const headers: RawAxiosRequestHeaders = {}; if (nodeName) { - headers['X-PortainerAgent-Target'] = nodeName; + headers[agentTargetHeader] = nodeName; } const { data } = await axios.get(