Commit Graph

67 Commits

Author SHA1 Message Date
Mathew Wicks 76cfa123ad
Fix `WEBHOOK_DISABLE_NAMESPACE_OWNERSHIP` env-var (#3107)
Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
2024-10-21 15:07:27 +00:00
Jonathan Innis c4843b746d
Give users the ability to disable namespace ownership of webhook configurations (#3095) 2024-09-26 01:31:27 +00:00
Dave Protasowski ee1db869c7
Update linter config and address lint warnings/failures (#3068)
* fix whitespace linter

* fix usestdlibvars

* fix staticheck

* ignore spancheck warning

* fix linter perfsprint

* fix nolintlint feedback

* fix nilerr lint checks

* fix misspell

* fix mirror lint

* fix intrange linter

* fix gofumpt linter

* fix gosec linter - ignore warning since default min tls version is 1.3

* fix gocritic linter

* fix whitespace

* fix fatcontext linter

* fix errorlint

* fix errname linter

* fix copyloopvar (go1.22) linter

* fix bodyclose linter

* update linter config

* add script to format code

* fix unit test
2024-06-25 14:49:36 +00:00
Dave Protasowski 8535fcc248
gofumpt the repo (#3067)
* gofumpt the repo

* don't prefix numbers with 0 - otherwise they're octal
2024-06-25 07:27:07 +00:00
Prashant Rewar fef5da99bd
Replace all usages of deprecated wait.PollImmediate with wait.PollUntilContextTimeout (#3004)
Signed-off-by: Prashant Rewar <108176843+prashantrewar@users.noreply.github.com>
2024-04-02 14:44:03 +00:00
cola a65a9e2510
lower log level for AdmissionController.Admit validation failures (#2905)
Signed-off-by: pingjiang <xiangpingjiang1998@gmail.com>
2024-01-08 15:09:14 +00:00
Hector Fernandez 4dbc3122f3
fix boilerplate (#2753)
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
2023-06-12 15:40:44 +00:00
Hector Fernandez 15605c78a2
Defaulting Controller options for all kind of webhooks (#2738)
* functional options

* move options to its own package

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add controller options to the webhook options

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* create custom options funcs for each webhook type

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* address comments from reviewers

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

---------

Signed-off-by: Hector Fernandez <hector@chainguard.dev>
Co-authored-by: dprotaso <dprotaso@gmail.com>
2023-06-12 08:38:02 +00:00
Matt Moore 92ed919344
Fix: Mute the linter on error return values. (#2627)
🐛 My previous change has revive/stylecheck warnings because I made the `warn` return value `[]error` and it wants the `error` last, which is kind of silly.

This mutes the linter on this signature, since it hits both revive and stylecheck

/kind bug
2022-11-02 19:46:06 +00:00
Matt Moore 198b463706
Cleanup: Turn multiple warnings into multiple warnings. (#2619)
🧹 Previously we lacked a public method for turning our `apis.FieldError` multi-error into a list of constituent error messages, so when we turned things into a webhook warning we simply used the combined serialization of all of the warnings.  Thanks to Nghia's recent change, we can now access the list of warnings to return as a list of errors.

/kind cleanup
2022-10-27 17:34:07 +00:00
Pierangelo Di Pilato fb2e4fbaa4
Preserve webhook namespaceSelector.matchLabels (#2605)
* Preserve webhook namespaceSelector.matchLabels

I have a webhook with this definition and the reconciler is
removing the matchLabels field:

Current resource:
```
				  namespaceSelector:
				    matchExpressions:
				    - key: webhooks.knative.dev/exclude
				      operator: DoesNotExist
				  objectSelector:
				    matchLabels:
				      app.kubernetes.io/component: kafka-dispatcher

```

Applied resource:
```
				    namespaceSelector:
				      matchExpressions: [ ]
				      matchLabels:
				        app.kubernetes.io/name: knative-eventing
				    objectSelector:
				      matchLabels:
				        app.kubernetes.io/component: kafka-dispatcher
```

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Optimize cases that don't need ensureLabelSelectorRequirements

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-10-06 21:14:31 +00:00
Pierangelo Di Pilato 717747b6ba
Register webhook GVKs for validating callbacks (#2590)
When a callback is registered for a gvk that isn't part of the
handlers that callback is never called since there is no webhook
rule associated with that GVK.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-09-14 07:19:48 +00:00
Ville Aikas a6afcab5bd
Fix #2115, allow selective verbs / subresources for webhooks. (#2547)
* WIP: just one option exploration.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Another option. New signature and new type for configuration.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Use interfaces and type assertions.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* log custom config with debug.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Address PR feedback.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
2022-08-24 01:10:17 +00:00
Ville Aikas f1f36a2c97
Fix subresource update logic. (#2546)
* Fix subresource update logic.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Rename IsInSubResourceUpdate => GetUpdatedSubresource

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
2022-07-15 18:32:28 +00:00
Paul Schweigert 5569169b0c
update boilerplate date (#2539)
Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>
2022-06-30 22:25:31 +00:00
Paul Schweigert aad4309963
sets mutating webhook ReinvocationPolicy to ifNeeded (#2472)
Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>
2022-06-07 15:53:37 +00:00
Matt Moore 16b36b7fca
Add support for admission webhook warnings. (#2498)
* Add support for admission webhook warnings.

This extends `apis.FieldError` to support designating certain FieldErrors as "warnings" (or explicitly as "errors", however, this is the default for back-compat).

You can turn an `apis.FieldError` into a warning using: `fe.At(apis.WarningLevel)` or force it into an error using: `fe.At(apis.ErrorLevel)`.

You can get the errors at a particular diagnostic level using: `fe.Filter(apis.WarningLevel)`.

This change also hooks this into the admission webhook infrastructure to support surfacing the "warning" level `apis.FieldError`s via the `Warnings` section of the `AdmissionResponse`.

Fixes: #2497

* Add a comment about the use of defer.
2022-05-02 21:56:57 +00:00
Pierangelo Di Pilato f4b57aef00
Fix invalid creator or lastModifier annotations on core resources (#2409)
When the admission request is for a resource with an empty string as
group, which happens on core resources, the `creator` or `lastModifier`
annotations are invalid since they become `/creator` or
`/lastModifier`.

This patch removes the `/` when group = `""`.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-01-31 06:49:30 -08:00
Pierangelo Di Pilato 0a429cba1c
Allow Unstructured callback from Defaulting Webhook (#2363)
* Add support for callback defaults

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Put unstr object in ctx and set user info

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Move get callback at the top

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Panic when using delete verb

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Split tests and add callback ctx tests

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Set user info annotations

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Register Webhook Rules from callbacks

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Adapt unstructured objects to apis.HasSpec

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Change json tag name to match struct field name

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-01-14 06:18:42 -08:00
knative-automation e61a20dd64
Update actions (#2313)
Signed-off-by: Knative Automation <automation@knative.team>
2021-10-15 12:26:13 -07:00
Dave Protasowski 0482448aac
allow unknown metadata fields (#2249)
* allow unknown metadata fields

* fix lint warnings

* include tests for nested structures in the metadata value
this is for catching any regressions
2021-09-02 07:33:06 -07:00
Matt Moore 9c7fd8e14f
Introduce `NewContext`, deprecate `NewImplFull`. (#2222)
* Introduce `NewContext`, deprecate `NewImplFull`.

Our generated `NewImpl` methods have long taken `context.Context`, but despite many iterations the forms we expose from our `controller` package never have.  This change contains several elements:
1. Expose a new `NewContext` method that takes `context.Context` in addition to the current `NewImplFull` signature.
2. Call `NewContext` instead of the deprecated `NewImpl` from our generated controller code.
3. Call `NewContext` from all our webhook reconcilers.

* Add a Tracker to controller.Impl to cut down on downstream boilerplate.
2021-08-21 14:00:34 -07:00
Markus Thömmes 35bcd16656
Drop redundant pointers and decoders (#2211) 2021-08-17 02:04:16 -07:00
NovaHe 8d21ce6c63
set webhooks OwnerReferences to namespace (#2044) (#2098) 2021-06-10 19:26:43 -07:00
Dave Protasowski 6484377731
update boilerplate date (#2134) 2021-05-28 13:21:29 -07:00
Markus Thömmes 4b2ae073fa
Replace deprecated github.com/markbates/inflect with github.com/gobuffalo/flect (#2014) 2021-02-08 05:12:26 -08:00
Dave Protasowski 75d66b5894
preserve the stable webhook logger names we had before (#1994)
* preserve the stable webhook logger names we had before

* pr feedback
2021-01-18 11:25:21 -08:00
Matt Moore f0ea5e6b9c
Use special error type to designate skips. (#1988)
This change introduces a new `controller.NewSkipKey` method to designate certain reconciliations as "skipped".

The primary motivation for this is to squelch useless logging on non-leader replicas, which currently report success with trivial latency.

I have plumbed this through existing reconcilers and the code-gen so most things downstream should get this for free.  In places where a key is observed, I do not mark the reconcile as skipped as the reconciler did some processing for which the awareness of side-effects and reported latency may be interesting.
2021-01-14 14:30:20 -08:00
Markus Thömmes 5f11dd0634
Add smart handling of selectors in webhooks (#1949)
* Add smart handling of selectors in webhooks

This is an alternative fix for #1590. Instead of arbitrarily adding a label from a different project to avoid the reconcilers racing, this adds "smart" handling of the selectors in that labels not inside the knative.dev domain are plainly ignored and our own selectors are added additively.

* Fix formatting

* Fix missing variable usage
2020-12-08 23:38:41 -08:00
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
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
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
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 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
Victor Agababov eb05e8dd5b
Various cleanups (#1446)
Thanks @markusthoemmes for the tool :)
2020-06-24 14:04:28 -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
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
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