Skip to content
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

Closed
Nicarim opened this issue Feb 22, 2024 · 2 comments
Labels
bug Something isn't working stale

Comments

@Nicarim
Copy link

Nicarim commented Feb 22, 2024

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

hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m Name:                hello-world-tmpl-42w72
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m Namespace:           argo
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m ServiceAccount:      unset
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m Status:              Pending
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m Created:             Thu Feb 22 21:42:51 +0000 (now)
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m Progress:
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m {"level":"error","ts":1708638171.9234018,"logger":"argo-events.sensor","caller":"sensors/listener.go:379","msg":"Failed to execute a trigger","sensorName":"hello-world-sensor","error":"failed to execute trigger, wor
kflows.argoproj.io \"hello-world-tmpl\" not found","triggerName":"argo-workflow-trigger","triggeredBy":["test-dep"],"triggeredByEvents":["34313965333736322d326235642d343631652d393562342d353036376639646437386261"],"stacktrace":"github.com/argoproj/argo-events/sens
ors.(*SensorContext).triggerWithRateLimit\n\t/home/runner/work/argo-events/argo-events/sensors/listener.go:379\ngithub.com/argoproj/argo-events/sensors.(*SensorContext).triggerActions.func1\n\t/home/runner/work/argo-events/argo-events/sensors/listener.go:360"}
hello-world-sensor-sensor-dh6jd-ddb6f7657-2qd2m {"level":"error","ts":1708638171.9234366,"logger":"argo-events.sensor","caller":"sensors/listener.go:364","msg":"Failed to execute a trigger","sensorName":"hello-world-sensor","error":"failed to execute trigger, wor
kflows.argoproj.io \"hello-world-tmpl\" not found","triggerName":"argo-workflow-trigger","stacktrace":"github.com/argoproj/argo-events/sensors.(*SensorContext).triggerActions.func1\n\t/home/runner/work/argo-events/argo-events/sensors/listener.go:364"}

To Reproduce
Steps to reproduce the behavior:

  1. Create WorkflowTemplate
  2. Create Sensor that triggers created workflowTemplate
  3. It should submit the Workflow successfully, but subsequently fail to observe it.
  4. See error

Expected behavior
No errors should be thrown after successfully running submit-from operation

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • Kubernetes: 1.27.1-k3s
  • Argo: 3.5.4
  • Argo Events: 1.9.1

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 in submit-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.

@Nicarim Nicarim added the bug Something isn't working label Feb 22, 2024
@Nicarim 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
@Nicarim
Copy link
Author

Nicarim commented Feb 23, 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 :)

Copy link
Contributor

This issue has been automatically marked as stale because it has not had
any activity in the last 60 days. It will be closed if no further activity
occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

1 participant