-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Provide mechanism to set environment variables on TaskRuns #1606
Comments
@poy I am not entirely sure I follow but I guess, what you want is to be able to pass environment variable from the It could be something like the following… apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: read-repo
spec:
taskRef:
name: read-task
env:
- name: "FOO"
value: "bar" … or we could enhance /kind feature |
Sorry for being vague, but you nailed it! I also prefer your first API suggestion. |
hey there @poy! could you describe a bit more about the use case for this? today you could accomplish this by:
We've tried to be very deliberate about what values provide at runtime: for example, if you have a step in Task X which requires environment variable FOO, we want to make sure that is as explicit in Task X as possible - if Task X doesn't mention it, but it's expected to be provided via the TaskRun, then users of the Task won't know how to use the Task |
@bobcatfish of course! So we are using Buildpacks with Tekton. Traditional Buildpacks (In Cloud Foundry) allowed environment variables for settings. We have no way of knowing what environment variables could be needed ahead of time as users can create their own Buildpacks. Therefore we need something more dynamic. |
Adds a `Env` field to `TaskRunSpec` to allow a user to set environment variables on each step container. This mimics Knative-Build's `TemplateInstantiationSpec`'s `Env` field. Setting environment variables is useful for when a `TaskRun` author may not know what variables are required ahead of time (e.g., Buildpacks). fixes tektoncd#1606
Adds a `Env` field to `TaskRunSpec` to allow a user to set environment variables on each step container. This mimics Knative-Build's `TemplateInstantiationSpec`'s `Env` field. Setting environment variables is useful for when a `TaskRun` author may not know what variables are required ahead of time (e.g., Buildpacks). fixes tektoncd#1606
@vdemeester @bobcatfish I took a swing at a PR for this so it was easier to visualize the API change: #1657 |
Thanks for the extra info @poy!
I'm not super familiar with Buildpacks, could you give an example of what an example Task + TaskRun would look like for this?
I'm a bit confused - how does the user provide the environment variables to the TaskRun if it's not known ahead of time what env variables are needed? (I think maybe an example might clear this up for me!) Another couple ideas of how you could do this:
|
I think this has the same magic problem that is making me hesitate to agree with adding env vars on TaskRuns - but at least it's a feature we already have :S btw I'm not sure if you've already been but if you're able to attend our working group could be a great place to discuss a feature request / design like this in real time |
(p.s. @vdemeester I noticed you put this into the beta milestone so we might be on slightly different pages about this?) |
@bobcatfish ah 😅 I did put it in the beta milestone just so that we discuss it while discussing beta, doesn't really mean I think it should go in for beta or not 👼 |
We use a well-known "named" ConfigMap to pass environment variable values into Steps. This works well when you know the environment variable name. If you do not know the environment variable name in advance you can use |
Just realized this is in the Task not the TaskRun so no help after all 🤦♀️ but @skaegi 's suggestions sound legit! and/or array param maybe? |
also, with embedded TaskSpec and PipelineSpec in the Run object & co, it's "kinda" covered, as you could "copy" a Task and embedded it with some changes 👼 |
@skaegi and @bobcatfish We actually use a secret today, however we were hoping to get away from managing the lifecycle of another object, however this is a valid option. @vdemeester It seems weird to me that there are different API options if I use a Task vs embed it... But it also doesn't seem very clean to do so. |
There is not a different API options depending of if you use a Task or embedded it. But as this is "hidden" from the user (aka your tool handle that), you could do something like the following (in go code) :
You would use a given task as a "template" for your taskrun ; but all your taskrun would be "self-descriptive" and would not depend on any "task" per-se. Not sure how clean or not it is 👼 it's just a possibility and a valid use-case I think 😉 |
Just to try and move the conversation forward a bit more on this, there's another use case for the feature that I think is worth considering. Node.js libraries and apps commonly support a debug env var (e.g. I don't think it's great that in order to support those env vars every Java or node.js Task in the universe would need to individually expose their own I'd also argue that, while it may not be awesome to allow runtime configuration outside of a task's declared params / artifacts, so long as the TaskRun stores the env vars that were passed in there will at least be a clear record of their usage and they aren't totally silent. And, finally, just to throw some more options out there, this could conceivably be configurable on the Task: kind: Task
allowRuntimeEnvVars: true # but defaults to false! Having that would make runtime env var support explicitly opt-in and catalog tasks could totally leave it out so we don't propagate an anti-pattern. |
I think at some point we have to recognize a Task author cannot make everything parameterizable. Not strictly for CI/CD and Tekton but when we hit these sorts of "debug" and "instrumentation" cases Kustomize is a pretty good solution. |
I just want to double check: are we sure that the array param won't work for @poy's use case? |
I think we could duct-tape this solution in, however it comes with two major drawbacks (as far as I can tell)... We would have to require the entrypoint to be a shell. This would allow us to prepend the command with the given array. BUT:
Overall, while I agree this would likely cover many use cases, it doesn't feel clean and certainly doesn't cover all of them. |
This is really a way of implementation, but if I want to pull up taskRun or pipelineRun through tektoncd/trigger project, it seems to be a little difficult. IIRC resourceTemplates can only pull an instance like pipelineResource or pipelineRun, but can't dynamically modify the definition of task step's env. I agree with @sbwsg that the template writer cannot enumerate the parameters/envs that the template instance will pass in |
Thanks for the follow up @poy!
What about if the params could be a map or list of lists? So you could do something like: apiVersion: tekton.dev/v1beta1
kind: TaskRun
spec:
params:
- name: settings
value:
- name: MY_ENV_VAR
value: foo
---
apiVersion: tekton.dev/v1beta1
kind: Task
spec:
params:
- name: settings
type: list-of-lists # probably something more complex with "schema" see #1393
steps:
- image: my-image-with-no-shell
envValueFrom: params.settings[*] (Completely handwaving about the syntax above! I think that @skaegi is going to simultaneously hate the above syntax and have way better ideas) If something like this would work for you @poy I'm happy to open another issue to explore further |
If those |
This will help to specificy env default, env at pipelinerun and taskrun level. Env in pod template will take precedence over one defined in step and stepTemplate Env at pipelinerun and taskrun level will take precedence over the one in default podtemplate Fix tektoncd#1606
This will help to specificy env default, env at pipelinerun and taskrun level. Env in pod template at taskrun and pipelinerun level will take precedence over one defined in step and stepTemplate Env at pipelinerun and taskrun level will override the default podtemplate Fix tektoncd#1606
This will help to specificy env default, env at pipelinerun and taskrun level. Env in pod template at taskrun and pipelinerun level will take precedence over one defined in step and stepTemplate Env at pipelinerun and taskrun level will override the default podtemplate Fix tektoncd#1606
This will help to specificy env default, env at pipelinerun and taskrun level. Env in pod template at taskrun and pipelinerun level will take precedence over one defined in step and stepTemplate Env at pipelinerun and taskrun level will override the default podtemplate Fix tektoncd#1606
This will help to specificy env default, env at pipelinerun and taskrun level. Env in pod template at taskrun and pipelinerun level will take precedence over one defined in step and stepTemplate Env at pipelinerun and taskrun level will override the default podtemplate Fix tektoncd#1606
This will help to specificy env default, env at pipelinerun and taskrun level. Env in pod template at taskrun and pipelinerun level will take precedence over one defined in step and stepTemplate Env at pipelinerun and taskrun level will override the default podtemplate Fix tektoncd#1606
Issues go stale after 90d of inactivity. /lifecycle stale Send feedback to tektoncd/plumbing. |
This is (about to be) in our roadmap (WIP roadmap) /lifecycle frozen |
Any updates on this issue? 🧐 |
This document proposes support for environment variables configuration in `podTemplate`. That allows to exclude common variables to the global level as well as overwrite defaults specified on the particular step level.
This issue was addressed in TEP-0101: Env in POD template - feel free to reopen if there are any further requests about this feature |
Expected Behavior
Have similar API to knative-builds TemplateInstantiationSpec to provide environment variables to a TaskRun.
Actual Behavior
Use work arounds.
Steps to Reproduce the Problem
Additional Info
The text was updated successfully, but these errors were encountered: