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
ArgoWorkflow trigger with submit-from operation throws errors even though it submits the template #3033
Comments
Nicarim
changed the title
ArgoWorkflow trigger submit-from throws errors even though it submits the template
ArgoWorkflow trigger with submit-from operation throws errors even though it submits the template
Feb 22, 2024
This is my really crude attempt to fix this: Index: sensors/triggers/argo-workflow/argo-workflow.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/sensors/triggers/argo-workflow/argo-workflow.go b/sensors/triggers/argo-workflow/argo-workflow.go
--- a/sensors/triggers/argo-workflow/argo-workflow.go (revision aa351e4b601198b10d58fc8d83edfa877fcd64b8)
+++ b/sensors/triggers/argo-workflow/argo-workflow.go (date 1708694760203)
@@ -16,7 +16,9 @@
package argo_workflow
import (
+ "bytes"
"context"
+ "encoding/json"
"fmt"
"os"
"os/exec"
@@ -170,7 +172,7 @@
return nil, fmt.Errorf("invalid kind %s", kind)
}
fromArg := fmt.Sprintf("%s/%s", kind, name)
- cmd = exec.Command("argo", "-n", namespace, "submit", "--from", fromArg)
+ cmd = exec.Command("argo", "-n", namespace, "submit", "--from", fromArg, "--output", "json")
case v1alpha1.Resubmit:
cmd = exec.Command("argo", "-n", namespace, "resubmit", name)
case v1alpha1.Resume:
@@ -186,13 +188,42 @@
default:
return nil, fmt.Errorf("unknown operation type %s", string(op))
}
-
- cmd.Stdout = os.Stdout
+ var cmdStdout bytes.Buffer
+ if op == v1alpha1.SubmitFrom {
+ cmd.Stdout = &cmdStdout
+ } else {
+ cmd.Stdout = os.Stdout
+ }
cmd.Stderr = os.Stderr
cmd.Args = append(cmd.Args, trigger.Template.ArgoWorkflow.Args...)
if err := t.cmdRunner(cmd); err != nil {
return nil, fmt.Errorf("failed to execute %s command for workflow %s, %w", string(op), name, err)
}
+ if op == v1alpha1.SubmitFrom {
+ var cmdJson map[string]interface{}
+ if err := json.Unmarshal(cmdStdout.Bytes(), &cmdJson); err != nil {
+ return nil, fmt.Errorf("failed to get json output from submit --from command, returned json was %s", cmdStdout.String())
+ }
+ var metadata map[string]interface{}
+ if x, found := cmdJson["metadata"]; found {
+ if metadata, ok = x.(map[string]interface{}); !ok {
+ return nil, fmt.Errorf("metadata was not a map in json output of submit --from command, returned json was %s", cmdStdout.String())
+ }
+ var nameFromJson string
+ if x, found := metadata["name"]; found {
+ if nameFromJson, ok = x.(string); !ok {
+ return nil, fmt.Errorf("metadata.name was not a string in json output of submit --from command, returned json was %s", cmdStdout.String())
+ }
+ name = nameFromJson
+ } else {
+ return nil, fmt.Errorf("metadata.name was not found in json output of submit --from command, returned json was %s", cmdStdout.String())
+ // didn't find the key
+ }
+ } else {
+ return nil, fmt.Errorf("metadata was not found in json output of submit --from command, returned json was %s", cmdStdout.String())
+ // didn't find the key
+ }
+ }
t.namespableDynamicClient = t.DynamicClient.Resource(schema.GroupVersionResource{
Group: "argoproj.io", This is really a hack, but works if anyone cares about fixing it too :) |
This issue has been automatically marked as stale because it has not had |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I'm trying to submit WorkflowTemplate through a Sensor using ArgoWorkflow trigger. The Workflow gets indeed run, but it throws following errors
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No errors should be thrown after successfully running
submit-from
operationScreenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
Additional context
I've narrowed it down to this line: https://github.com/argoproj/argo-events/blob/master/sensors/triggers/argo-workflow/argo-workflow.go#L203
It tries to get a workflow object, based on workflowTemplate name, which obviously won't work because created Workflow object name has randomized suffix. I imagine it should use the same labels it is using for
submit
to find the Workflow insubmit-from
operation.Message from the maintainers:
If you wish to see this enhancement implemented please add a 👍 reaction to this issue! We often sort issues this way to know what to prioritize.
The text was updated successfully, but these errors were encountered: