-
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
Losslessly roundtrip Pipelines with Finally from beta to alpha and back #3779
Conversation
/hold This is a proof-of-concept that we can pass Finally back to v1alpha1 without losing information when storing it back again to v1beta1. Open to feedback and questions here, still tidying up and editing tests. |
The following is the coverage report on the affected files.
|
/kind bug |
The following is the coverage report on the affected files.
|
Also, some more context, Kubernetes' guidance for CRD versioning links out to their API changes guide wherein they state the following rule:
|
Thanks @sbwsg for initiating this PR. I tried creating a sample pipeline in
Webhook logs:
I am looking into your changes next. |
Here's an example manual test to try with this PR's branch: # Apply a v1beta1 pipeline with finally section
$ k apply -f ./examples/v1beta1/pipelineruns/pipelinerun-with-final-tasks.yaml
# Get the v1alpha1 rendering of that pipeline
$ kubectl get pipelines.v1alpha1.tekton.dev clone-cleanup-workspace -o yaml > test.yaml
# Open test.yaml in your text editor of choice.
# Edit to have a new name.
# Edit to remove the UUID from the metadata.
# Re-apply the v1alpha1 yaml
k apply -f ./test.yaml Now when you |
Sorry, it was my bad 😞 , the sample pipeline I was using was invalid ( This works great with annotations having the entire finally section in it:
And verified its possible to round-trip. But I am not sure if this is the right solution though (I can approve these changes since at least the log spamming is stopped with this PR 😄 ). My concerns:
beta:
converted to alpha:
And, we haven't heard any complains on these missing when expressions which kind of tells us that the users are not dependent on this conversion. We will have to fix when expressions if we go this route.
|
Yes, will have to add annotations for every new field we add (or that we added in the past). To be honest the alternatives we've considered until now do not seem better:
I'm not entirely sure what the format of these annotation should be, we could discuss whether we want to have one per field, one per api version, or perhaps event store the complete resource as it's stored in an annotation. Things might get complicated if we add a new field with a new field for instance...
I think so, unless we find a better solution. |
Question: would one be able to create resources with these annotations? So effectively create |
Another idea on how to adding fields to API versions.
Issues with this approach:
Possible solutions:
|
@vdemeester I think these processes we should define and document as part of the feature gates TEP |
The following is the coverage report on the affected files.
|
Good point, I was surprised by this - validation is not performed on the converted resource. So upgrading from v1alpha1 w/ invalid finally annotation did not result in error. I've pushed a change so that the Finally is validated after unmarshalling from json annotation. |
The following is the coverage report on the affected files.
|
For reference I went looking for any other examples where an annotation is used to store upgrade/downgrade information. The kubernetes Deployment type stores Edit: and similarly with a DaemonSet field https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/apps/v1/conversion.go#L89 |
@sbwsg what do you think about storing the entire v1beta1 spec instead of just just the finally field in a special annotation? That way we don't have to keep adding new annotations as we keep adding new fields (e.g. when expressions). |
I think that makes a lot of sense! If a user makes changes to the v1alpha1 yaml, do we accept those changes or ignore them when re-hydrating the v1beta1 version from the annotation? Edit: I'd probably lean toward copying the v1alpha1 fields directly over the top of the rehydrated v1beta1 fields, so keeping the changes. |
A question concerning the Finally section issue. From my understanding, if new feature is introduced it is in the following order v1alpha -> v1beta -> V1. If correct then new features would always be introduced first in the alpha version of v1 until we freeze it for v2? |
Yeah, that sounds good to me! |
With every new API version we introduce, the lower API versions are required to implement conversion routines i.e. This is what we have today (serving
Just to get an overall idea with conversion process if we add
Edit: a couple of format changes after adding comment |
I had no idea the lower versions had compounding |
Update from yesterday's API WG call: it sounded like most folks agreed that putting the whole v1beta1 object into an annotation on the v1alpha1 yaml is likely the best route to go down. We're going to look at this again in next week's API WG as the discussion spilled over time this week.
Edit: Discussion in Slack lead to us wanting to get this in ASAP without this change after all. |
sorry, couldn't resist sharing, this tutorial has a great example of round tripping two separate API versions and explanation on conversion: https://youtu.be/AAxuEPIzHUQ?t=2994 |
[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 |
/lgtm Thanks a bunch @sbwsg for adding this fix. As per the discussion on slack, we are limiting the fix to a pipeline with (there are conflicts and will need to resolve them 😉 :) |
The following is the coverage report on the affected files.
|
Prior to this commit pipelines returned an error when converting from a v1beta1 pipeline to a v1alpha1 pipeline if that pipeline had a Finally section in it. As a result of this error the kubeapi would repeatedly request v1alpha1 pipelines every second, filling up our webhook logs with these errors. This commit allows Finally to be serialized into alpha Pipelines, keeping the Finally Tasks as an annotation on the resource. If the alpha Pipeline is then re-applied to the cluster the Finally annotation is rehydrated into the Finally section of the stored v1beta1 resource.
The following is the coverage report on the affected files.
|
/auto-cc |
/lgtm |
/hold cancel |
I'm very late to the party on this, but happy to see it fixed :)
I see this was mentioned as an option - this is in fact the correct solution to this problem, and what is recommended upstream. The purpose of API versioning/creating a new API version is to permit authors of APIs to make breaking changes (i.e., renaming a field) to the schema of an API version. It is not to denote what functionality is supported in a given API. When adding a net-new field, it is perfectly valid to add this within the same API version (without creating anything new). This is the approach upstream APIs taken regularly, and cert-manager has been taking as well. Doing it this way will also avoid huge amounts of annotations being added in future for other fields as you add them to the latest API version (and also stop you needing to cut v2, v3, v4 etc whenever you add new functionality 😄) |
Changes
Fixes #3206
Prior to this commit pipelines returned an error when converting from
a v1beta1 pipeline to a v1alpha1 pipeline if that pipeline had a Finally
section in it. As a result of this error the kubeapi would repeatedly
request v1alpha1 pipelines every second, filling up our webhook logs
with these errors.
This commit allows Finally to be serialized into alpha Pipelines, keeping
the Finally Tasks as an annotation on the resource. If the alpha Pipeline
is then re-applied to the cluster the Finally annotation is rehydrated into
the Finally section of the stored v1beta1 resource.
This is a follow-up to #3757. In that PR we simply squashed the error message, but in this PR we squash the error while also retaining the Finally information during conversion roundtrips.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
Release Notes