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

KEP-20, Part 1: Extend admission webhook and implement Instance.PlanExecution #1188

Merged
merged 25 commits into from
Jan 28, 2020

Conversation

zen-dog
Copy link
Contributor

@zen-dog zen-dog commented Dec 16, 2019

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 and this test 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

@zen-dog zen-dog changed the title First PlanExecution draft. KEP-20: Manually triggered plan executions Dec 16, 2019
@zen-dog zen-dog force-pushed the fb/kep-20 branch 2 times, most recently from 6f03d74 to 9e6e6a3 Compare December 20, 2019 10:16
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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

nice tests 👏

Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@zen-dog zen-dog marked this pull request as ready for review January 20, 2020 15:14
@zen-dog zen-dog requested a review from nfnt as a code owner January 20, 2020 15:14
@zen-dog zen-dog changed the title KEP-20: Manually triggered plan executions KEP-20, Part 1: Extend admission webhook and implement Instance.PlanExecution Jan 20, 2020
Copy link
Contributor

@alenkacz alenkacz left a 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 :) 👏

config/crds/kudo.dev_instances.yaml Show resolved Hide resolved
pkg/apis/kudo/v1beta1/instance_admission.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/instance_admission.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/instance_admission.go Outdated Show resolved Hide resolved
}

// resetInstanceStatus clears Instance.Status to effectively restart existing plan
func resetInstanceStatus(instance *Instance) error {
Copy link
Contributor

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

Copy link
Contributor Author

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.

pkg/apis/kudo/v1beta1/instance_admission.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/instance_admission.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/instance_admission.go Outdated Show resolved Hide resolved
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 {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice tests 👏

Copy link
Contributor

@alenkacz alenkacz left a 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 👍

cmd/manager/main.go Outdated Show resolved Hide resolved
config/crds/kudo.dev_instances.yaml Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
// - <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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@zen-dog zen-dog merged commit 0ed9632 into master Jan 28, 2020
@zen-dog zen-dog deleted the fb/kep-20 branch January 28, 2020 14:03
ANeumann82 pushed a commit that referenced this pull request Feb 13, 2020
…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>
runyontr pushed a commit that referenced this pull request Mar 11, 2020
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants