-
Notifications
You must be signed in to change notification settings - Fork 3.4k
test: refactor E2E examples tests and fix Makefile
#14094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This rewrites `hack/test-examples.sh` in Go to make those tests easier to debug and facilitate testing more complex scenarios, like the VAP added in argoproj#14045 The new tests do strict validation, which caught a bug in `examples/webhdfs-input-output-artifacts.yaml`: ``` $ kubectl apply -f examples/webhdfs-input-output-artifacts.yaml Error from server (BadRequest): error when creating "examples/webhdfs-input-output-artifacts.yaml": Workflow in version "v1alpha1" cannot be handled as a Workflow: strict decoding error: unknown field "spec.templates[0].outputs.artifacts[0].overwrite" ``` $ make test-examples <SNIP> examples_test.go:28: Error parsing ../../examples/webhdfs-input-output-artifacts.yaml: strict decoding error: unknown field "spec.templates[0].outputs.artifacts[0].overwrite" === FAIL: ExamplesSuite/TestExampleWorkflows FAIL github.com/argoproj/argo-workflows/v3/test/e2e 1.580s FAIL make: *** [Makefile:609: test-examples] Error 1 ``` Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
|
/retest |
| echo "Checking for banned images..." | ||
| grep -lR 'workflows.argoproj.io/test' examples/* | while read f ; do | ||
| echo " - $f" | ||
| test 0 == $(grep -o 'image: .*' $f | grep -cv 'argoproj/argosay:v2\|python:alpine3.6\|busybox') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering what are you thoughts on not including this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is redundant, since we're already checking the image when Given.Workflow() is called:
argo-workflows/test/e2e/fixtures/given.go
Lines 86 to 139 in b2a2c8f
| func (g *Given) checkImages(wf interface{}) { | |
| g.t.Helper() | |
| var defaultImage string | |
| var templates []wfv1.Template | |
| switch baseTemplate := wf.(type) { | |
| case *wfv1.Workflow: | |
| if baseTemplate.Spec.TemplateDefaults != nil && baseTemplate.Spec.TemplateDefaults.Container != nil && baseTemplate.Spec.TemplateDefaults.Container.Image != "" { | |
| defaultImage = baseTemplate.Spec.TemplateDefaults.Container.Image | |
| templates = baseTemplate.Spec.Templates | |
| } | |
| case *wfv1.WorkflowTemplate: | |
| if baseTemplate.Spec.TemplateDefaults != nil && baseTemplate.Spec.TemplateDefaults.Container != nil && baseTemplate.Spec.TemplateDefaults.Container.Image != "" { | |
| defaultImage = baseTemplate.Spec.TemplateDefaults.Container.Image | |
| templates = baseTemplate.Spec.Templates | |
| } | |
| case *wfv1.CronWorkflow: | |
| if baseTemplate.Spec.WorkflowSpec.TemplateDefaults != nil && baseTemplate.Spec.WorkflowSpec.TemplateDefaults.Container != nil && baseTemplate.Spec.WorkflowSpec.TemplateDefaults.Container.Image != "" { | |
| defaultImage = baseTemplate.Spec.WorkflowSpec.TemplateDefaults.Container.Image | |
| templates = baseTemplate.Spec.WorkflowSpec.Templates | |
| } | |
| default: | |
| g.t.Fatalf("Unsupported checkImage workflow type: %s", wf) | |
| } | |
| // discouraged | |
| discouraged := func(image string) bool { | |
| return image == "python:alpine3.6" | |
| } | |
| // Using an arbitrary image will result in slow and flakey tests as we can't really predict when they'll be | |
| // downloaded or evicted. To keep tests fast and reliable you must use allowed images. | |
| allowed := func(image string) bool { | |
| return strings.Contains(image, "argoexec:") || image == "argoproj/argosay:v1" || image == "argoproj/argosay:v2" || discouraged(image) | |
| } | |
| for _, t := range templates { | |
| container := t.Container | |
| if container != nil { | |
| var image string | |
| if container.Image != "" { | |
| image = container.Image | |
| } else { | |
| image = defaultImage | |
| } | |
| if !allowed(image) { | |
| g.t.Fatalf("image not allowed in tests: %s", image) | |
| } | |
| // (⎈ |docker-desktop:argo)➜ ~ time docker run --rm argoproj/argosay:v2 | |
| // docker run --rm argoproj/argosay˜:v2 0.21s user 0.10s system 16% cpu 1.912 total | |
| // docker run --rm argoproj/argosay:v1 0.17s user 0.08s system 31% cpu 0.784 total | |
| if discouraged(image) { | |
| _, _ = fmt.Println(color.Ize(color.Yellow, "DISCOURAGED IMAGE: "+g.t.Name()+" is using "+image)) | |
| } | |
| } | |
| } | |
| } |
but now that I look again, that code is actually broken: it's only checking the images if the workflow defines TemplateDefaults, since otherwise, templates will be an empty array. I think this was a bug introduced 2 years ago in #10784.
I fixed the bug so that it's properly verifying images again, but that caused a ton of tests to fail, since there were a lot of tests introduced since then that used a banned image. I went through and fixed everything. While I was at it, I changed everything under test/ that was using the deprecated python:alpine3.6 image to use argoproj/argosay:v2 instead, which removes the need for the deprecated image check.
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
| command: [sh, -c] | ||
| args: ["sleep 1; cat /upload/testUpload; cat /upload/testUpload.txt > /upload/testUpload.txt"] | ||
| image: alpine:3.18.4 | ||
| args: ["sleep 1; cat /upload/testInput.txt > /upload/testUpload.txt"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was a little tricky, because the behavior of sh in alpine is actually different than sh in argoproj/argosay:v2, because the former allows cat /upload/testUpload.txt > /upload/testUpload.txt and the latter does not:
docker run --entrypoint=/bin/sh --rm alpine:3.18.4 -xc 'touch /tmp/foo; cat /tmp/foo > /tmp/foo'; echo $?
+ touch /tmp/foo
+ cat /tmp/foo
0
$ docker run --entrypoint=/bin/sh --rm argoproj/argosay:v2 -xc 'touch /tmp/foo; cat /tmp/foo > /tmp/foo'; echo $?
+ touch /tmp/foo
+ cat /tmp/foo
cat: /tmp/foo: input file is output file
1
I think the intention of this was to copy the input artifact to the output, so I updated it to do so
|
/retest |
tczhao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Motivation
This rewrites
hack/test-examples.shin Go to make those tests easier to debug and facilitate testing more complex scenarios, like the VAP added in #14045This also fixes a
Makefilebug that @panicboat reported in #14090 (reply in thread). The expression$(shell [ $PROFILE = plugins ] && echo false || echo true)isn't escaping the$sign, which causesmaketo substitute the value of thePvariable, if any. The official docs recommend using parentheses:Modifications
KubectlApplyhelper to reduce duplicationhack/test-example.shwithtest/e2e/examples_test.go. The new tests do strict validation, which caught a bug inexamples/webhdfs-input-output-artifacts.yaml:MakefilebugVerification
Ran E2E tests.