-
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
Add support for optional volumes in Tasks #4083
Comments
Hey @goldmann ! I'm surprised to see a feature being requested around volumes + volume mounts in tasks and would love to hear more about why you prefer these to using workspaces - ive actually been hoping we'll remove volumes + volumemounts in the long run, since they dont fit with the authoring time vs runtime distinction we've tried to draw between tasks and task runs - it looks like you've worked around that in your example by using a param for config-name, but I'm curious why not use workspaces (you mentioned that they may not fit all use cases - do you have some specific ones in mind?) For exmaple: apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: sample
spec:
workspaces:
- name: pipeline
- name: config
optional: true
mountPath: /config
steps:
- name: execute
image: dummy
command: ["run"] it seems like that would give you everything you need? is it that you want to ensure that the provided workspace is a configmap instead of some other volume? (if so, maybe what is missing is more type information in the workspace declaration?) |
Thanks for the answer! Let me try to go through this. Lets assume following:
Let's assume we use workspaces to provide the functionality. Task developer defines workspace requirement on the Task. Making it optional makes it possible to use in an automated system. But how to provide data that is understandable to the Task? We have a problem that can be summarized as: how an automated system could be smart enough to wire things together? Some starter questions:
Now, let's think about using volumes. Task developer can define explicitly the requirement: "in order to provide configuration, create a CM with XYZ data". If it exists - it is used, if not - nothing happens, Task will still run. Now the best part - our Operator does not need to know about the volume requirement, it doesn't care even. The whole complexity of checking resources, guessing what to mount, problematic PipelineRun creation within Tekton Triggers just goes away - nothing like this is required anymore. We used built-in Kubernetes functionality to provide values for such systems instead of writing it ourselves. The only required thing would be to define a convention on resource names to prevent clashes, but this one is easy. Does this help? |
Probably a bit related to this is one issue I created recently : #4055 |
thanks for the detailed response @goldmann - that definitely helps!
it seems like maybe what is missing is something in the workspace expressing more about what it needs - exactly like @vdemeester is pointing out in that issue he linked. am i understanding correctly: you need to be able to create/provide config-maps/volumes/secrets dynamically, which meet a task's requirements? (and volumes + volume mounts allow you to be more explicit about this so they work better for you than workspaces?) if the workspace declarations in a Task provided enough info that you could tell if they required a volume vs a configmap vs a secret, would that be enough for you to be able to use workspaces instead of volumes and volume mounts? also, are you able to provide any more details of the specifics of what you're doing, e.g. an example of a task and what kind of value you are dynamically providing for it? no worries if you can't share but the more concrete details the bette (and the more likely we can add the functionality you need!) |
You can include a kind: Task
apiVersion: tekton.dev/v1beta1
metadata:
name: footask
spec:
volumes:
- name: conf
configMap:
name: foo-bar-config # this doesnt exist in my cluster. the dir will be empty.
optional: true
steps:
- name: foostep
image: alpine:latest
volumeMounts:
- name: conf
mountPath: /conf
script: |
if [ -d /conf ] ; then
echo "YES THERE IS AN OPTIONAL CONF DIRECTORY!!!"
ls -lah /conf
else
# never reached. there's always a dir, even if no configmap exists.
echo "NO THERE IS NOT AN OPTIONAL CONF DIRECTORY!!"
fi
echo "hello world"
---
kind: TaskRun
apiVersion: tekton.dev/v1beta1
metadata:
name: footaskrun-task-ref
spec:
taskRef:
name: footask Continuing the thread of conversation though - while ConfigMap and Secrets do have an optional param I don't think any other volume types have it. I'm not sure how we'd support this for other volume types without sort of "forking" them from Kubernetes to add the optional field. The concept of optional volumes also has the side-effect of making the outcome of a run less deterministic: for ex a pod w/ optional secret volume can race with an automated secret creation process. Which state of the volume (populated/unpopulated) will the code running inside the pod end up seeing? Optional Workspaces don't suffer this same racing problem - either they're provided explicitly in the run (and therefore must exist prior to pod creation) or they're not, and the pod will be created without the volume attachment (assuming the workspace is optional ofc). Wiring workspaces together in a pipeline is still very much not solved though. I do still strongly suspect that there's a solution here that involves workspaces, we just need to keep poking at it I think. Offering a default workspace binding inside a task's or pipeline's workspace declaration sounds like a passable approach to me. The issues I guess that raises are:
Also, pulling in @vdemeester's suggestion from #4055:
Automated systems and orgs could decide precisely how they map "meaning" to "volume type". I like this idea a lot but I'm also finding myself poking holes in it. e.g. how do we deal with: mismatched meaning labels between tasks in the catalog, ensuring authors include meaning labels on these tasks in the first place, providing the right set of meaning labels that covers enough use-cases without forcing automated systems to deal with combinatorial explosion, etc etc. Note: Edited to inline a yaml code example at the top. |
Sorry for the delay!
In my case I consider a ConfigMap or Secret as a configuration for the Task. Task defines what it needs, for example if the implementation of a Task is to connect to some service that requires authentication - a Secret would be the way to satisfy this requirement. This requirement would be specified on the Task level because this is where we need to have it. Now, continuing with the example - let's look at ConfigMap. Here, the Task can define optional configuration for the Task. For example if you want to override the URL to the service to connect to - you could create a ConfigMap like this: apiVersion: v1
kind: ConfigMap
metadata:
name: task-xyz-config
data:
serviceUrl: http://192.1.2.3/context If this is provided, it is mounted in the Task. If it's not provided - empty dir is mounted -> file does not exist -> defaults from the Task implementation are used (for example: The thing is that the orchestrator that wires everything together is now totally free from trying to understand requirements and providing them. This may be very tricky in some cases.
This would shift the responsibility of finding out (guessing?) what is needed to the orchestrator. If Task would define a workspace requirement for a CM - we would need to know what CM should be provided there. This could be partially solved by implementing a convention for names - this would limit number of available items to mount, but there is still uncertainity which exactly CM should be mounted. Just a reminder - orchestrator is an automated system. For a manually crafted Pipeline/Run - it's easier. Uhm, ehm, huh? 😕 I'm not exactly sure how it happened, but I was able to apply mine (and yours) example onto my cluster now. I wonder if some upgrades of the components made some difference here. I've updated Kubernetes and Tekton to newer versions.
Good catch. To be fair, my biggest use case for optional volumes are ConfigMaps as "optional configuration" (as shown above).
Slight offtopic here: If we are touching the Hub... Currently there are no rules what workspaces are requested, meaning: we know only name and some description in the doc, nothing else. If we would like to reuse it in an automated system we have a big problem. I'm exactly in this situation now. Generally I find Hub tasks not ready for reuse and limited, just two examples:
But back to topic. If a workspace would have:
I think this would make it possible to move from volumes into workspaces. What I don't want to do in an automated system is the guessing part. apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: sample
spec:
workspaces:
- name: config
defaultRef:
kind: ConfigMap
name: sample-config
optional: true
...
In general Dunno, just an idea. |
just a quick update @goldmann - @sbwsg has opened a proposal to add workspace "type hinting" which might be relevant to your needs: tektoncd/community#510 |
Issues go stale after 90d of inactivity. /lifecycle stale Send feedback to tektoncd/plumbing. |
Stale issues rot after 30d of inactivity. /lifecycle rotten Send feedback to tektoncd/plumbing. |
Rotten issues close after 30d of inactivity. /close Send feedback to tektoncd/plumbing. |
@tekton-robot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Feature request
Consider following
Task
:If it would be possible to specify
optional: true
for the volume we would have a way to mountConfigMap
andSecret
only if these are available. This would not fail the run in case it is not available. And this is exactly what is the power of it.Such feature is already is built-in into Kubernetes and would need to be exposed in Tekton. Docs aren't really great, but:
FWIW: I'm aware that there is support for optional workspaces, but it may not fit all use cases.
Use case
Imagine an established convention for configuration ConfigMap names ins some system. Such ConfigMap's would be always mounted with
optional
set totrue
. In case CM would exist - configuration would be provided. This would make it possible to have a plug-in configuration for Tasks. If ConfigMap would not be provided, defaults in the Task would be used.The text was updated successfully, but these errors were encountered: