From 12871f7524e2e973b3d1f214efcdd4b203bf2120 Mon Sep 17 00:00:00 2001 From: shuangkun tian <72060326+shuangkun@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:29:56 +0800 Subject: [PATCH] fix: correct pod names for inline templates. Fixes #12895 (#13261) Signed-off-by: shuangkun Signed-off-by: Anton Gilgur <4970083+agilgur5@users.noreply.github.com> Signed-off-by: Anton Gilgur Co-authored-by: AlbeeSo Co-authored-by: Anton Gilgur <4970083+agilgur5@users.noreply.github.com> Co-authored-by: Anton Gilgur (cherry picked from commit 3f9b992cdddb09633ef329c13eab1823ca6e5f3e) --- test/e2e/workflow_test.go | 36 +++++++++++++++++++++++++++++++ workflow/util/pod_name.go | 5 ++--- workflow/util/pod_name_v2_test.go | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/test/e2e/workflow_test.go b/test/e2e/workflow_test.go index e10ca1558b81..7f1bc3f59b6c 100644 --- a/test/e2e/workflow_test.go +++ b/test/e2e/workflow_test.go @@ -188,6 +188,42 @@ spec: }) } +func (s *WorkflowSuite) TestWorkflowInlinePodName() { + s.Given().Workflow(` +apiVersion: argoproj.io/v1alpha1 +kind: Workflow +metadata: + generateName: steps-inline- + labels: + workflows.argoproj.io/test: "true" +spec: + entrypoint: main + templates: + - name: main + steps: + - - name: a + inline: + container: + image: argoproj/argosay:v2 + command: + - cowsay + args: + - "foo" +`). + When(). + SubmitWorkflow(). + WaitForWorkflow(fixtures.ToBeCompleted, time.Minute*1). + Then(). + ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) { + assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase) + }). + ExpectWorkflowNode(func(status v1alpha1.NodeStatus) bool { + return strings.Contains(status.Name, "a") + }, func(t *testing.T, status *v1alpha1.NodeStatus, pod *apiv1.Pod) { + assert.NotContains(t, pod.Name, "--") + }) +} + func TestWorkflowSuite(t *testing.T) { suite.Run(t, new(WorkflowSuite)) } diff --git a/workflow/util/pod_name.go b/workflow/util/pod_name.go index b230d3777cc5..a124f377325f 100644 --- a/workflow/util/pod_name.go +++ b/workflow/util/pod_name.go @@ -4,7 +4,6 @@ import ( "fmt" "hash/fnv" "os" - "strings" "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/argoproj/argo-workflows/v3/workflow/common" @@ -58,8 +57,8 @@ func GeneratePodName(workflowName, nodeName, templateName, nodeID string, versio } prefix := workflowName - if !strings.Contains(nodeName, ".inline") { - prefix = fmt.Sprintf("%s-%s", workflowName, templateName) + if templateName != "" { + prefix = fmt.Sprintf("%s-%s", prefix, templateName) } prefix = ensurePodNamePrefixLength(prefix) diff --git a/workflow/util/pod_name_v2_test.go b/workflow/util/pod_name_v2_test.go index e27d11f5338e..bed796147841 100644 --- a/workflow/util/pod_name_v2_test.go +++ b/workflow/util/pod_name_v2_test.go @@ -52,6 +52,6 @@ func TestPodNameV2(t *testing.T) { h = fnv.New32a() _, _ = h.Write([]byte("stp.inline")) - name = GeneratePodName(shortWfName, "stp.inline", longTemplateName, nodeID, PodNameV2) + name = GeneratePodName(shortWfName, "stp.inline", "", nodeID, PodNameV2) assert.Equal(t, fmt.Sprintf("wfname-%v", h.Sum32()), name) }