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

Error when trying to pass Env Vars as a parameter to a template, cannot unmarshal object into Go struct #8827

Open
3 tasks done
RoryDoherty opened this issue May 23, 2022 · 13 comments
Labels
area/templates/script solution/workaround There's a workaround, might not be great, but exists type/feature Feature request

Comments

@RoryDoherty
Copy link
Contributor

Checklist

  • Double-checked my configuration.
  • Tested using the latest version.
  • Used the Emissary executor.

Summary

What happened/what you expected to happen?
Tried to pass a parameter as a json/list of env vars but get the following error when submitting the workflow:

 Unsuccessful HTTP response: json: cannot unmarshal object into Go struct field ScriptTemplate.workflow.spec.templates.script.env of type []v1.EnvVar

I have tried various assortments of quotes, yaml continuation using | and >

According to this thread on slack it did work at some stage so this may be a regression:
https://cloud-native.slack.com/archives/C01QW9QSSSK/p1628785975367900

What version are you running?
v3.3.5

Diagnostics

Paste the smallest workflow that reproduces the bug. We must be able to run the workflow.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: demo-
  namespace: argoci
spec:
  entrypoint: demo
  templates:
    - name: demo
      dag:
        tasks:
          - name: env-var-test
            template: run-test
            arguments:
              parameters:
                - name: vars
                  value: |
                    [
                      {name: "Foo", value: "bar"},
                      {name: "Bar", value: "foo"},
                      {name: "zoo", value: "animal"}
                    ]

    - name: run-test
      inputs:
        parameters:
          - name: vars
      script:
        image: ubuntu:18.04
        imagePullPolicy: Always
        command: [bash]
        workingDir: "/src"
        env: {{inputs.parameters.vars}}
        source: |
          env

Logs from the workflow controller:

There were no logs in the workflow controller when I submitted the workflow via the UI
Is there a trace logs setting I can enable?


Message from the maintainers:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.

@dpadhiar dpadhiar added type/regression Regression from previous behavior (a specific type of bug) and removed triage labels May 23, 2022
@sandeepk8s
Copy link
Contributor

sandeepk8s commented May 24, 2022

@RoryDoherty Try this

script:
   image: ubuntu:18.04
   command:
     - bash
   workingDir: /src
   env:
     - name: a
       value: '{{inputs.parameters.vars}}'
   source: |
     echo $a

@RoryDoherty
Copy link
Contributor Author

@sandeepitachi
Thanks, I tried that and yes that works, I get this output:

[ {name: "Foo", value: "bar"}, {name: "Bar", value: "foo"}, {name: "zoo", value: "animal"} ]

However I'm not trying to pass that as a string, I want to be able to set the env vars for a template within the dag task.
So in my original example I want "Foo" "Bar" and "zoo" to be environment variables I can access within the script section

@RoryDoherty
Copy link
Contributor Author

RoryDoherty commented May 24, 2022

I can work around this for now using the following:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: demo-
spec:
  entrypoint: demo
  templates:
    - name: demo
      dag:
        tasks:
          - name: env-var-test
            template: run-test
            arguments:
              parameters:
                - name: vars
                  value: |
                    export Foo="bar"
                    export Bar="Foo"

    - name: run-test
      inputs:
        parameters:
          - name: vars
      script:
        image: ubuntu:18.04
        imagePullPolicy: Always
        command: [bash]
        workingDir: "/src"
        env: 
          - name: vars
            value: '{{inputs.parameters.vars}}'
        source: |
          echo $vars > /tmp/vars
          source /tmp/vars
          env

But it would definitely be good if we could set environment variables from the task and not just in the template

@sarabala1979 sarabala1979 added solution/workaround There's a workaround, might not be great, but exists and removed type/regression Regression from previous behavior (a specific type of bug) labels May 24, 2022
@stale

This comment was marked as resolved.

@stale stale bot added the problem/stale This has not had a response in some time label Jun 12, 2022
@RoryDoherty

This comment was marked as resolved.

@stale stale bot removed the problem/stale This has not had a response in some time label Jun 13, 2022
@stale

This comment was marked as resolved.

@stale stale bot added the problem/stale This has not had a response in some time label Jul 10, 2022
@RoryDoherty

This comment was marked as resolved.

@vitalii-cidersecurity

This comment was marked as resolved.

@stale stale bot removed the problem/stale This has not had a response in some time label Aug 11, 2022
@ddemydenko

This comment was marked as duplicate.

@sarabala1979 sarabala1979 added type/feature Feature request and removed type/bug labels Aug 24, 2022
@sarabala1979
Copy link
Member

@RoryDoherty This is by design this is not a bug. Script Template is using v1.container spec. if v1.container will accept the array of EnvVar.
We can enhance the controller to parse the JSON and convert []envVar.

@RoryDoherty
Copy link
Contributor Author

Thanks @sarabala1979 , I had seen a similar snippet in a slack thread as a working example in an earlier release which is why I opened it as a bug!
I'm happy for it to be converted to an enhancement though, if you want to point me in the right direction of where the processing is I'd be happy to take a crack at it

@tooptoop4

This comment was marked as spam.

@alexec
Copy link
Contributor

alexec commented Nov 16, 2022

I don’t believe it is possible to change this behavior The templating merging works by marshaling the string into a struct. It cannot cater for arbitrary string due to whitespacing. Even if you managed to get it to work, any small change to white space would break it.

@RoryDoherty suggestion is looks like a good work-around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/templates/script solution/workaround There's a workaround, might not be great, but exists type/feature Feature request
Projects
None yet
Development

No branches or pull requests

9 participants