Commit Graph

158 Commits

Author SHA1 Message Date
Victor Agababov 5807b6f9ee
Fix the error/warn log usage (#1839)
* Fix the error/warn log usage

zap doesn't do this well, when errors are not presented without zap.Error

* nits
2020-10-23 13:06:37 -07:00
Lionel Villard 7a4b522241
restrict defaulting and validation webhook to resource and status subresource only (#1833) 2020-10-23 10:56:38 -07:00
Josh Soref b39d5da935
Spelling (#1797)
* spelling: adopted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: aliased

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: apierrs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assignment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: coexistence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: commit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversions

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: creates

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: custom

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: determine

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: different

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: distribution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: duplicate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: editing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: endpoint

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: environment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: implementation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: identified

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: ignore

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: indicates

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interface

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interleaved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: labels

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: label

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mimic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: namespaced

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: organization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: populatable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: prometheus

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: refer

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reference

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: repetitive

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: response

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: something

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: spoofing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: synchronized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: this

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: trailing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unsupported

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: validation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* chore: reviewdog go header boilerplate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-10-18 14:22:57 -07:00
tianfeiyu 975a1cf9e4
feat: get cluster domain use utility (#1795) 2020-10-11 15:54:16 -07:00
Victor Agababov 7bad843466
Enable golint and exclude some other generated or additional dirs (#1783)
* Enable golint and exclude some other generated or additional dirs

Also remove `test` ignore, since it's covered by path ignore rule.

* meh

* fixes

* more

* progressing

* further

* like a boss
2020-10-07 14:58:20 -07:00
Victor Agababov 247841408e
Apply the cleanup to the pkg (#1776)
* Apply the cleanup to the pkg

This is probably the final iteration of my cleanup application.

* codegen

* one more try
2020-10-05 21:41:20 -07:00
Victor Agababov 1e373a9e5d
take 2 (#1755) 2020-09-29 14:10:29 -07:00
Victor Agababov a371418524
v2 (#1754) 2020-09-29 13:18:29 -07:00
Markus Thömmes 5fbbde31b3
Align linters with serving (enables stylecheck and asciicheck) (#1738) 2020-09-23 07:37:40 -07:00
Markus Thömmes 754da4653a
Enable unparam linter to catch unused parameters (#1731) 2020-09-22 09:13:40 -07:00
Markus Thömmes e4ecf702a3
Apply gosec checks to the codebase, except tests. (#1725)
* Apply gosec checks to the codebase, except tests.

* Fix YAML whitespace.

* Tune back file mode change and add a comment.
2020-09-22 08:55:40 -07:00
James Turley 62c718260c
Remove resource_name tag from webhook stats (#1464)
Common use cases for this webhook involve using Kubernetes's
generateName API to randomise resource names (this is a good
idea in Tekton pipelines, for example, where there are uniqueness
constraints. That means that the webhook metrics here end up with
very high cardinality, which makes Prometheus fall over. Even
without generateName, it is possible to shoot oneself in the foot.
This commit just removes the resource_name label altogether.
2020-09-21 12:09:49 -07:00
Victor Agababov ddf2cbe3c1
Various nits around the code (#1719)
* Various nits around the code

* stagger
2020-09-18 16:22:45 -07:00
Riccardo Piccoli 27275cae24
add subresource reconciler for bindings BaseReconciler (#1712) 2020-09-18 15:26:45 -07:00
Tsubasa Nagasawa 9c6ca07aaf
Remove patch detail for webhook being logged on info (#1702)
* Remove patch detail for webhook being logged on info

It might contain the sensitive data so print it to debug log

* Pass admission review info to the fields in structured logging

* Remove knative namespace from admission webhook logkey

* Use loosely-typed key-value pairs for suggered logger in admission wb

* Move admission specific logkey to local package

* Print patch type with patch body on debug log
2020-09-18 10:23:45 -07:00
Zbynek Roubalik 2d4efecc6b
bump to k8s 1.18 (#1428)
* bump to k8s 1.18.8

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>

* plumbing ctx through

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>

* add more ctx plumbing

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>

* ctx WithCancel()

Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
2020-09-11 07:54:00 -07:00
Markus Thömmes 07fa902e49
Enhance error message on failure to update _example. (#1698)
We still see users frequently struggle with this and the error message seemingly doesn't help them. This gives a more explicit description of what the user can do to fix the situation.
2020-09-10 07:18:51 -07:00
Scott Nichols b4c9a6da30
do not fight with azure's webhook for webhooks (#1696) 2020-09-09 16:37:51 -07:00
Matt Moore 3ff7bcc422
Remove spammy log line (#1687)
Fixes: https://github.com/knative/pkg/issues/1686
2020-09-07 10:55:32 -07:00
Victor Agababov 34838c4559
Remove all ClearAll calls from pkg UTs (#1654)
We need this in order to deprecate the function.
Serving is already free of those.
2020-08-27 13:13:07 -07:00
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