gANDALF
gANDALF

Reputation: 238

How to pass paramters to argo workflow api

I am running my workflow through argo workflow api ,and I am not able to pass dynamic input paramters

curl  -k --request POST \
  --url https://localhost:2746/api/v1/workflows/argo \
  --header 'content-type: application/json' \
  --data '{
  "namespace": "argo",
  "serverDryRun": false,
  "workflow": {
      "metadata": {
        "generateName": "hello-world-",
        "namespace": "argo",
        "labels": {
          "workflows.argoproj.io/completed": "false"
         }
      },
     "spec": {
       "templates": [
        {
         "name": "whalesay",
         "arguments": {},
         "inputs": {
             "parameters":{
                "name":"[email protected]"

             }


         },
         "outputs": {},
         "metadata": {},
         "container": {
          "name": "",
          "image": "gandalf/patientreg",
          "command": [
            "./app"
          ],
          "args": [
            ""
          ],
          "resources": {}
        }
      }
    ],
    "entrypoint": "whalesay",
    "arguments": {}
  }
}
}'

I am getting this error while running the workflow

{"code":3,"message":"json: cannot unmarshal object into Go struct field Inputs.workflow.spec.templates.inputs.parameters of type []v1alpha1.Parameter"}%

I want to pass dynamic email through api and receive if as command line arguments in my app such that I can run my workflow . How to achieve that ?

Upvotes: 1

Views: 1683

Answers (1)

chinoy
chinoy

Reputation: 172

You can pass parameters to the workflow which instead can be sent to any step inside the workflow. The parameter should have a name. In your example you are only passing the value directly to the step.

Here is an example payload.

    {
        "workflow": {
            "metadata": {
                "name": "awesome-dragon",
                "namespace": "argo",
                "labels": {
                    "example": "true"
                }
            },
            "spec": {
                "arguments": {
                    "parameters": [
                        {
                            "name": "workflow-arg",
                            "value": "[email protected]"
                        }
                    ]
                },
                "entrypoint": "argosay",
                "templates": [
                    {
                        "name": "argosay",
                        "inputs": {
                            "parameters": [
                                {
                                    "name": "step-level-arg",
                                    "value": "{{workflow.parameters.workflow-arg}}"
                                }
                            ]
                        },
                        "container": {
                            "name": "main",
                            "image": "argoproj/argosay:v2",
                            "command": [
                                "/argosay"
                            ],
                            "args": [
                                "echo",
                                "{{inputs.parameters.step-level-arg}}"
                            ]
                        }
                    }
                ],
                "ttlStrategy": {
                    "secondsAfterCompletion": 300
                },
                "podGC": {
                    "strategy": "OnPodCompletion"
                }
            }
        }
    }

Note that an named argument is passed from outside to the argo workflow. The same workflow argument can be utilized any template inside.

Upvotes: 1

Related Questions