-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: respect workflowDefaults
when validating workflows. Fixes #10946. Fixes #11465
#13642
Conversation
…argoproj#10946 Submitting a workflow with a variable reference that points to a label or annotation that comes from `workflowDefaults` will always fail with an error like the following: ``` msg="Failed to submit workflow: rpc error: code = InvalidArgument desc = templates.whalesay-template: failed to resolve {{workflow.labels.arg-name}} ``` This is happening because the workflow is merged with `workflowDefaults` at runtime by https://github.com/argoproj/argo-workflows/blob/2dac1266b446d059ac6df78afe3d09a6ddb3af4b/workflow/controller/controller.go#L1375 which happens before the workflow is validated by `ValidateWorkflow()`. Therefore, we need to explicitly pass in the `workflowDefaults` (if any) to `ValidateWorkflow()` so it can merge in any labels/annotations before validating templates. Signed-off-by: Mason Malone <[email protected]>
Test failures seem due to flakiness. For the failure in
|
Signed-off-by: Mason Malone <[email protected]>
Signed-off-by: Mason Malone <[email protected]>
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.
Thank you!
Test failures are unrelated and should go away when #13660 is merged |
@@ -3931,7 +3931,7 @@ func (woc *wfOperationCtx) setExecWorkflow(ctx context.Context) error { | |||
// Validate the execution wfSpec | |||
err := waitutil.Backoff(retry.DefaultRetry, | |||
func() (bool, error) { | |||
validationErr := validate.ValidateWorkflow(wftmplGetter, cwftmplGetter, woc.wf, validateOpts) | |||
validationErr := validate.ValidateWorkflow(wftmplGetter, cwftmplGetter, woc.wf, woc.controller.Config.WorkflowDefaults, validateOpts) |
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.
In the Controller, this is normally handled via setWorkflowDefaults
above (as you mentioned in your description) and the difference between woc.wf
and woc.execWf
.
That's probably why this worked in direct submissions but not cron ones or server ones, if I had to guess. Also the cron part means this doesn't just affect the server, if I'm not mistaken -- we may want to change the title if so
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 not sure what you mean by "direct submissions", but if you mean submitting workflows via a POST
request to /api/v1/workflows
, then that too is broken. The E2E tests I updated in this PR checks for that. I created a branch of main
that cherry-picks just the tests so you can see for yourself: main...MasonM:argo-workflows:test-main-10946
Run make TestSubmitWorkflowTemplateWorkflowMetadataSubstitution
and you should see the test fail with the following error:
workflow-template-submittable-v5xfw : Failed invalid spec: templates.whalesay-template: failed to resolve {{workflow.labels.default-label}}
Did not find node
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 not sure what you mean by "direct submissions"
Sorry I meant through the k8s API / kubectl
"directly". Maybe the word "created" makes more sense in that case than "submitted", since the latter is generally used in the CLI & API?
Versus "server ones" I meant as through the API that are ofc failing. I meant them as "indirect" since they go through an intermediary, the Server.
"cron ones" I noted bc they do go through the same SubmitWorkflow
method that runs validation, as this PR shows, meaning it would be affecting the (cron) Controller too, not just the Server
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.
Oh, okay. Yes, it looks like Cron workflows are affected too, so I updated the title to remove the (server)
scope.
workflowDefaults
when validating workflows. Fixes #10946. Fixes #11465
Signed-off-by: Mason Malone <[email protected]>
workflowDefaults
when validating workflows. Fixes #10946. Fixes #11465workflowDefaults
when validating workflows. Fixes #10946. Fixes #11465
Signed-off-by: Mason Malone <[email protected]>
Fixes #10946 and Fixes #11465
Motivation
Submitting a workflow with a variable reference that points to a label or annotation that comes from
workflowDefaults
will always fail with an error like the following:Modifications
This error is happening here:
argo-workflows/workflow/validate/validate.go
Line 705 in 2dac126
The
scope
argument comes fromValidateWorkflow()
, which isn't aware ofworkflowDefaults
, and therefore doesn't include any labels/annotations defined therein. This is purely a validation issue, sinceworkflowDefaults
is merged into the workflow at runtime byargo-workflows/workflow/controller/controller.go
Line 1375 in 2dac126
This updates
ValidateWorkflow()
to take in theworkflowDefaults
(if any) and use that to populate the context with any labels/annotations, which is ultimately used to populate thescope
argument. Most of the changes in this PR is just passing around theworkflowDefaults
so that it can ultimately get passed toValidateWorkflow()
.Verification
I opted to modify the existing
TestSubmitWorkflowTemplateWorkflowMetadataSubstitution
E2E test to verify this is working. I could've added a new test, but considering how slow the CI pipeline already is, that seems suboptimal.