Skip to content

Commit

Permalink
fix: correct pod names for inline templates. Fixes #12895 (#13261)
Browse files Browse the repository at this point in the history
Signed-off-by: shuangkun <[email protected]>
Signed-off-by: Anton Gilgur <[email protected]>
Signed-off-by: Anton Gilgur <[email protected]>
Co-authored-by: AlbeeSo <[email protected]>
Co-authored-by: Anton Gilgur <[email protected]>
Co-authored-by: Anton Gilgur <[email protected]>
(cherry picked from commit 3f9b992)
  • Loading branch information
shuangkun authored and agilgur5 committed Jul 30, 2024
1 parent 38bb8d3 commit 12871f7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
36 changes: 36 additions & 0 deletions test/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
5 changes: 2 additions & 3 deletions workflow/util/pod_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion workflow/util/pod_name_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 12871f7

Please sign in to comment.