-
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
adding metadata to taskSpec in PipelineTask #2826
Conversation
This PR cannot be merged: expecting exactly one kind/ label Available
|
1 similar comment
This PR cannot be merged: expecting exactly one kind/ label Available
|
/kind feature |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
@@ -6,6 +6,9 @@ spec: | |||
pipelineSpec: | |||
tasks: | |||
- name: echo-good-morning | |||
metadata: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is its own field now? so it will not necessarily be written "just above" taskSpec
. If we could have the Task
as a field, optional metadata would work out of the box, as with volumeClaimTemplate
where I can declare a PersistentVolumeClaim
with or without metadata, https://github.com/tektoncd/pipeline/blob/master/pkg/apis/pipeline/v1beta1/workspace_types.go#L61
I would prefer that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlpettersson I think your proposal would help avoid adding k8s
specific types in the PipelineTask
, we can introduce a new field TaskTemplate
or EmbeddedTask
in PipelineTask
which can of type *Task
:
type PipelineTask struct {
TaskTemplate *Task `json:"taskTemplate,omitempty"`
PipelineTask
can have one of TaskRef
, TaskSpec
, or TaskTemplate
.
I understand we are looking over to Custom Tasks
which would help solve many use cases but this would solve the issue in short term and could be extended to custom tasks if needed. I am looking for feedback on this 🙏
@vdemeester @bobcatfish @jlpettersson thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like that is the most proper solution, yes.
We haven't used "Template" for declarations in other places, but it may work. Other alternatives are:
Task *Task 'json:"task, omitempty"'
or
TaskDeclaration *Task 'json:"task, omitempty"'
Most correct description about what this is, is probably: inline task declaration
I don't think this is related to CustomTask
at all, it will be the exact same problem. I think CustomTask
recently has become the most misunderstood thing about Tekton.
@@ -93,6 +95,9 @@ type PipelineResult struct { | |||
// PipelineTask defines a task in a Pipeline, passing inputs from both | |||
// Params and from the output of previous tasks. | |||
type PipelineTask struct { | |||
// +optional | |||
metav1.ObjectMeta `json:"metadata,omitempty"` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we had Task *v1beta1.Task
instead of (or in addition to - for compatibility) the current TaskSpec *TaskSpec
, then metadata
would be included as optional - by design
...as how I understand from the volumeClaimTemplate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this does not work for TaskRef
if we want a "custom" metadata - but if we want to use the metdata as-is, I think it should work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @jlpettersson, with taskRef
, the referring task can have metadata which should be sufficient like we have today. My focus was to only add metadata
with taskSpec
as pipeline
has no means of specifying task metadata with taskSpec
.
I think this might require a TEP - since it's an API change, and also this is introducing more k8s specific stuff into a PipelineTask - I'd at least like to discuss it before adding it |
looks like @vdemeester didnt feel it required a TEP (#2767 (comment)) that's ok with me, but could we at least discuss this at the API working group and talk about why we need it? |
yup, will add it for the discussion in the API group 🙏 |
Here is one of our use cases with this new API: apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
labels:
pipelines.kubeflow.org/pipeline-sdk-type: kfp
name: echo
spec:
steps:
- args:
- echo hello world
command:
- sh
- -c
image: library/bash:4.4.23
name: main
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
labels:
pipelines.kubeflow.org/pipeline-sdk-type: tfx
name: echo2
spec:
steps:
- args:
- echo hello world
command:
- sh
- -c
image: library/bash:4.4.23
name: main
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: sequential-pipeline
spec:
tasks:
- name: echo
taskRef:
name: echo
- name: echo2
runAfter:
- echo
taskRef:
name: echo2
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: sequential-pipeline-run
spec:
pipelineRef:
name: sequential-pipeline Here, we can filter these pods based on a label. e.g. However, when we try to convert the above pipeline into a single pipelineRun kind, we don't have a way to express the labels or annotations on the task level. Therefore, we want to have the above API to represent the pipelineRun in this way. apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: sequential-pipeline-run
spec:
pipelineSpec:
tasks:
- name: echo
metadata:
labels:
pipelines.kubeflow.org/pipeline-sdk-type: kfp
taskSpec:
steps:
- args:
- echo hello world
command:
- sh
- -c
image: library/bash:4.4.23
name: main
- name: echo2
metadata:
labels:
pipelines.kubeflow.org/pipeline-sdk-type: tfx
runAfter:
- echo
taskSpec:
steps:
- args:
- echo hello world
command:
- sh
- -c
image: library/bash:4.4.23
name: main |
thanks @Tomcli for the example, it looks great, would also like to know:
I understand the expectation is accurate that the
|
I know there will be conflicts when using the |
This is similar to paradigms where a superset has "default" values, and unless a subset from that superset defines its own values which override the "default", the default gets applied to subset as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👯
One nit, and one question 😉
// Propagate labels and annotations from PipelineRun and TaskSpec to TaskRun. | ||
labels := getTaskrunLabels(pr, rprt.PipelineTask.Name) | ||
annotations := getTaskrunAnnotations(pr) | ||
if rprt.PipelineTask.TaskSpec != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question here : which labels should take precedence ? My gut is that the TaskRun
labels should take precedence over the one defined in the Pipeline
; otherwise a Pipeline
can define a label that override tekton.dev/Task
or something and it could break some UX/UI/…. This code does the other way around (labels define in the Pipeline
tasks take over the TaskRun
labels).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the way its implemented, labels defined in pipeline would take precedence. You are right, it is possible that pipeline defined tekton.dev
label would break and takes over the TaskRun labels. I will change the order here.
Should we apply the same precedence order in Conditions? I can create a separate PR for conditions.
Also, I think labels with tekton.dev/
should be reserved for the platform and we should not allow such labels, anything starting with tekton.dev/
. What do you think? We could add this kind of validation in this PR as part of ValidateTaskSpecMetadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we apply the same precedence order in Conditions? I can create a separate PR for conditions.
I would think so indeed 😉
Also, I think labels with
tekton.dev/
should be reserved for the platform and we should not allow such labels, anything starting withtekton.dev/
. What do you think? We could add this kind of validation in this PR as part of ValidateTaskSpecMetadata.
Indeed, we should probably add that kind of validation to ValidateTaskSpecMetadata
(for some reason I thought that was already the case 😜 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, in general Metadata
is validated for valid Name
(no special character .
and max length of 63 characters). I have added validation on labels as part of taskSpec
metadata to restrict using tekton.dev/Task
. Not sure if we can block in general any label with tekton.dev
in taskSpec
metadata (git
and docker
credentials use tekton.dev
but they belong to k8s Secrets
) or should we rather restrict labels with tekton.dev/
from every Tekton resource i.e. Pipeline
, Task
, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the order so that TaskRun labels takes higher precedence.
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
@vdemeester @imjasonh @bobcatfish @jlpettersson its ready for review, PTAL 🙏 |
Adding metadata to TaskSpec in PipelineTask to allow specifying metadata. This metadata will be propogated to taskRun and then to the pods. ``` apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: pipelinerun-with-taskspec-to-echo-greetings spec: pipelineSpec: tasks: - name: echo-greetings taskSpec: metadata: labels: [ …] steps: ... ``` Metadata is already supported as part of Tasks and Pipelines while respective CRDs are created. But was not possible to specify with embedded resources.
The following is the coverage report on the affected files.
|
/lgtm 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/meow
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. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vdemeester The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test check-pr-has-kind-label |
/retest |
/test pull-tekton-pipeline-integration-tests |
Hum, boskos is in trouble 😅 |
/test pull-tekton-pipeline-integration-tests |
one more try 🙃 /test pull-tekton-pipeline-integration-tests |
/test pull-tekton-pipeline-integration-tests |
Changes
Adding
metadata
totaskSpec
withinPipelineTask
to allow specifying labels and annotations when a task is embedded usingtaskSpec
. These labels and annotations are propagated totaskRun
and then to the pods.Metadata is already supported as part of Tasks and Pipelines while respective CRDs are created. But was not possible to specify with embedded resources.
These labels are commonly used to identify and filter pods for further actions (such as collecting pod metrics, and cleaning up completed pod with certain labels, etc) even being part of one single Pipeline.
Closes #2767
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Double check this list of stuff that's easy to miss:
cmd
dir, please updatethe release Task to build and release this image.
Reviewer Notes
If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.
Release Notes