Commit Graph

79 Commits

Author SHA1 Message Date
Dave Protasowski accfe36491
Satisfy linter (#3132)
* drop deprecated linter

* fix uint64=>int64 overflow

* fix unnecessary fmt.Sprintf

* ignore false positive fatcontext

* fix integer overflows

* update golangci-lint config - properly was moved

* fix formatting calls

* use new integer range syntax

* adjust nolint comments

* stop using deprecated k8s types
2025-01-10 15:06:18 +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
Dave Protasowski 2daa86aa8f
Electors can provide an initial set of buckets (#2473)
The controller package now promotes those buckets
prior to starting reconciliation and leader election

The unopposed elector now seeds the univeral bucket

This helps avoid races in unit tests were the univeral
bucket isn't promoted in time when reconciling an resource
2022-03-25 11:21:49 -07:00
Dave Protasowski 80c511aa34
Wait for reconciler/controllers to return prior to exiting the process (#2437) 2022-02-22 13:12:04 -08:00
Julian Friedman d569db39a8
Add context to reconcile error logs (#2281) 2021-09-09 03:21:58 -07:00
Matt Moore e957ee54fa
Drop several deprecated APIs. (#2228) 2021-08-30 13:25:54 -07:00
Matt Moore 6ef763ddee
Remove long deprecated NewImplWithStats (#2223) 2021-08-21 14:43:34 -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
Julian Friedman 50410e0b83
Use consistent case for "Deprecated" comments (#2216)
* Use consistent case for "Deprecated" comments

Not the most important thing ever, but the canonical string to use for
Deprecated warnings is case sensitive, and also it's nice to be
consistent.

* Add nolint comment
2021-08-17 09:15:16 -07:00
Matt Moore 3826bb2436
Add a new mechanism for requeuing a key. (#2201)
This is modelled after some of the semantics available in controller-runtime's `Result` type, which allows reconcilers to indicate a desire to reprocess a key either immediately or after a delay.

I worked around our lack of this when I reworked Tekton's timeout handling logic by exposing a "snooze" function to the Reconciler that wrapped `EnqueueAfter`, but this feels like a cleaner API for folks to use in general, and is consistent with our `NewPermanentError` and `NewSkipKey` functions in terms of influencing the queuing behaviors in our reconcilers via wrapped errors.

You can see some discussion of this here: https://knative.slack.com/archives/CA4DNJ9A4/p1627524921161100
2021-07-30 08:31:33 -07:00
zhaojizhuang 4cdacd0473
add concurrency for each controller (#2160) 2021-06-25 12:41:44 -07:00
Markus Thömmes 980a33719a
Fix revive related linting issues (#2131) 2021-05-26 01:10:28 -07:00
Markus Thömmes 04fdbd775b
Add WaitForCacheSyncQuick and use it in tests (#2045) 2021-03-05 07:07:20 -08:00
Victor Agababov 8fbab7ebb7
Redo the comment a bit further (#2042)
I think `thus` is quite wrong here (I commented on the pr), but
also took it a bit further.
2021-03-03 11:22:15 -08:00
Markus Thömmes 08fc6268bf
Fix comment for skipKeyError (#2041)
* Fix comment for skipKeyError

* Review
2021-03-03 03:19:15 -08:00
Matt Moore 8a9bf766d3
Add symmetric filter helped based on OwnerRefable. (#2032)
Most resources stamped out by knative controllers have OwnerReferences synthesized via `kmeta.NewOwnerRef`, which requires the parent resource to implement `kmeta.OwnerRefable` for accessing the `GroupVersionKind`.

However, where we setup informer watches on those same children resources we have essentially relied on direct synthesis of the `Group[Version]Kind` where we could instead provide an empty instance of the controller resource and leverage `GetGroupVersionKind` to provide the GVK used for filtration.

So where before folks would write:

```golang
FilterFunc: controller.FilterControllerGK(v1alpha1.WithKind("MyType"))
```

They may now write:

```golang
FilterFunc: controller.FilterController(&v1alpha1.MyType{})
```

The latter is preferable in part because it is more strongly typed, but also shorter.
2021-02-19 08:47:03 -08:00
Markus Thömmes a02dcff9ee
Bump a few assorted dependencies to their latest versions (#2013)
* Bump a few assorted dependencies to their latest versions

* Use new uuid helper

* Some more slight adjustments
2021-02-08 09:52:52 -08:00
Dave Protasowski 5bb97df49b
fix duration logging (#1992) 2021-01-15 12:20:20 -08:00
Dave Protasowski a74906c7fb
Use structured logging to augment our logger vs. naming (#1991)
* Use structured logging to augment our logger vs. naming

* remove unused line
2021-01-15 12:08: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 261c9b4624
Remove unnecessary intermediate loggers (#1969)
* Remove unnecessary intermediate loggers

* Make linter happy

* Collapse logging variable into if contexts
2020-12-16 08:27:58 -08:00
rusde 3154117dcf
Add tags to knative provided reconcile metrics (#1916)
* Add  tags to knative provided reconcile metrics

* Remove resource tag to reduce metric cardinality

* Removing unknown tags

* Update controller/testing/fake_stats_reporter.go

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

Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-11-24 12:42:35 -08:00
Markus Thömmes 565516e224
Add errorlint and fix all existing issues (#1855) 2020-10-29 01:14:35 -07:00
Markus Thömmes 385c8b9c0e
Fix nolint warnings and adhere to best practices (#1823) 2020-10-20 09:33:59 -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
Markus Thömmes 5fbbde31b3
Align linters with serving (enables stylecheck and asciicheck) (#1738) 2020-09-23 07:37:40 -07:00
Victor Agababov d5c09d2aef
Optimize and clean the controller code (#1639)
- fix outdated comments
- reorder the code to reduce the  number of defer calls
- various other nits
"
2020-08-21 22:20:46 -07:00
Matt Moore 3ac62a93ca
Fix the logkey.Key tagging in Enqueue. (#1627)
Debugging https://github.com/knative-sandbox/net-contour/issues/214 I noticed the logging was showing up as:

```
"knative.dev/key":{"knative.dev/key":"serving-tests/service-create-and-update-teaoccuu"}
```
2020-08-16 11:49:06 -07:00
Victor Agababov 0ecf6f86c1
Fix the debug->debugf (#1609)
this is a shame cube situation
2020-08-11 14:58:05 -07:00
Victor Agababov 62f2560aa7
Also log the key we're enqueueing when printing debug info (#1594) 2020-08-06 16:07:28 -07:00
Jon Donovan 7be5c0a87b
Allow creating controller with custom RateLimiter. (#1546)
* Allow creating controller with custom RateLimiter.

Which was possible before via field modification.
Not switching to a builder pattern mostly for speed of resolution.
Happy to consider alternatives.

* Add tests for new functionality.

Specifically, these test that the Wait() function is notified about
the item, and that the RateLimiter is passed through to the queue.

* Add Options. Gophers love Options.

* Even moar controller GenericOptions.

* Attempt to appease lint, don't create struct for typecheck.

* GenericOptions -> ControllerOptions

* Public struct fields.
2020-08-03 14:31:28 -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
Lance Liu e863db0344
Remove key in tags to reduce metrics count (#1494)
* Remove key in tags to reduce metrics count
Issue: https://github.com/knative/serving/issues/8609

Signed-off-by: Lance Liu <xuliuxl@cn.ibm.com>

* remove tag key for OpenCensus

Signed-off-by: Lance Liu <xuliuxl@cn.ibm.com>
2020-07-15 01:29:32 -07:00
Matt Moore 7df8fc5d77
Implement the first wave of per-reconciler leaderelection. (#1301)
* Implement the first wave of per-reconciler leaderelection.

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

* Feedback from vagababov

* Feedback from yanweiguo

* Drop IsLeaderFor from the LeaderAware interface.

* Moar vagababov nits

* dprotaso feedback

* Add issue comment, error return

* Incorporate dprotaso test feedback
2020-06-18 19:07:25 -07:00
Antoine Cotten 82fe339a5e
Implement Unwrap() and Is() for permanentErrors (#1363)
* Implement Unwrap() for permanentErrors

* Implement Is() for permanentErrors
2020-06-02 13:27:18 -07:00
Victor Agababov 66f1d63f10
Fix logging around pkg (#1310)
- use more performant functions (mostly remove formatters were possible)
- move zap.Error() to the call site, rather than creating a new sugared logger with a key attached (not cheap)
- fix *w usages where the key was not provided.
2020-05-07 15:00:45 -07:00
Markus Thömmes 0e0f650dfa
Fix deprecation comment. (#1279) 2020-05-04 00:13:43 -07:00
Markus Thömmes 47137cdc30
Explicitly name controller filters. (#1257)
* Explicitly name controller filters.

Everytime I read the generic "Filter" or "FilterGroupVersionKind" my brain needs to do an extra roundtrip to realize that this actually filters on the **controller** having that GVK/GK. This adds new functions that explictly state that to avoid that roundtrip.

Old functions are just deprecated so this can be rolled out without a downstream break.

* Rename after review.
2020-04-29 10:18:42 -07:00
Matt Moore 7b6e21a57a
Change StartAll to take context. (#1247)
* Change StartAll to take context.

This has bugged me since we started using `ctx`, which containers a `stopCh` of sorts as `Done()`.  This is somewhat for consistency, but by using `ctx` explicitly we enable ourselves to take advantage of more contextual information.

I did a quick scan of call sites and the good news is that the `sharedmain` change should be the place through which the vast majority of calls occur, however, the one outlier here is the KPA which calls this manually.  I will stage a PR to manually import pkg into serving to fix this once this lands.

* Add a Run shim for back-compat
2020-04-25 16:21:49 -07:00
Ville Aikas 4e57475bc8
add EnqueueNamespaceOf (#1217)
* add EnqueueNamespaceOf

* correct log error msg
2020-04-10 18:11:07 -07:00
Dave Protasowski e3d924ba00
allow filtering on schema.GroupKind (#1080)
* allow filtering on schema.GroupKind

In addition deprecated usage of Filter with the introduction of
FilterGroupVersionKind

* reduce nesting & simplify boolean logic
2020-02-12 12:12:18 -08:00
Maisem Ali 64ed9fcf84 add EnqueueSentinel to pkg/controller (#841)
* add EnqueueSentinel to pkg/controller

* address comments
2019-11-04 16:22:20 -08:00
Matt Moore 809ce573e4 Add FilterByName for cluster-scoped resources. (#816)
This is a precursor to reconciling named webhook configurations, and largely a copy of `FilterByNameAndNamespace`.
2019-10-28 10:41:42 -07:00
Slavomir Kaslev 29642b017b Add RunInformers function (#758)
Add RunInfomers which is similar to the StartInformers function but allows for
users to for informers to finish running.

This function will be mainly used in tests to fix the race described in
knative/serving#5351
2019-10-14 10:02:32 -07:00
Markus Thömmes de32ec136d Fix a subtle bug with cluster scoped entities. (#708) 2019-09-20 12:26:07 -07:00
Markus Thömmes 4a790dd36c Plumb through a structured key, keep current behavior. (#703)
* Plumb through a structured key, keep current behavior.

* Rename variable.
2019-09-20 06:52:05 -07:00
Victor Agababov 7db4b798fb Do not enqueue items when the queue is shut down (#652)
* Do not enqueu (and log) if we're shutting down

* Wait for queue to empty before terminate and other restrictions

We need to stop enqueueing stuff when queue is shuitting down since this causes panics in our tests.
So

1. wait for queue to empty before shutting down
2. do not enqueue stuff for global reconciliation if the queue is shutting down (this exhibits races in global resync tests)
3. do not enqueue on error, since while the erroneous object was being processed the queue might have terminated

/assign mattmoor
2019-09-09 18:07:11 -07:00