Skip to content

Commit 12871f7

Browse files
shuangkunAlbeeSoagilgur5
committed
fix: correct pod names for inline templates. Fixes argoproj#12895 (argoproj#13261)
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)
1 parent 38bb8d3 commit 12871f7

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

test/e2e/workflow_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,42 @@ spec:
188188
})
189189
}
190190

191+
func (s *WorkflowSuite) TestWorkflowInlinePodName() {
192+
s.Given().Workflow(`
193+
apiVersion: argoproj.io/v1alpha1
194+
kind: Workflow
195+
metadata:
196+
generateName: steps-inline-
197+
labels:
198+
workflows.argoproj.io/test: "true"
199+
spec:
200+
entrypoint: main
201+
templates:
202+
- name: main
203+
steps:
204+
- - name: a
205+
inline:
206+
container:
207+
image: argoproj/argosay:v2
208+
command:
209+
- cowsay
210+
args:
211+
- "foo"
212+
`).
213+
When().
214+
SubmitWorkflow().
215+
WaitForWorkflow(fixtures.ToBeCompleted, time.Minute*1).
216+
Then().
217+
ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
218+
assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase)
219+
}).
220+
ExpectWorkflowNode(func(status v1alpha1.NodeStatus) bool {
221+
return strings.Contains(status.Name, "a")
222+
}, func(t *testing.T, status *v1alpha1.NodeStatus, pod *apiv1.Pod) {
223+
assert.NotContains(t, pod.Name, "--")
224+
})
225+
}
226+
191227
func TestWorkflowSuite(t *testing.T) {
192228
suite.Run(t, new(WorkflowSuite))
193229
}

workflow/util/pod_name.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"hash/fnv"
66
"os"
7-
"strings"
87

98
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
109
"github.com/argoproj/argo-workflows/v3/workflow/common"
@@ -58,8 +57,8 @@ func GeneratePodName(workflowName, nodeName, templateName, nodeID string, versio
5857
}
5958

6059
prefix := workflowName
61-
if !strings.Contains(nodeName, ".inline") {
62-
prefix = fmt.Sprintf("%s-%s", workflowName, templateName)
60+
if templateName != "" {
61+
prefix = fmt.Sprintf("%s-%s", prefix, templateName)
6362
}
6463
prefix = ensurePodNamePrefixLength(prefix)
6564

workflow/util/pod_name_v2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ func TestPodNameV2(t *testing.T) {
5252

5353
h = fnv.New32a()
5454
_, _ = h.Write([]byte("stp.inline"))
55-
name = GeneratePodName(shortWfName, "stp.inline", longTemplateName, nodeID, PodNameV2)
55+
name = GeneratePodName(shortWfName, "stp.inline", "", nodeID, PodNameV2)
5656
assert.Equal(t, fmt.Sprintf("wfname-%v", h.Sum32()), name)
5757
}

0 commit comments

Comments
 (0)