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 2: trigger plans manually #1352

Merged
merged 13 commits into from
Mar 9, 2020
Merged

KEP-20 part 2: trigger plans manually #1352

merged 13 commits into from
Mar 9, 2020

Conversation

zen-dog
Copy link
Contributor

@zen-dog zen-dog commented Feb 19, 2020

Summary:

  • current ValidationWebhookConfiguration is replaced by MutatingWebhookConfiguration. Instance admission webhook is now setting the Spec.PlanExecution.PlanName on updates/creates
  • kudo-manager-instance-validation-webhook-config webhook (when active) is enforcing all rules around triggering plans directly (manually) and indirectly (through Instance updates), making sure that no conflicting plans are running
  • new cli command $ kubectl kudo plan trigger --name deploy --instance dummy-instance is available to trigger a plan manually
  • manually triggering plans is only possible when webhooks are enabled (kudo init --webhook=InstanceValidation ...)

Note:

  • change: Instance CRD got updated
  • heavily change: ValidationWebhookConfiguration from previous KUDO version (in case webhooks were used) has to be removed manually

What this PR does / why we need it:

Fixes #649 #741

@zen-dog zen-dog force-pushed the ad/kep-20 branch 2 times, most recently from bff7f29 to a441ee6 Compare February 21, 2020 14:46
Summary:
- current `ValidationWebhookConfiguration` is replaced by `MutatingWebhookConfiguration` to allow instance admission webhook to set the `Spec.PlanExecution.PlanName`
- `Spec.PlanExecution.PlanName` is now not required anymore

Note:
- Instance CRD got updated
- breaking change: ValidationWebhookConfiguration from previous KUDO version (in case webhooks were used) has to be removed manually

Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
so that when the same plan is re-triggered a new UID is generated and the controller can restart the plan.

Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
…instance

additionally, instance controller now properly handles the cases where the webhooks are enabled and where they are disabled.

Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
@@ -116,6 +128,85 @@ func (i *Instance) PlanStatus(plan string) *PlanStatus {
return nil
}

// annotateSnapshot stores the current spec of Instance into the snapshot annotation
Copy link
Contributor Author

@zen-dog zen-dog Feb 28, 2020

Choose a reason for hiding this comment

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

Moved here from the instance_controller as they're needed in the webhook too.

new command `kudoctl plan trigger --name=<planNam> --instance=<instanceName>` is now available

Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
@zen-dog zen-dog marked this pull request as ready for review March 3, 2020 12:30
@zen-dog zen-dog added release-highlight release/breaking-change This PR contains breaking changes and is marked in the release notes labels Mar 3, 2020
Copy link
Member

@ANeumann82 ANeumann82 left a comment

Choose a reason for hiding this comment

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

First pass, more to come

pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/plan.go Show resolved Hide resolved
pkg/kudoctl/kudoinit/prereq/webhook.go Outdated Show resolved Hide resolved
pkg/webhook/instance_admission.go Outdated Show resolved Hide resolved
// 2. Cleanup plan exists in the operator version and has *never run* before
// 3. Cleanup hasn't been scheduled yet (first time the deletion is being reconciled)
// we set the Spec.PlanExecution.PlanName = 'cleanup'
hasToScheduleCleanupAfterDeletion := func() bool {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason that these are inline funcs? I'd rather have them outside as actual funcs or just plain code in this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since they're only used once inside this method, they would otherwise "pollute" the controller namespace. I prefer to inline them to give a "speaking name" to otherwise complicated check.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I get the "pollution" argument, although I blame go for it ;)

Still, I wouldn't mind having just the simple booleans inside this func instead of full functions that are only called once, but it's not a blocker for me. Just looks weird.

@ANeumann82 ANeumann82 added release/highlight This PR is a highlight for the next release and removed release-highlight labels Mar 4, 2020
Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
Copy link
Member

@ANeumann82 ANeumann82 left a comment

Choose a reason for hiding this comment

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

I'm not sure if we should keep the webhooks optional now, but... This looks ok so far.

// 2. Cleanup plan exists in the operator version and has *never run* before
// 3. Cleanup hasn't been scheduled yet (first time the deletion is being reconciled)
// we set the Spec.PlanExecution.PlanName = 'cleanup'
hasToScheduleCleanupAfterDeletion := func() bool {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I get the "pollution" argument, although I blame go for it ;)

Still, I wouldn't mind having just the simple booleans inside this func instead of full functions that are only called once, but it's not a blocker for me. Just looks weird.

@ANeumann82
Copy link
Member

I'd like to see at least one more review on this though. It's a big PR ;)

@zen-dog
Copy link
Contributor Author

zen-dog commented Mar 4, 2020

I'd like to see at least one more review on this though. It's a big PR ;)

absolutely! 💯

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 was not able to finish the review, will come back to it tomorrow, sorry

