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

TEP-0061 Allow custom task to be embedded in pipeline #393

Merged
merged 5 commits into from
Apr 12, 2021
Merged

TEP-0061 Allow custom task to be embedded in pipeline #393

merged 5 commits into from
Apr 12, 2021

Conversation

ScrapCodes
Copy link
Contributor

@ScrapCodes ScrapCodes commented Mar 26, 2021

See issue tektoncd/pipeline#3682, for initial discussion regarding this TEP.

/cc @Tomcli, @litong01

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 26, 2021

CLA Signed

The committers are authorized under a signed CLA.

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 26, 2021
teps/README.md Outdated Show resolved Hide resolved
@Tomcli
Copy link
Contributor

Tomcli commented Mar 26, 2021

/cc @afrittoli @pritidesai

@Tomcli
Copy link
Contributor

Tomcli commented Mar 26, 2021

@animeshsingh

@pritidesai
Copy link
Member

Thank you @ScrapCodes for this proposal 🙏

Some house keeping - please squash the commits into one.


## Proposal

Use combination of taskRef and taskSpec to indicate an embedded custom task.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can go in the alternative section if needed. Combination of taskRef and taskSpec is generally avoided so far, it's either one or the other allowed.

This is not needed in the proposal. Just taskSpec is sufficient to inline custom specifications. Like @imjasonh suggested in one of the comments in the issue, taskSpec can hold apiVersion, kind, and spec.

This would require to change the EmbeddedTask definition to:

type EmbeddedTask struct {
	// +optional
	Metadata PipelineTaskMetadata `json:"metadata,omitempty"`

	// TaskSpec is a specification of a task
	TaskSpec `json:",inline,omitempty"`

        // APIVersion and Kind can be specified here.
	runtime.TypeMeta `json:",inline,omitempty"`

        // inline custom task specification here
	Spec             runtime.RawExtension `json:"spec,omitempty"`
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change to the EmbeddedTask struct, inlining task-loop specifications can be done with:

spec:
  tasks:
    - name: run-my-tests
      taskSpec:
        apiVersion: custom.tekton.dev/v1alpha1
        kind: TaskLoop
        spec:
          taskRef:
            name: simpletask
          iterateParam: word
          timeout: 60s
          retries: 2

to users whether to embed the custom task spec as part of the pipeline similar
to regular Tekton tasks.

Alternatively, we can have the `apiVersion` and `kind` embedded in the task
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop this for now, this can be added back with the proposal.

Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this up! I'm excited to see this work moving forward. 👍

Use Tektoncd/pipeline webhook to determine if a task is a custom task based
on above suggestion. Once a task is determined to be a custom task, then the
specification defined in taskSpec will be also used to define the `Run` custom
resource. This requires the `Run` API also need to be updated with the taskSpec.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this point with an example Run YAML that the above Task would produce? I think that would help illustrate what the proposal is suggesting. It could also be helpful to show what code changes you're proposing to the Run struct, along with @pritidesai 's Go and YAML examples in her comments.

Adding taskSpec to the Run type adds a requirement for Run controller authors, which we'll need to describe in documentation. Some controllers might only want to support taskRef and not taskSpec (or vice versa), and we should give guidance about how they can signal that to users.

resource. This requires the `Run` API also need to be updated with the taskSpec.

Once `Run` resource creation is requested by Tektoncd/Pipeline webhook,
the custom controller should have a webhook to validate if the `Run` has the embedded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should prescribe that a Run controller should use webhook validation necessarily (even though I think it's a good idea). Webhooks in k8s are unfortunately still very annoying to set up. Async validation in reconciling might be better for some Custom Tasks, so we should allow that.

Maybe loosen the wording to "custom controllers should consider having a webhook to validate..." ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the webhook could be optional and let the custom task owner decide whether to implement it.

@ScrapCodes ScrapCodes closed this Mar 27, 2021
@ScrapCodes ScrapCodes reopened this Mar 27, 2021
@ScrapCodes
Copy link
Contributor Author

ScrapCodes commented Mar 27, 2021

CLA Signed

The committers are authorized under a signed CLA.

@ScrapCodes
Copy link
Contributor Author

ScrapCodes commented Mar 27, 2021

Thanks a lot @pritidesai, @imjasonh and @Tomcli for the quickest review. 🚀

I have dropped Proposal section for now, we can add that later. Please Take a look again !

Comment on lines 138 to 141
With the embedded taskSpec for the custom task, all the Tekton clients
can create a pipeline or pipelineRun using a single API call to the Kubernetes.
Any downstream systems that employ tektoncd e.g. Kubeflow pipelines, will not be
managing all the custom task CRs and their versioning.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+100

Having Tekton resources generated through a DSL or an external platform is a very common use case, and this very much reduces the orchestration complexity for those use cases.

Comment on lines 190 to 191
We can reuse the custom task e2e tests with the current test controller
to verify whether the controller can handle the custom task taskSpec.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you then add support for embedded spec to the test controller?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will update the custom task test over here. Looks like there no test controller running in the e2e test?
https://github.com/tektoncd/pipeline/blob/main/test/custom_task_test.go

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! This addition makes very much sense.
The embedded spec should be an optional part of the Run API.
I believe that's the intention anyways, and something we can specify along with the proposal details.

teps/README.md Outdated Show resolved Hide resolved
@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2021
Co-authored-by: Tong Li <[email protected]>
Co-authored-by: Tommy Li <[email protected]>
Co-authored-by: Prashant Sharma <[email protected]>
@ScrapCodes ScrapCodes closed this Apr 3, 2021
@tekton-robot tekton-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 3, 2021
@ScrapCodes ScrapCodes reopened this Apr 3, 2021
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 3, 2021
@ScrapCodes ScrapCodes requested a review from imjasonh April 3, 2021 13:24
@dibyom
Copy link
Member

dibyom commented Apr 7, 2021

/assign @vdemeester
/assign @sbwsg

/cc @imjasonh @afrittoli

resource specification file using [`taskRef`](https://github.com/tektoncd/community/blob/main/teps/0002-custom-tasks.md).
That feature allows a custom task to be submitted to kubernetes along
the submission of the [Tektoncd/pipeline](https://github.com/tektoncd/pipeline),
however, the submission of a custom task is a separate request to Kubernetes.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify this a bit? It sounds in the beginning like custom tasks are submitted to k8s along with a pipeline but then the second part of the sentence says that, no, custom tasks are actually submitted separately. I don't totally understand what we mean here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, there are some mistakes on the wording. The formal custom task is referring to the pipelineTask type. The latter custom task is referring to the custom resources created for the custom task. I will update the summary to make it more clear.


## Motivation

It is natural for a user to follow ways such as a [Kubernetes Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/), ReplicaSet, StatefulSet and also
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This jumps directly into a general assertion that there are natural or unnatural ways for users to work with Kubernetes. This is useful context but I think it would be really helpful if we could nail down a specific motivation too.

From your experiences using custom tasks can you include here a description of the exact problem you and your users face? Ideally not generalized over an entire problem area but very concretely: User X does A, User Z does B, these actions collide because C, we are then motivated to add Custom Task Specs to fix it by ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will move our Kubeflow pipeline use case over here since that's the exact problem we are facing

will have conflicts when they are using the same name for their custom task CR.
- In KFP, we need all the templates and task spec live in each pipeline. Currently,
having all the custom task templates living in the Kubernetes namespace scope means that
we have to make multiple API calls to Kubernetes in order to get all the pipeline
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is, I think, exactly what I was looking for in the motivation section. Could you move this in to the motivation section and elaborate on it a little bit: "we first have to call the api to get X, then we have to call to get Y, this could be much simpler if we just had the whole thing available in a single place".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

-->

- Users can put all the information in one pipelineRun CR.
- Users don't have to manage the custom task CR. Since custom task CR is
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read this and I've read the associated issue but I still don't quite grok what we mean by "managing the custom task CR". What is being managed? Also, which users are we talking about here? The KFP end-users or KFP devs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are just referring users that run pipeline directly on Kubernetes using Tekton. I can update the use cases here to fit more in terms of the KFP scenario.

Consider including folks that also work outside the WGs or subproject.
-->

None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely cannot be known until the implementation is proposed. Suggest simply omitting this for the time being.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Any downstream systems that employ tektoncd e.g. Kubeflow pipelines, will not be
managing all the custom task CRs and their versioning.

It is natural for a user to follow ways such as a
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you're referring here to the fact that deployments and such allow the user to define a podTemplate or similar, is that right? Could you call that out specifically as part of this? Otherwise it's left up to interpretation and prior knowledge/understanding of those resource types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@vdemeester vdemeester added the kind/tep Categorizes issue or PR as related to a TEP (or needs a TEP). label Apr 8, 2021

1. Allow custom tasks to be embedded in a pipeline specification,
2. Custom task specification verification/validation should be handed
over to custom task controllers, custom task specification must not be
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we soften the wording of this one a bit? I think there are approaches here where the custom task controller could specify the validation (e.g. as openapi) and pipelines controller enforces that validation.

We might not want to make this required, or the default expectation, but I am a tad nervous about "only" treating this field as a generic blob which the pipelines controller has no insight into. It could make future work around conformance and Custom Tasks (for example) considerably more complicated if we've blanket prohibited the pipelines controller from performing any verification / validation.

We could remove this goal and simply leave it as a non-goal for now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can move this to non-goal

@ScrapCodes
Copy link
Contributor Author

@sbwsg, @Tomcli, Hi Scot and Tommy, I am still improving the document as per the feedback, will let you guys know once I have an update.

@ScrapCodes
Copy link
Contributor Author

@sbwsg Please take another look !

@ScrapCodes ScrapCodes requested a review from a user April 12, 2021 06:50
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for tackling all those changes! I'm very excited to see this move ahead.

/approve

-->

- The Tekton controller is responsible for adding the custom task spec to
the Run spec. Validation of the custom task is delegated to the custom controller.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 12, 2021
@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ImJasonH, sbwsg

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pritidesai
Copy link
Member

thank you @ScrapCodes @Tomcli 🙏
/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 12, 2021
@tekton-robot tekton-robot merged commit bbdc472 into tektoncd:main Apr 12, 2021
@Tomcli
Copy link
Contributor

Tomcli commented Apr 12, 2021

Thanks everyone for reviewing this TEP!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/tep Categorizes issue or PR as related to a TEP (or needs a TEP). lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Implemented
Development

Successfully merging this pull request may close these issues.

8 participants