-
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
Migrate/Upgrade previous version with a default timeout… #1083
Migrate/Upgrade previous version with a default timeout… #1083
Conversation
// add the old default timeout. | ||
// Most likely those TaskRun passing here are already done and/or already running | ||
// and were meant to have the 10 minutes default timeout | ||
timeout = &metav1.Duration{Duration: 10 * time.Minute} |
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 hard-coded old value. We could just use config.DefaultTimeoutMinutes
here instead.
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 would rather use the new value - seems odd to sometimes default to old value, sometimes default to the new value
/hold |
I tried to google this but didnt see an obvious answer: I thought there was a difference between a "mutating" webhook and a non-mutating webhook, i.e. something you need to declare when actually creating the webhook controller itself? Up until this point I thought we were only validating, not mutating, so I am surprised we can just start suddenly mutating. I think I'm missing some knowledge on how this actually works tho, any help appreciated! :bow_panda: Is it because of: pipeline/config/200-clusterrole.yaml Lines 15 to 17 in 0ee3b14
And if so, does that mean we've been mutating all this time? (I didn't think we were 🤔) |
// HasDefaultConfigurationName checks to see whether the given context has | ||
// been marked as having a default configurationName. | ||
func HasDefaultConfigurationName(ctx context.Context) bool { | ||
return ctx.Value(hdcnKey{}) != 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.
what's hdcn
?
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.
why not ? 😹 hdcn
is for hasdefaultconfigurationname
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.
🤭
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.
@vdemeester do we want to take the approach of defaulting values via a mutating webhook in all cases like this in the future?
It looks to me like the root cause is:
timeout := tr.Spec.Timeout.Duration |
So another way to approach this would be to check if tr.Spec.Timeout
is nil before trying to use Duration
?
|
||
// lemonadeKey is used as the key for associating information | ||
// with a context.Context. | ||
type lemonadeKey struct{} |
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.
what's lemonade?
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.
it's just a random key struct used internal for storing some metadata in the context
(here just that we are upgrading it). I was debating on naming this sthg else, but it's how knative named it, and I like lemonade 😝
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.
v good in hot weather 😎
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.
maybe the comment could mention that lemonadeKey is a random name? when i see this it makes me think there is some kinda important thing called "lemonade" - e.g. a "lemonade" defaulting algorithm?
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.
Ah I see, yeah I can add a comment 😉
I have two thoughts:
But I'm happy to go ahead and get this in to fix 0.5.1! Thanks for fixing this so fast and for putting up with my many comments @vdemeester 🙇♀ /lgtm |
I think we do, yes
Right, that would another way to fix it. The only thing I didn't want is to add yet another place where we check / add defaults. Might be the simplest fix though 👼 |
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. |
I feel like we should do that also, b/c as it is we have code that if called as-is could panic 😓 (e.g. in a unit test). It's a separation of concerns for sure - I guess the ideal case would be ensuring via the way these objects are instantiated that all the fields have valid values so every single function accessing them doesn't have to worry about them. |
@bobcatfish #1085 for the simplest fix (to be cherry-picked), I'll update this one to have this mechanism to all resources 👼 😉 |
|
||
var timeout *metav1.Duration | ||
if IsUpgradeViaDefaulting(ctx) { | ||
// This case is for preexisting `TaskRun` before 0.5.0, so let's |
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 I'm missing something: the lemonade key is added to the context at the beginning of the reconcile
function, so it will be added to old and new TaskRuns
alike. However new TaskRuns
willl have the timeout set, so they won't hit L47.
fc4c3a7
to
b76ad0f
Compare
@bobcatfish Updated for |
The following is the coverage report on pkg/.
|
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 left a few comments ... mostly asking for comments haha - there is a bit about how this defaulting works that I am not 100% clear on 🙏
// HasDefaultConfigurationName checks to see whether the given context has | ||
// been marked as having a default configurationName. | ||
func HasDefaultConfigurationName(ctx context.Context) bool { | ||
return ctx.Value(hdcnKey{}) != 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.
🤭
|
||
// lemonadeKey is used as the key for associating information | ||
// with a context.Context. | ||
type lemonadeKey struct{} |
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.
v good in hot weather 😎
} | ||
|
||
// IsUpgradeViaDefaulting checks whether we should be "defaulting" from v1alpha1 to | ||
// the v1beta1 subset. |
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'm a bit confused about what v1alpha1
and v1beta1
are referring to in this context - my understanding is that we are going from pre 0.5.0 to 0.5.0 ? Or does v1beta1
here refer to the version of a lib we are using? (maybe the comment could clarify?)
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.
ah lol, I write that "ahead" of time. it should be from pr 0.5.0 to post 0.5.0 indeed 😉
I need to update the comment indeed 👍
|
||
// lemonadeKey is used as the key for associating information | ||
// with a context.Context. | ||
type lemonadeKey struct{} |
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.
maybe the comment could mention that lemonadeKey is a random name? when i see this it makes me think there is some kinda important thing called "lemonade" - e.g. a "lemonade" defaulting algorithm?
b76ad0f
to
451d0b4
Compare
The following is the coverage report on pkg/.
|
Updated 👼 |
I think the specific use case here is:
Is that accurate? If so, CRD conversion webhooks are the long-term solution here. Use of mutating webhook to perform this function is a stop-gap until we have those. |
More information on CRD defaulting (alpha in 1.15): https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#defaulting |
@pmorie yes, that is accurate 🤗 |
/hold cancel |
In case of a controller upgrade, we may still store previous versions of resource that may not have been the default set. This migrates those "in memory" to make sure we do not panic in those cases. This also gives a great example of how to use a mutating webhook to migrate some resources from one version to another. Signed-off-by: Vincent Demeester <[email protected]>
451d0b4
to
fbfbfea
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bobcatfish, 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 |
The following is the coverage report on pkg/.
|
/lgtm |
/test pull-tekton-pipeline-integration-tests |
Changes
In case of a controller upgrade, we may still store previous versions
of resource that may not have been the default set. This migrates
those "in memory" to make sure we do not panic in those cases.
This also gives a great example of how to use a mutating webhook to
migrate some resources from one version to another.
/priority critical-urgent
/cc @bobcatfish
Signed-off-by: Vincent Demeester [email protected]
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 and TaskRun to build and release this image
Release Notes