cmd/manager/main.go Outdated Show resolved Hide resolved
pkg/kudoctl/kudoinit/prereq/webhook.go Outdated Show resolved Hide resolved
pkg/kudoctl/kudoinit/prereq/webhook.go Outdated Show resolved Hide resolved
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.

Did my first full pass :) I need to go over the webhook logic one more.

Most comments are nits, there are two bigger things I think we should take a look at (controller logic + that namespace default)

Overall nice work 👏

cmd/manager/main.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/plan/plan_trigger.go Show resolved Hide resolved
pkg/kudoctl/util/kudo/kudo.go Show resolved Hide resolved
pkg/webhook/instance_admission.go Outdated Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
Proper namespace handling for CREATEd instances, robust detection of instances deletion life-cycle and logging improvements

Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
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.

👏 nice work, the logic is very complex but you did a great job documenting it!

My only bigger concern is - you cannot trigger plan when running kudo without webhooks. I was always thinkig about the whole thing in this way:

  • kudo without webhooks is only suitable for newcomers who want to quickly start something locally and run some very basic operator like cowsay and see what kudo is doing and play around with its features OR for developers of operators who run local and know what they are doing since no webhooks are not giving you consistency guarantees
  • with webhooks for ALL OTHER CASES

I think it will be misleading that you can trigger plans only for kudo running in cluster and with webhooks.

cmd/manager/main.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/plan.go Show resolved Hide resolved
pkg/kudoctl/util/kudo/kudo.go Show resolved Hide resolved
pkg/kudoctl/util/kudo/kudo_test.go Outdated Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
pkg/webhook/instance_admission.go Show resolved Hide resolved
Copy link
Member

@porridge porridge left a comment

Choose a reason for hiding this comment

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

Mostly nitpicks here and there, but the thing I'm concerned about is that we're adding a very complex component without integration tests.

cmd/manager/main.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
pkg/kudoctl/kudoinit/prereq/webhook.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/instance_types_helpers.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/plan/plan_trigger.go Outdated Show resolved Hide resolved
pkg/kudoctl/cmd/init_integration_test.go Outdated Show resolved Hide resolved
@zen-dog
Copy link
Contributor Author

zen-dog commented Mar 9, 2020

I think it will be misleading that you can trigger plans only for kudo running in cluster and with webhooks.

The bottom line is: KUDO API is edge-based which suits a lot of real-world practical scenarios really good. However, the only way KUDO operations stay consistent (and e.g. avoid data loss) is by guarding them with the webhook. While it was possible to run into inconsistent behavior without manually triggering plans, the later definitely exaggerates it. I'm strongly against allowing it without webhooks.

@alenkacz
Copy link
Contributor

alenkacz commented Mar 9, 2020

I think it will be misleading that you can trigger plans only for kudo running in cluster and with webhooks.

The bottom line is: KUDO API is edge-based which suits a lot of real-world practical scenarios really good. However, the only way KUDO operations stay consistent (and e.g. avoid data loss) is by guarding them with the webhook. While it was possible to run into inconsistent behavior without manually triggering plans, the later definitely exaggerates it. I'm strongly against allowing it without webhooks.

Then please at least make it obvious that it's not allowed from CLI, not just silently ignore it. Also document it with the reasoning 🙏 thanks

@zen-dog zen-dog dismissed porridge’s stale review March 9, 2020 19:38

I addressed all smaller issues and the bigger one (e2e test) will be a followup PR

@zen-dog zen-dog merged commit c6155ca into master Mar 9, 2020
@zen-dog zen-dog deleted the ad/kep-20 branch March 9, 2020 19:40
runyontr pushed a commit that referenced this pull request Mar 11, 2020
Summary:
- current `ValidationWebhookConfiguration` is replaced by `MutatingWebhookConfiguration`. Instance admission webhook is now setting the `Spec.PlanExecution.PlanName` on updates/creates
- `kudo-manager-instance-validation-webhook-config` webhook (when active) is enforcing all rules around triggering plans directly (manually) and indirectly (through Instance updates), making sure that no conflicting plans are running
- new CLI command `$ kubectl kudo plan trigger --name deploy --instance dummy-instance` is available to trigger a plan manually
- manually triggering plans is only possible when webhooks are enabled (`kudo init --webhook=InstanceValidation ...`)

**Notes**:
- **change**: Instance CRD got updated
- **heavy change**: `ValidationWebhookConfiguration` from previous KUDO version (in case webhooks were used) has to be removed manually

<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://github.com/kudobuilder/kudo/blob/master/CONTRIBUTING.md
2. Make sure you have added and ran the tests before submitting your PR
3. If the PR is unfinished, start it as a Draft PR: https://github.blog/2019-02-14-introducing-draft-pull-requests/
-->

**What this PR does / why we need it**:

<!-- 
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #649 #741 

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
release/breaking-change This PR contains breaking changes and is marked in the release notes release/highlight This PR is a highlight for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to manually run a plan
4 participants