Commit Graph

71 Commits

Author SHA1 Message Date
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
zhouhaibing089 03bf3de6e2
webhook: add options to disable resource_namespace tag in metrics (#2931)
* webhook: add options to disable resource_namespace tag in metrics

To add some context, historically, `resource_name` was removed from this
tag list due to its high potential of causing high metrics cardinality.
See [knative/pkg#1464][1] for more information.

While that's great, but it might not be sufficient for large scale use
cases where namespaces can be super dynamic (with generateName, too) or
grows fase enough. There is an issue report from
[tektoncd/pipeline#3171][2] which talks about this.

This proposal makes it possible to disable `resource_namespace` tag via
an option function. The default behavior is not changed, so no user
impact if any of existing users rely on this tag. There is no API
contract change either due to the beauty of variadic functions.

Now downstream projects can consume this by override `StatsReporter` in
webhook context options with their own preference. As a caveat here, if
downstream project does choose to override `StatsReporter`, the default
`ReportMetrics` function shouldn't be called by default as they may now
have a different set of tag keys to report. As such, this function is
only called if the default `StatsReporter` is used.

[1]: https://github.com/knative/pkg/pull/1464
[2]: https://github.com/tektoncd/pipeline/issues/3171

* webhook: add StatsReporterOptions in webhook.Options

There are two ways to customize StatsReporter:

1. Use a whole new StatsReporter implementation.
1. Or pass Option funcs to customize the default StatsReporter.

Option 1 is less practical at this time due to the metrics registration
conflict. `webhook.RegisterMetrics()` is called regardless which
StatsReporter implementation is used (which is a problem by itself). The
second option is more practical since it works well without dealing with
metrics conflicts.

The `webhook.Option` in particular allows people to discard certain
metrics tags.
2024-04-01 19:02:21 +00:00
Stavros Kontopoulos 4a80605786
Add health checks (#2671)
* add health checks

* updates

* make probes more flexible

* simplify

* minor

* internal only

* fixes
2023-02-15 23:38:50 +00:00
Kenny Leung b812affa38
Support fetching observability from ctx. (#2610)
* add option to load observability config from ctx

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* comments and tests

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* undo

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* move observability setup logic into function to match logger

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* fix arg

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

Signed-off-by: Kenny Leung <kleung@chainguard.dev>
2022-10-14 16:45:53 +00:00
Sascha Schwarze 5f66ecf267
Allow configuration of threads-per-controller (#2567) 2022-09-14 15:47:04 +00:00
Matt Moore af54d7330b
Support fetching configs from `ctx`. (#2505)
* Support fetching configs from `ctx`.

This enables callers of `sharedmain` to infuse `ctx` with a `logging.Config` or `leaderelection.Config` instead of relying on the API server for it.

* Move context methods into appropriate packages, drop stutter
2022-05-03 15:25:57 +00:00
Dave Protasowski 80c511aa34
Wait for reconciler/controllers to return prior to exiting the process (#2437) 2022-02-22 13:12:04 -08:00
Matthias Wessendorf 671e46d0cc
💫 we must use `flags` instead of `pflags`, since this is not working. It seems like pflag.* adds the var to its own flag set, not the one package flag uses, and it doesn't expose the internal flag.Var externally - hence this fix. (#2414)
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
2022-02-01 08:28:38 -08:00
Pierangelo Di Pilato d82be484e4
Disable controllers using a command-line flag (#2339)
* Disable controllers using a flag

This patch allows disabling controllers when using a new `Main` function
called `MainNamed` which takes a list of `NamedControllerConstructor`.

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

* Apply reviews

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

* Add comments, split filter and conversion

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

* Allocate len(ctors)

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

* to disable -> disabling

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>
2021-11-16 13:30:53 -08:00
Markus Thömmes a1bc850346
Print proper warning logs from API warnings (#2168) 2021-06-24 05:13:45 -07:00
Dave Protasowski 47dfdcfaed
consolidate k8s flags to an environment package (#2133)
* consolidate k8s flags to an environment package

* add copyright

* fix comment style

* use go1.16 in workflows so downstream tests work

* Deprecate GetRESTConfig and do not remove

* update copyright date
2021-05-28 13:30:30 -07:00
Matt Moore e2d6b4f845
Try splitting configmap package (#1851) 2020-12-22 13:58:04 -08:00
Gallardot 6d905b3f84
expose loggingconfig last error (#1373) 2020-10-29 05:22:34 -07:00
Markus Thömmes 565516e224
Add errorlint and fix all existing issues (#1855) 2020-10-29 01:14:35 -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
Scott Nichols 5a5f68637e
use k8s.interface (#1808)
* use k8s.interface

* start to remove test client

* don't use test/KubeClient
2020-10-14 09:51:31 -07:00
Julian Friedman bcdd7509c0
Use default no-op logger for maxprocs (#1801)
Set uses a no-op logger by default, so no need to explicitly pass one.
2020-10-13 01:39:30 -07:00
Victor Agababov a04d64c180
Shush autogomaxproc. (#1800)
* Shush autogomaxproc.

I am not as sure about this change, but those logs are not following the standard formt
and given we need to inject the logger in init() makes this next to impossible.

Corollary, is that we set cpu limits on all our binaries, except QP, so it only mattered there
since otherwise the package logs nothing.

* m
2020-10-12 19:13:30 -07:00
Victor Agababov e3b4e9c229
Step I: move memstats to metrics (#1799)
step II: update deps (serving and eventing)
step: III: remove from shared main

For https://github.com/knative/serving/issues/9787
2020-10-12 15:14:17 -07:00
Scott Nichols 46761ba7c3
Put EnableInjectionOrDie back on the main path (#1772)
* put EnableInjectionOrDie back on the main path

* nil check pointer type

* move enable injeciton out of sharedmain

* lint

* nit picking fmt....

* add documentation

* feedback cleanup

* injection.GetRESTConfig

* redirect code that moved:
2020-10-06 16: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
Zhongduo Lin (Jimmy) ea7374e811
Delay start of informers in sharedmain (#1767)
The EnableInjectionOrDie starts informers immedidately in a go
routine, which changes the order of informer start and controller
setup. As a result setting resync period to informer handler will
be ignored as the informer is already started. Though this will
likely affect more components, changing the EnableInjectionOrDie
function will break the API, so this is a temporary solution to
fix all the controllers depending on sharedmain.
2020-10-03 10:57:33 -07:00
Victor Agababov 1e373a9e5d
take 2 (#1755) 2020-09-29 14:10:29 -07:00
Victor Agababov ec3e2dd4bd
Inject the pod name into logger when provided in the envvars (#1714)
Deployments that are H(P)A need to provide the pod name envvar via downward api.
Activator and QP are already doing this.
2020-09-17 14:47: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 d21012af55
Deprecate --master flag in favor of --server. (#1693)
* Deprecate --master flag in favor of --server.

* Actually just drop the flag altogether.
2020-09-09 09:57:50 -07:00
chen zhengwei 2fee224e95
Fix some comments in main.go (#1685) 2020-09-03 20:57:31 -07:00
Scott Nichols 2335e4d84a
Adding an easy entry method next to sharedmain to allow for utilities to leverage injection without being a controller. (#1658) 2020-08-28 13:08:07 -07:00
Adam Harwayne 530eac8757
Inject the config into the context. (#1610) 2020-08-11 16:18:05 -07:00
Julian Friedman 095ff27da6
Automatically set GOMAXPROCS using automaxprocs library (#1585) 2020-08-10 02:00:30 -07:00
Ville Aikas 1127f59d7b
kube already gives us this, do not double log http (#1542) 2020-07-22 10:13:57 -07:00
Victor Agababov acd3f31714
nits (#1529) 2020-07-20 18:44:35 -07:00
Matt Moore 931d1210f1
Enable components to get debug logging from our rest transports. (#1515) 2020-07-17 13:54:33 -07:00
Matt Moore a9ea699c70
Make MainWithConfig respect user-provided overrides. (#1513) 2020-07-17 10:09:34 -07:00
Matt Moore a81727701f
Enable leader election by default. (#1476)
* Enable HA by default.

This consolidates the core of sharedmain around the new leaderelection logic, which will now be **enabled by default**.

This can now be disabled with `--disable-ha` or by passing `sharedmain.WithHADisabled(ctx)` to `sharedmain.MainWithConfig`.

* vagababov comments, build failure

* Open an issue for enabledComponents removal.

* Move the configmap watcher startup.

This race was uncovered by the chaos duck on knative/serving!  When we have enabled a feature flag, e.g. multi-container, and the webhook pods are restarted, there is a brief window where the webhook is up and healthy before the configmaps have synchronized and the new webhook pod realizes the feature is enabled.

* Drop the import alias
2020-07-13 12:43:18 -07:00
Matt Moore 27389b2fa0
Enable use of StatefulSet in sharedmain. (#1451)
This change allows for (just webhook for now) controllers going through sharedmain to opt into Yanwei's logic by setting several environment variables.

I was able to pull this change in downstream and change the webhook to use a StatefulSet with the following environment:
```
+        # These settings are used for statefulset-based
+        # leader selection.
+        - name: CONTROLLER_ORDINAL
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.name
+        - name: STATEFUL_SERVICE_NAME
+          value: "webhook"
```

Running the above with 10 replicas and 10 buckets worked as intended (keys were evenly distributed across the replicas).
2020-06-27 09:29:28 -07:00
Matt Moore b6a13e2894
Implement the third wave of per-reconciler leaderelection. (#1303)
This lets downstream components enable leaderelection on `WebhookMain*`-based components.

Detailed design: https://docs.google.com/document/d/1i_QHjQO2T3SNv49xjZLWlivcc0UvZN1Tbw2NKxThkyM/edit#
Issue: https://github.com/knative/pkg/issues/1181
2020-06-19 11:26:25 -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
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 22b9613719
Inject config into controller context. (#1253)
This makes the config used to start all the clients available on the context starting the controllers. That enables us to use that config to create secondary clients in the controllers with the same config.
2020-04-28 06:35:51 -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
Matt Moore 3b7a675e73
Revert "Use loggers when emitting count messages (#1239)" (#1248)
This reverts commit c13917eb25.
2020-04-25 15:48:50 -07:00
Matt Moore 2d0c254ac6
Incorporate component name into ComponentConfig. (#1246) 2020-04-25 10:15:49 -07:00
Matthew Broomfield c13917eb25
Use loggers when emitting count messages (#1239)
Fixes #1225
2020-04-24 10:55:50 -07:00
Markus Thömmes 8aa4090a02
Release leader election lock as soon as we exit. (#1229) 2020-04-21 13:44:35 -07:00
Kenjiro Nakayama 08b31df9e6
Retry to get logging configmap when failed (#1189)
* Retry to get logging configmap when failed

When deploying pods with Istio sidecar, it takes a few seconds until
network is configured. In fact, Serving's system pods always fail when
Istio sidecar is enbled.

To fix it, this patch changes to retry to get logging configmap for 5
seconds.

* Add IsNotFound error check

* Remove if error condition
2020-04-04 11:17:18 -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
Knative Prow Robot acb0b0386b
Fix crash looping when leader election config doesn't exist (#1142) 2020-03-05 12:50:25 -08:00
Paul Morie ca35cb8791
add leader election support to sharedmain (#1019)
* Add leader election config and to sharedmain

* Add new dependencies

* Extract method for RunLeaderElected

* Make leader election config constructor validate

* Rename leader election files

* Always start profiling server whether component has LE lock or not

* Fix entering unreachable section when leader election is disabled

* Address PR feedback
2020-02-26 14:40:50 -08:00
Evan Anderson 7af3fab62c
Roll forward #1045 (#1109)
* Revert "Add support for client TLS to pkg/metrics (#1045)"

This reverts commit 945b556708.

* Roll forward "Add support for client TLS to pkg/metrics (#1045)"

Adds support for client TLS certs for opencensus export

* Switch sharedmain to only pass a getter rather than an all-namespace lister.

* Add a TODO about using a cached copy if this generates undue load

* Update deps per build failure.

* Refactor per @anniefu suggestion
2020-02-25 11:42:51 -08:00