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

add support to create webhook configuration when webhooks is enabled #120905

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kmala
Copy link
Member

@kmala kmala commented Sep 26, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

The changes would create/update the validation webhook configuration if webhooks are enabled as part of the cloud controller and is an extension of #108838.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Added the ability to create a validating webhook configuration as part of the cloud controller manager bootstrap.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: [KEP-2699](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cloud-provider/2699-add-webhook-hosting-to-ccm)

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 26, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @kmala. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 26, 2023
@kmala
Copy link
Member Author

kmala commented Sep 26, 2023

/sig cloud-provider

@k8s-ci-robot k8s-ci-robot added sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. area/cloudprovider and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 26, 2023
@elmiko
Copy link
Contributor

elmiko commented Sep 27, 2023

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 27, 2023
CABundle: []byte(webhooksConfig.CaBundle),
}
}
kubeClient := clientBuilder.ClientOrDie("ccm")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is ccm the right client name? I think that name shows up in the audit logs, so I'm wondering if we want a suffix to make it clear what aspect of the ccm is making these calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

ccm-webhook ?

Copy link
Member

Choose a reason for hiding this comment

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

+1

}
}
}
if webhookConfigs.Len() != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

So the behavior here is that we need a 1:1 mapping of enabled webhooks to webhook configs, right? I think that makes sense. The only case I'm thinking of is where a user wants to disable the webhook and reenable it later, but I think its better to force them to remove the config because that way its explicit what webhooks exist based on the configuration and the webhook names.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that correct. Since both are configs provided by the user i felt its better to force to update both places.

// CaBundle is the ca certs to be used by apiserver for validating the webhook server certs.
CaBundle string
// ValidationWebhookConfiguration is the config used for creating validation webhook config object.
ValidationWebhookConfiguration *admissionregistrationv1.ValidatingWebhookConfiguration
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to allow the user to choose between validating and mutating webhooks on a per-webhook basis?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Per @cheftako we may want to allow providers to choose, but they may not want their customers to choose.

@andrewsykim
Copy link
Member

/assign @cheftako

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 7, 2023
@elmiko
Copy link
Contributor

elmiko commented Dec 20, 2023

discussed today at sig cloud provider meetings, needs a few more reviews here.

@cheftako has offered to take point on the review requests

@kmala
Copy link
Member Author

kmala commented Feb 23, 2024

@cheftako can you please review when you get chance

@dims
Copy link
Member

dims commented Mar 7, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 7, 2024
@kmala
Copy link
Member Author

kmala commented Mar 15, 2024

/retest

@kmala kmala force-pushed the ccmwebhook branch 2 times, most recently from 54442a5 to 612c052 Compare March 15, 2024 17:30
@kmala
Copy link
Member Author

kmala commented Mar 15, 2024

/retest

@kmala kmala force-pushed the ccmwebhook branch 2 times, most recently from 737a281 to 9164613 Compare March 15, 2024 21:02
@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. labels Mar 15, 2024
@kmala kmala force-pushed the ccmwebhook branch 3 times, most recently from 4a86b5a to 57f032d Compare March 21, 2024 21:28
@kmala
Copy link
Member Author

kmala commented Mar 21, 2024

/test pull-kubernetes-dependencies

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kmala
Once this PR has been reviewed and has the lgtm label, please ask for approval from cheftako and additionally assign msau42 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kmala
Copy link
Member Author

kmala commented Mar 22, 2024

/retest-required

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Mar 22, 2024

@kmala: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-e2e-gce-providerless 3c2a8c6 link false /test pull-kubernetes-e2e-gce-providerless
pull-kubernetes-verify 3c2a8c6 link true /test pull-kubernetes-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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 understand the commands that are listed here.

Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

this is generally making sense to me, and i don't see anything in the code that is concerning. i would like to play with the unit tests and run this locally to get a feel for how it works.

but i think on balance this is looking good to me

// CaBundle is the ca certs to be used by apiserver for validating the webhook server certs.
CaBundle string
// ValidatingWebhookConfiguration is the config used for creating validation webhook config object.
ValidatingWebhookConfiguration *admissionregistrationv1.ValidatingWebhookConfiguration
Copy link
Member

Choose a reason for hiding this comment

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

I'm very confused about what is going on here... why are we expecting to apply defaulting from REST APIs to fields of this config file?

@@ -162,6 +168,97 @@ the cloud specific control loops shipped with Kubernetes.`,
return cmd
}

func createOrUpdateWebhookConfiguration(ctx context.Context, webhooks map[string]WebhookHandler, webhooksConfig cloudproviderconfig.WebhookConfiguration, clientBuilder clientbuilder.SimpleControllerClientBuilder) error {
Copy link
Member

Choose a reason for hiding this comment

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

This self-registration of webhooks is really tricky to get right... I had no idea this was being contemplated to be added into cloud-controller-manager

some quick observations:

  1. it's not clear why having CCM create this programatically is better than applying a manifest
  2. does having CCM do this mean that multiple CCM controllers duel when the configuration changes?
  3. is the WebhookAddress expected to point to the CCM instance? how does routing work when there are multiple CCM instances?
  4. how do multiple CCM controllers handle rollout of a new webhook / configuration? all instances have to understand the new endpoints or fail open when requests to unknown endpoints arrive

Copy link
Contributor

Choose a reason for hiding this comment

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

great questions @liggitt , i was not aware of the complexity around the self-registration but it makes perfect sense once you've laid it out. i think this might cause us to reconsider the methodology here, it seems like using a manifest would make a better experience for users and help with some of the ordering/dueling issues.

thanks for the review!

Comment on lines +219 to +226
currentConfiguration, err := kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Get(ctx, webhooksConfig.ValidatingWebhookConfiguration.Name, metav1.GetOptions{})
if err != nil {
klog.ErrorS(err, "Unable to create validating webhook configuration with API server, error getting existing webhook configuration", "webhookconfiguration", webhooksConfig.ValidatingWebhookConfiguration.Name)
return fmt.Errorf("unable to get validating webhook configuration from API server %w", err)
}
currentConfiguration.Webhooks = webhooksConfig.ValidatingWebhookConfiguration.Webhooks

_, err = kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Update(ctx, currentConfiguration, metav1.UpdateOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

how does this avoid dueling registration from other CCM instances?

// SetDefaults_ValidatingWebhook sets defaults for webhook validating. This function
// is duplicated from "k8s.io/kubernetes/pkg/apis/admissionregistration/v1/defaults.go"
// in order for in-tree cloud providers to not depend on internal packages.
func SetDefaults_ValidatingWebhook(obj *admissionregistrationv1.ValidatingWebhook) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think any defaulting is required here... the defaulting gets applied when creating against the server

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 6, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-sigs/prow repository.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 5, 2024
@elmiko
Copy link
Contributor

elmiko commented Dec 5, 2024

i think this is still an important feature to work on, but i'm not sure we have the time/resources to push it further currently.

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cloudprovider area/code-generation area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/release Categorizes an issue or PR as relevant to SIG Release. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants