Commit Graph

138 Commits

Author SHA1 Message Date
Victor Agababov c451e3c37f
Various cleanups around the codebase (#1630)
* Various cleanups around the codebase

- unindent the else after return
- make things private that are not used anywhere
- rearrange params
- etc

* add
2020-08-17 19:11:13 -07:00
Scott Nichols 7b92ffa783
filter "control-plane" labeled namespaces out of our webhooks (#1592)
* include a filter on control plane namespaces for defaulting and validation webhooks from knative/pkg

* Update unit tests to include control-plane

* adding a comment to explain why we are adding 'control-plane' to the webhook config
2020-08-07 14:23:29 -07:00
Victor Agababov 08156c67f6
Use slow lane to do global resync (#1528)
* Use slow lane to do global resync

* cmt

* yolo

* yolo v2

* fix log str

* fixes

* publicize things

* renamemove
2020-07-21 13:11:54 -07:00
Victor Agababov acd3f31714
nits (#1529) 2020-07-20 18:44:35 -07:00
Victor Agababov 1cea86c85f
Use two lane queue instead of the regular workqueue (#1514)
* Use two lane queue instead of the regular workqueue

- we need to poll for len in the webhook tests because we have async propagation now, and check at the wrong time will be not correct.
- otherwise just a drop in replacement.

* update test

* cmt

* tests hardened
2020-07-19 14:01:34 -07:00
Matt Moore e193c4be24
Implement a new shared "Drainer" handler. (#1517)
* Implement a new shared "Drainer" handler.

This implements a new `http.Handler` called `Drainer`, which is intended to wrap some inner `http.Handler` business logic with a new outer handler that can respond to Kubelet probes (successfully until told to "Drain()").

This takes over the webhook's relatively new probe handling and lame duck logic with one key difference.  Previously the webhook waited for a fixed period after SIGTERM before exitting, but the new logic waits for this same grace period AFTER THE LAST REQUEST.  So if the handler keeps getting (non-probe) requests, the timer will continually reset, and once it stops receiving requests for the configured grace period, "Drain()" will return and the webhook will exit.

The goal of this work is to try to better cope with what we believe to be high tail latencies of the API server seeing that a webhook replica is shutting down.

Related: https://github.com/knative/pkg/issues/1509

* Switch to RWLock
2020-07-17 21:25:34 -07:00
Matt Moore 0f78f8a8cc
Disable keep-alives on shutdown. (#1511)
See also: https://github.com/knative/pkg/issues/1509#issuecomment-659737054
2020-07-16 16:55:33 -07:00
Victor Agababov ac02cac99b
Preallocate sets in pkg (#1485) 2020-07-14 00:09:18 -07:00
Victor Agababov eb05e8dd5b
Various cleanups (#1446)
Thanks @markusthoemmes for the tool :)
2020-06-24 14:04:28 -07:00
Dave Protasowski 5be32bbb99
Return TypeMeta as part of the admission response (#1444) 2020-06-24 08:54:27 -07:00
Weston Haught 602857dcc5
add self to aliases and add reviewers to OWNERS (#1409)
* add self to aliases and add reviewers to OWNERS

* fix typo
2020-06-22 12:30:27 -07:00
Dave Protasowski 02c28cd5ff
Return TypeMeta as part of the conversion response (#1433)
This is a requirement when adopting CRD v1 APIs
2020-06-22 08:29:27 -07:00
Matt Moore bfc0cee945
Implement the second wave of per-reconciler leaderelection (#1302)
* Implement the second wave of per-reconciler leaderelection.

Detailed design: https://docs.google.com/document/d/1i_QHjQO2T3SNv49xjZLWlivcc0UvZN1Tbw2NKxThkyM/edit#
Issue: https://github.com/knative/pkg/issues/1181

* incorporate vagababov feedback

* Improve controller.go coverage
2020-06-19 09:47:25 -07:00
Dave Protasowski caa444033b
use crd & webhook v1 APIs (#1391) 2020-06-19 08:43:25 -07:00
Mike Petersen 086ff43956
Allows for webhooks to exclude certain namespaces (#1399)
* Allows for webhooks to exclude certain namspaces

Added a namespaces selector to the mutating webhook configuration which
allows for excluding namespaces from the webhook

Fixes #1379

* Updated skipWebhooks key to skip-webhooks for defaulting and validating
webhooks

* Updated table tests with new label

* Updated key name to webhooks.knative.dev/exclude
2020-06-15 18:11:24 -07:00
Markus Thömmes f1416d3e62
Only validate ConfigMaps the webhook knows about. (#1395) 2020-06-09 10:29:32 -07:00
jpower432 7ed1d4a552
Added common name to cert tmpl (#1384)
* Added common name to cert tmpl

Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>

* Added a common name test to TestCreateCert function

* Update webhook/certificates/resources/certs_test.go

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Update webhook/certificates/resources/certs_test.go

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Applied changes to improve formatting and style

* Update webhook/certificates/resources/certs_test.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* Update webhook/certificates/resources/certs_test.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* Added Subject to caParsedCert CommonName check

* Fixed failure message to remove reference to diff

* Update webhook/certificates/resources/certs_test.go

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Update webhook/certificates/resources/certs_test.go

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Update webhook/certificates/resources/certs.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* Update webhook/certificates/resources/certs.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* Update webhook/certificates/resources/certs.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

Co-authored-by: Victor Agababov <vagababov@gmail.com>
Co-authored-by: Matt Moore <mattmoor@vmware.com>
2020-06-06 15:44:18 -07:00
Julian Friedman 7b4093b435
Use annotation rather than label for configmap checksum (#1380) 2020-06-05 04:26:17 -07:00
Markus Thömmes b0dc3661a7
Use a hexadecimal representation for the example checksum. (#1374) 2020-06-03 08:33:18 -07:00
Markus Thömmes f45b641fc2
Check example-checksum label for consistency in ConfigMap webhook. (#1366)
* Check example-hash label for consistency in ConfigMap webhook.

We've seen users try to edit our configuration and falling into the trap of editing the '_example' block a lot. This attempts at guiding the users to do "the right thing" by checking the ConfigMap's '_example' value (if present) against a precomputed hash of the same value (if present). The idea is that we precompute this has using the tool herein in code generation and thus allow us to easily change the example block automatically while making it hard to change it on ppurpose. If the hashes don't match on an upgrade, the webhook will return an error synchronously, guiding the user to the correct behavior.

* Add tests.

* Add hash check to test utilities.

* Add a bit of coverage.

* Rewrite into a table test.

* Rename.

* Reduce test surface.

* Godoc.

* Code nits.

* Docs.

* Use CRC32.

* Nits.
2020-06-02 10:48:17 -07:00
Victor Agababov 389d28f9b6
Use the generic networking constant for shutdown (#1365)
- use standard const, which is better
- stop modifying the default in the test, which is ugh a bit :)
2020-05-29 09:47:02 -07:00
Dave Protasowski b0e3201ad2
Kubelet probes would result in the webhook writing the HTTP status twice (#1355)
* Kubelet probes would result in the webhook writing the HTTP status twice

Doesn't seem like it affected anything - just writes out some extra
log messages

* nits

* nits

* nits

* nits
2020-05-26 10:34:50 -07:00
Victor Agababov 18ed8c75b6
Add the key of the object to the log context (#1348)
* Add the key of the object to the log context

We don't log _what_ we convert, but only _what type_ it is.
And it's not very useful
So log all the stuff

* issues

* redo
2020-05-25 12:49:47 -07:00
Jihui Nie 3c29a1ce89
Add helper function to read webhook port number from env var (#1162)
* Add helper function to read port number from env var

* Add check for port == 0

* Add the unit test

* Update error message

Co-Authored-By: savitaashture <sashture@redhat.com>

* Panic when env var is set but invalid

* Rename the func to be PortFromEnv.

* Apply suggestions from code review on error message

Co-authored-by: Victor Agababov <vagababov@gmail.com>

* Join defers

Co-authored-by: savitaashture <sashture@redhat.com>
Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-05-16 18:43:02 -07:00
Matt Moore b52862b1b3
Implement the K8s lifecycle in webhook. (#1318)
* Implement the K8s lifecycle in webhook.

The webhook never properly implemented the Kubernetes SIGTERM/SIGKILL
lifecycle, and doesn't even really support readiness probes today.  This
change enables folks to use a block like this on their webhook container:

```yaml
        readinessProbe: &probe
          periodSeconds: 1
          httpGet:
            scheme: HTTPS
            port: 8443
            httpHeaders:
            - name: k-kubelet-probe
              value: "webhook"
        livenessProbe: *probe
```

With this, the webhook won't report as `Ready` until a probe has succeeded,
and when the SIGTERM is received, we will start failing probes for a grace
period (so our Endpoint drops) before shutting down the webhook's HTTP Server.

This was uncovered by running the webhook across 10 replicas in Serving with
the "Goose" (https://github.com/knative/pkg/pull/1316) enabled for the e2e
tests.  The failure mode I saw was conversion webhook requests failing across
random tests.

This also moves the Serving probe-detection function into PKG.

* Increase the log level when we start to fail probes

* Wait for go routines to terminate on all paths.
2020-05-09 16:44:45 -07:00
Yanwei Guo 19b1d7b64d
Add a helper func to set a default metric config for unit tests (#1263)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* add a comment

* fix typo

* fix tests

* revert

* revert tests

* revert

* fix conflicts

* one more test file
2020-05-07 21:11:45 -07:00
Markus Thömmes d29cf98a77
Assorted linting fixes. (#1249)
* Remove unused code.

* Use raw strings to avoid escaping.

* Remove unneeded type conversions.

* Preallocate slices where possible.

* Use semantic equality in psbinding reconciler.
2020-04-28 08:20:51 -07:00
Victor Agababov 5ba6c1d101
Change %v to %w in errors and other nits (#1252)
* Change %v to %w in errors and other nits
Other are things I noticed when fixing the main %v->%w conversion

* fold
2020-04-27 15:04:51 -07:00
Matt Moore 8c3cf6f2ee
Fix the webhook workqueue names (#1245) 2020-04-25 10:08:49 -07:00
Markus Thömmes e983887dc4
Change default port in webhook test to 8443. (#1242)
A lot of systems have something running that responds on 443, i.e. a local test environment or a webserver.
2020-04-24 10:49:49 -07:00
Shashwathi 4945766b29
Manually print all elements of response object (#1241)
Signed-off-by: Shash Reddy <shashwathireddy@gmail.com>

Co-authored-by: Andrew Su <asu@pivotal.io>
2020-04-23 13:03:31 -07:00
Lukas Berk 0e31d66795
Sinkbinding Webhook should label namespace for inclusion (#1208)
* First hack at getting the namespaces of interest to the ps

* Have the webhook label the namespace for inclusion

* Fix unit tests

* Update with feedback

* Add namespace lister, use constants

* Add one more err logging statement
2020-04-21 09:29:36 -07:00
whaught 9d7c06b6ab
Allow Delete verb on validation callbacks (#1219)
* Create IsInDelete context

* Set up context with WithinDelete

* Test for callback delete

* fix subresource update

* Return oldObj for deletes

* include delete in webhook config

* include delete in unit test

* don't log on delete
2020-04-16 18:30:48 -07:00
whaught d22642244e
Allow Unstructured callback from Validating Webhook (#1172)
* Add new callback pattern to pkg

* include the context

* typo

* Remove the empty instance of unstructured

* initialize the unstructured var

* Eliminate the unneeded pointer

* Pass a pointer to unstructured callback

* Create a validation specific context struct

* Move callback tests to own unit test case

* Switch from converting to decoding

* Update webhook/resourcesemantics/validation/validation.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* don't wrap context and include params

* split validation files

* include 2020 copyright

* include unit test for WithKubeClient

* Don't bother updating copyright date

* Inclue a unit test for panic

* Move dryRun to context

* Include context dry run unit test

* put the request operation in the context

* eliminate circular dep

* move kubeclient test out of context_test

* dont bother iterating callback map

* Callback takes a list of supported verbs

* Remove extra type

* Ensure Callback interface is public

* Alias Operation into validation

* alias Operation right in Webhook

* Update webhook/resourcesemantics/validation/validation_admit.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit_test.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit_test.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* Update webhook/resourcesemantics/validation/validation_admit_test.go

Co-Authored-By: Victor Agababov <vagababov@gmail.com>

* correct parens

* minor style fixes

* Rename Callback to Func

* Fix build error

* Switch callback to take a list with a factory

* keep descriptive names

* update comment

* Drop pointer, correct comments

* Add a unit test to disallow duplicate verbs

* fix comments, struct{} for set

* switch to variadic arg for NewCallback

Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-04-06 12:22:19 -07:00
Markus Thömmes 3506048289
t.Fatal must not be called in a goroutine. (#1194)
* t.Fatal must not be called in a goroutine.

* Add early return statements.
2020-04-06 08:27:19 -07:00
Markus Thömmes 83edd9f30d
Add augmented logger to the context to pass it down. (#1192) 2020-04-06 08:21:27 -07:00
Markus Thömmes c09083a601
Fix a few simple linter warnings: unused code, govet warnings etc. (#1191) 2020-04-06 08:21:20 -07:00
Matt Moore e2ee5bed78
Start the webhook before informers sync. (#1180)
* Start the webhook before informers sync.

Some webhooks (e.g. conversion) are required to list resources, so by delaying those until after informers have synced, we create a deadlock when they run in the same process.  This change has two key parts:
1. Start the webhook immediately when our process starts, and issue a callback from sharedmain when the informers have synced.
2. Block `Admit` calls until informers have synced (all conversions are exempt), unless they have been designated by implementing `webhook.StatelessAdmissionController`.

Our built-in admission controllers (defaulting, validation, configmap validation) have all been marked as stateless, the main case where we want to block `Admit` calls is when we require the informer to have synchronized to populate indices for Bindings.

* Add missing err declaration
2020-03-30 18:14:50 -07:00
Matt Moore be54585f8f
Drop the logic to create missing secrets. (#1154)
This is a carry-over from when this was originally written and we had webhooks and secrets being GC'd due to a bad owner reference.
2020-03-16 11:36:31 -07:00
Matt Moore 1893541a0f
Scope the webhook secret informers to the system namespace. (#1158) 2020-03-12 18:29:29 -07:00
Victor Agababov a572b9922a
Remove named returns, since they look icky :) (#1151)
In general, imo, it's prettier to return things as is, rather than the pattern that was
there.
Also handle one more error case, which was kind of ignored before (probably in practice
impossible, but idk)
2020-03-10 14:39:29 -07:00
Victor Agababov 507b519649
Fix some nits in the webhook code (#1150) 2020-03-10 10:36:29 -07:00
Cong Liu 55831d9ef7
Add an option to specify the selector for psbinding webhook. (#1123) 2020-02-24 13:24:08 -08:00
Dave Protasowski d771641c91
Fixed #1057 - Rename ConvertUp/Down to ConvertTo/From (#1122) 2020-02-24 09:44:08 -08:00
Mike Petersen a2e3b66654
Renews a webhook cert before it expires (#1101)
* Renews a webhook cert before it expires

* Moved checks out of webhook and into certificate

* Updated error messages and others from review

* Updated error messages and changed time comparison

* Added two tests cases for checking expiration

* Fixed issue with missing "." in webhook.go
2020-02-22 12:33:08 -08:00
Matt Moore 3bada55aab
Drops the Serving-specific stats reporter logic from knative/pkg (#1114) 2020-02-21 10:02:07 -08:00
cshou 1cc3c3e852
Update jsonpatch lib that correctly handle object removal (#1078)
* update jsonpatch lib

* add more patch tests for removal
2020-02-12 08:27:22 -08:00
Timur Zununbekov a805892837
Handle wrong apiVersion/kind in SinkBinding subject (#1067)
* Handle case with unavailable subject in psbinding

* Added test for finalizing forbidden subject
2020-02-11 06:09:08 -08:00
Victor Agababov 41aec11a3c
Use new RecordBatch method to join metric reporting (#1029)
* Use new RecordBatch method to join metric reporting

* review
2020-02-03 16:27:30 -08:00
Dave Protasowski 88d4536182
Conversion Webhook Framework (#993)
* ConversionController implementation

This controller will reconcile target CRDs with the correct
conversion webhook configuration. Specifically, the HTTP path and
CA bundle will be updated.

Additionally, the conversion controller will perform the given
conversions through a hub and spoke model utilizing the
apis.Convertible interface.

* Webhook now can host ConversionControllers

* injection/sharedmain now supports webhook.ConversionControllers

These conversion controllers will be hosted by the webhook that
the sharedmain will start

* support defaulting & include godoc
2020-02-03 08:59:29 -08:00