-
Notifications
You must be signed in to change notification settings - Fork 104
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
KEP-20, Part 1: Extend admission webhook and implement Instance.PlanExecution
#1188
Conversation
PlanExecution
draft.6f03d74
to
9e6e6a3
Compare
Committed to start a discussion on the PE API.
All tests are green and the rules implemented. However, the implementation became complex and brittle.
- added a table explaining major compatibility rules - refactored `validateUpdate` method to be more straightforward and readable
@@ -90,3 +94,47 @@ func wasRunAfter(p1 PlanStatus, p2 PlanStatus) bool { | |||
} | |||
return p1.LastFinishedRun.Time.After(p2.LastFinishedRun.Time) | |||
} | |||
|
|||
// GetParamDefinitions retrieves parameter metadata from OperatorVersion CRD | |||
func GetParamDefinitions(params map[string]string, ov *OperatorVersion) []Parameter { |
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.
These were simply moved from the instance_controller.go
since they're now used in two places.
upgraded := idle.DeepCopy() | ||
upgraded.Spec.OperatorVersion = v1.ObjectReference{Name: "foo-operator-2.0"} | ||
|
||
tests := []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.
These tests cover all the rules defined in the instance_admission.go
webhook.
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 tests 👏
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.
🙇
@@ -0,0 +1,239 @@ | |||
package v1beta1 |
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.
You're better off switch to the Unified
diff view for this file.
Instance.PlanExecution
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.
Okay, done with the first pass :) This looks good, love the documentation and tests. I have couple of questions, but I think this is very close to being merge-able :) 👏
} | ||
|
||
// resetInstanceStatus clears Instance.Status to effectively restart existing plan | ||
func resetInstanceStatus(instance *Instance) error { |
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.
hmm does this really belong to webhook? 🤔 I kind of thought obnly controller modifies status
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 certainly does not. It was meant as a place-holder for now - I wasn't even sure if to implement it in this PR or in the next one.
case isParameterUpdate: | ||
// if the same plan is triggered by the update, we clean the Instance.Status to effectively restart the plan | ||
if *triggeredPlan == oldPlan { | ||
if err := resetInstanceStatus(old); err != 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.
I wonder if one even can update status in the hook, I hope yes. I mean in controller it's two requests... I hope that API server does not ignore those updates. I guess we could try it out :)
upgraded := idle.DeepCopy() | ||
upgraded.Spec.OperatorVersion = v1.ObjectReference{Name: "foo-operator-2.0"} | ||
|
||
tests := []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.
nice tests 👏
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 this looks great, left just couple of nits.
Just a general note - if we merge this right now, is master still releasable with this? I was at one point thinking it isn't because it's using fields controller is not interpreting but now I am actually starting to feel like it IS releasable since controller will still do the right thing even with this logic so 👍
pkg/webhook/instance_admission.go
Outdated
// - <nil> when there is no change to an existing scheduled plan | ||
// - '' empty string when an existing plan should be canceled (not implemented yet) | ||
// - 'newPlan' some new plan that should be triggered | ||
func validateUpdate(old, new *kudov1beta1.Instance, ov *kudov1beta1.OperatorVersion) (*string, error) { |
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 just realized few things about this PR while working on something in controller-runtime :)
- this should not be called validate as we're calling reset status in between
- also if you want to reset status, you need to transform the webhook from validating to mutating in the webhook config
perhaps this PR should go in without the reset and the rest should be in another PR?
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 don't mind, resetInstanceStatus
still returns nil
here.
…Execution` (#1188) This is part one of the KEP-20 implementation. **tl;dr**: - added new `Instance.Spec.PlanExecution` field that is populated (holding plan name) by the admission webhook either: - directly by the user through a manual plan trigger or - indirectly by the instance admission webhook on parameter updates or upgrades - `PlanExecution` field is ignored by the instance controller (yet), the later still has the old logic to decide what to do next. This will be part of part two of the implementation. - admission webhook (`instance_admission.go`) was extended with a set of rules guarding conflicting direct and indirectly triggered plans in combination with upgrades. See this beautiful (!) [table](https://github.com/kudobuilder/kudo/pull/1188/files#diff-3ee7e3fb450b5a364e3d9139fb154ad2R78) and this [test](https://github.com/kudobuilder/kudo/pull/1188/files#diff-c3a36ee52a0157a756e794446d2f4e6bR67) for more details. If an instance update is invalid, an error (status code and error message) will be returned to the user - KEP-20 was extended to reflect current implementation approach Co-authored-by: alenkacz <avarkockova@mesosphere.com> Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
…Execution` (#1188) This is part one of the KEP-20 implementation. **tl;dr**: - added new `Instance.Spec.PlanExecution` field that is populated (holding plan name) by the admission webhook either: - directly by the user through a manual plan trigger or - indirectly by the instance admission webhook on parameter updates or upgrades - `PlanExecution` field is ignored by the instance controller (yet), the later still has the old logic to decide what to do next. This will be part of part two of the implementation. - admission webhook (`instance_admission.go`) was extended with a set of rules guarding conflicting direct and indirectly triggered plans in combination with upgrades. See this beautiful (!) [table](https://github.com/kudobuilder/kudo/pull/1188/files#diff-3ee7e3fb450b5a364e3d9139fb154ad2R78) and this [test](https://github.com/kudobuilder/kudo/pull/1188/files#diff-c3a36ee52a0157a756e794446d2f4e6bR67) for more details. If an instance update is invalid, an error (status code and error message) will be returned to the user - KEP-20 was extended to reflect current implementation approach Co-authored-by: alenkacz <avarkockova@mesosphere.com> Signed-off-by: Thomas Runyon <runyontr@gmail.com>
This is part one of the KEP-20 implementation.
tl;dr:
Instance.Spec.PlanExecution
field that is populated (holding plan name) by the admission webhook either:PlanExecution
field is ignored by the instance controller (yet), the later still has the old logic to decide what to do next. This will be part of part two of the implementation.instance_admission.go
) was extended with a set of rules guarding conflicting direct and indirectly triggered plans in combination with upgrades. See this beautiful (!) table and this test for more details. If an instance update is invalid, an error (status code and error message) will be returned to the userCo-authored-by: alenkacz avarkockova@mesosphere.com