Commit Graph

123 Commits

Author SHA1 Message Date
Matt Moore 6f19c52bf1
[master] Format markdown (#1547)
Produced via:
  `prettier --write --prose-wrap=always $(find -name '*.md' | grep -v vendor | grep -v .github | grep -v docs/cmd/)`
/assign n3wscott vagababov
/cc n3wscott vagababov
2020-07-23 08:00:57 -07:00
Scott Nichols ae9c3f7fa8
Refactor the genreconciler code to pull state out (#1544)
* Refactor the genreconciler code to pull state out

* don't generate the stubs

* fix indent
2020-07-22 23:02:57 -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
Weston Haught bce16cf786
remove krshapedlogic tag, this is default now (#1442) 2020-06-26 11:28: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
Weston Haught d5043a4332
Groom conditions LastTransitionTime in postprocess (#1403)
* Groom conditions time

* unit test

* unit test fix

* make readme accurate
2020-06-18 11:46:25 -07:00
Weston Haught b559da3646
Generate common logic for krshaped resources (#1311)
* generate krshaped logic

* add logic to the tag

* Update injection/README.md

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

* move var to reconciler

Co-authored-by: Matt Moore <mattmoor@vmware.com>
2020-05-08 10:00:45 -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
Matt Moore 1893541a0f
Scope the webhook secret informers to the system namespace. (#1158) 2020-03-12 18:29:29 -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
Knative Prow Robot 312b1be35c
Format markdown (#1139)
Produced via:
  `prettier --write --prose-wrap=always $(find -name '*.md' | grep -v vendor | grep -v .github)`
/assign n3wscott vagababov
/cc n3wscott vagababov
2020-03-04 10:55:54 -08:00
Andrew Su 340837e654
Fix typos (#1138)
- implementor -> implementer
- implemnted -> implemented
- "Codify" the kind tag.
2020-03-03 09:59:53 -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
Paul Morie 1d60dd6107
Introduce sharedmain.WebhookMain* (#1084) 2020-02-21 07:25:07 -08:00
Scott Nichols 5d8a01d12c
Implement strongly typed class reconcilers (#1103)
* Implement strongly typed class reconcilers

* document class filters.

* matt is always right
2020-02-19 08:38:06 -08:00
Evan Anderson 1ad2b11321
Revert "Add support for client TLS to pkg/metrics (#1045)" (#1106)
This reverts commit 945b556708.
2020-02-19 08:20:06 -08:00
Scott Nichols 72f3cd2bbc
[Genreconciler] Fix group names when client groups differ than their directory name. (#1097)
* looking at annotations for group overrides.

* checkpoint.

* checkpoint

* I think it is correct.

* ok

* trim down the files.

* simulate tekton

* working test out of checkin

* remove test client

* update docs

* and test.

* lint

* it ok

* update codegen
2020-02-18 17:14:59 -08:00
Evan Anderson 945b556708
Add support for client TLS to pkg/metrics (#1045)
* Document the plan for metrics

* Update with issue links

* Update with other @mattmoor comments.

* Address feedback from @anniefu

* Update export address since `localhost` won't work for a DaemonSet.

* Add an explicit action item to migrate Prometheus

* Fix possible (ambiguous) link vs checkbox.

* Fix typo in metrics/README.md

* Add support for client TLS to pkg/metrics

* Address comments from @vagababov and @anniefu

* Finish removing Resource code

* Update name to be shorter and not require a double migration.

* Add tests for opencensus exporting with TLS
2020-02-18 11:04:58 -08:00
Matthias Wessendorf c9cd4f2956
Updating README for genreconciler (#1100) 2020-02-17 08:35:10 -08:00
Scott Nichols d93ce78496
[Reconciler Generators] Adding support for configStore.ToContext (#1085)
* Support optional config maps.

* document configmap stores

* whitespace.

* optionsFns

* review

* check for nil.

* zero trust imports.
2020-02-12 16:10:35 -08:00
Scott Nichols a447f39709
Document genreconciler. (#1066)
* document genreconcilerwow

* adding docs around how to use the generator and the stubs

* add finalizer details

* googlebot sucks.
2020-02-11 12:42:21 -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
Antoine Cotten 5e3431e561 Filter tracked sharedmain ConfigMaps based on optional label selector (#973)
* tests: Rename 'cm' vars to 'cmw' for consistency

* Filter tracked sharedmain ConfigMaps based on label selector

The ConfigMap watcher only tracks the ConfigMaps which contain the label
defined by the optional SYSTEM_RESOURCE_LABEL env var if the latter
exists.
2020-01-13 06:53:04 -08:00
Antoine Cotten ce9dfe90d1 Fix sharedmain log messages format (#974) 2020-01-06 07:53:49 -08:00
Matt Moore 43ca049cdb Reduce the boilerplate for setting up duck.InformerFactory's. (#896)
This augments the injection codegen with the capability to produce a duck.InformerFactory
attached to context for each type that we process.

Now a `duck.InformerFactory` for "Addressable" can be produced by "Get"ing it from the context.

This is triggered by placing `// +genduck` on the type that implements `duck.Implementable`.
2019-11-25 09:57:10 -08:00
Matt Moore 80da64a31c golang format tools (#879)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign n3wscott
2019-11-14 11:06:31 -08:00
Vincent 94911510c3 Skip watching the ConfigMaps if they are missing (#872)
* Skip watching the ConfigMaps if they are missing

* Log the error message
2019-11-13 15:17:29 -08:00
Markus Thömmes 56c2594e4f Assorted linting fixes. (#840)
* Remove unused code.

* Remove unneeded loops.

* Remove unneeded Printf calls.

* Use time.Since instead of time.Now().Sub.

* Remove unused values.

* Rename error variable according to conventions.

* Return error last.

* Simplify array allocations.

* Remove leaky ticker.

* Remove Yoda conditions.

* Remove deprecated function to talk to GKE.

* Remove dot import.

* Remove empty critical section and replace with a channel operation.

* Add linter directives to explicitly state wanted weirdness.

* Update deps.

* Fix broken line.
2019-11-01 12:49:12 -07:00
Matt Moore cc1ba8e560 Expand sharedmain to support launching our webhook. (#828)
With the simplified `webhook.New` signature, this supports detecting when one or more of the controllers we have launched has a `Reconciler` that implements `webhook.AdmissionController` and launching the webhook with this admission controllers registered.

There is still work that needs to be done to refactor the webhooks to follow this shape, but this hopefully starts to paint the picture of where things are headed.
2019-10-29 13:29:11 -07:00
Antoine Cotten 839f05b988 Update outdated package paths in injection usage doc (#803) 2019-10-26 09:06:35 -07:00
Antoine Cotten 87d4fd2e4f Log type instead of <nil> in injection panic message (#806) 2019-10-26 09:04:35 -07:00
Matt Moore 2e019c8a87 Expose Go memstats as metrics. (#711)
This exposes metrics for the properties available through [here](https://godoc.org/runtime#MemStats) so that we can get some better visibility into things like GC pressure.
2019-09-21 00:07:08 -07:00
Markus Thömmes 7b725e1ae6 Use a nil map instead of an empty map for the same effect. (#695) 2019-09-19 13:00:00 -07:00
Vincent 24f524cb25 Add the creation of default LoggingConfig, if config-logging is missing (#663)
* Add the creation of default LoggingConfig, if config-logging is missing

* Create empty map for the func NewConfigFromMap
2019-09-17 09:30:47 -07:00
Dave Protasowski 528ad1c1dd Generate K8s Injection Code (#640)
* update codegen so the fatal error messages are more informative

String representation of an untyped nil is 'nil' so the Fatal messages weren't useful

* generate k8s injection code

* generate apiextensions injection code

* use Fatal & move output paths

* switch from Fatal to Panic

* injection creates a single factory
2019-09-09 12:52:11 -07:00
Matt Moore 524f6c5bb2 Add the ability to scope informers to a namespace with injection. (#626) 2019-09-03 07:17:00 -07:00
Spencer Peterson 8cae700d29 Add CronJob informer (#623)
* add cronjob informer

* update deps
2019-08-31 12:19:55 -07:00
Martin Gencur 366ab85660 Profiling support (#562)
* Profiling support

* Move ProfilingPort to profiling package

* Fix golint errors

* Refactor watcher to accept variable length observers

* Cleaner happy path

* Remove profiling handlers argument

* use :8008 string as const

* Make the profiling port package private

* Make UpdateFromConfigMap member of profiling handler

* use mutex when accessing the enabled flag
* test the server as well

* Fixes

* Initialize profiling from configMap at startup

* Use httptest.ResponseRecorder to make the test more lightweight

* Fixes

* Do not initialize from configmap at startup
2019-08-22 08:17:33 -07:00
Markus Thömmes 717a85540f Read the logging configmap via API, not from the file system. (#553)
* Read the logging configmap via API, not from the file system.

This makes it possible to run our controllers locally which can be super handy for quick development cycles.

* Use NewConfigFromConfigMap to avoid conversion.

* Implement a fallback mechanism and create a public helper.

* Remove some duplication.

* Rolling back some of the changes.
2019-08-01 10:06:44 -07:00
Markus Thömmes e8df94bc5a Derive the config for our controller setup like kubectl etc. (#554)
Our config loading currently only tries the given flags or in-cluster config. This also adds the KUBECONFIG env variable and the user's home directoy as fallback solutions to find a valid configuration.

That helps running our controllers locally with minimal effort.
2019-07-31 14:26:43 -07:00
Jean-Rémy Bancel b583d04e47 Remove '-' from suggested component name. (#525) 2019-07-12 12:41:44 -07:00
Joseph Lewis III db77877519 added limitrange and resourcequota informers (#501) 2019-07-02 22:44:32 -07:00
mattmoor-sockpuppet 1864f499dc golang format tools (#497)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
/assign @mattmoor
2019-06-27 07:37:08 -07:00
chaodaiG 1104d6c755 update readme with knative.dev/pkg (#495) 2019-06-26 14:56:08 -07:00
Matt Moore 222dd25986 Migrate pkg to use the knative.dev/pkg import path (#489)
* Manual changes.

* scripted changes.
2019-06-26 13:02:06 -07:00
Joseph Lewis III 9c5d970cbc Add injection for rbacv1.role (#479) 2019-06-21 13:09:21 -07:00
Scott Nichols 68737b1b4e Adding Batch v1 Job to injection client. (#459)
* adding Batch v1 Job to injection client.

* damn lock file.
2019-06-12 14:55:43 -07:00
Scott Nichols 28f181241c Remove GCP default auth. (#455)
* Remove default remote gcp auth from pkg.

* update deps.
2019-06-10 08:39:41 -07:00
Scott Nichols f48815f454 Add injection for ServiceAccount and RoleBinding (#453)
* Adding ServiceAccount.

* Adding RoleBinding.

* update gen.
2019-06-10 07:34:41 -07:00
mattmoor-sockpuppet d01d3b0112 golang format tools (#454)
Produced via:
  `gofmt -s -w $(find -path './vendor' -prune -o -type f -name '*.go' -print))`
  `goimports -w $(find -name '*.go' | grep -v vendor)`
2019-06-10 07:17:42 -07:00
Scott Nichols 4dec36bd68 Adding namespaces to injeciton, eventing uses this. (#452) 2019-06-08 14:12:41 -07:00
Matt Moore 2353d3bfc0 Add a pod informer and fakes. (#451) 2019-06-08 07:49:41 -07:00
Scott Nichols afdedebb9e Adding Api Extensions to client injection in pkg. (#449)
* Adding Api Extensions to client injection in pkg.

* Moving to logger.panicf when the thing you ask for is not in the context.
2019-06-07 18:54:40 -07:00
mattmoor-sockpuppet 463df98531 Format markdown (#448)
Produced via: `prettier --write --prose-wrap=always $(find -name '*.md' | grep -v vendor | grep -v .github)`
2019-06-07 09:39:41 -07:00
Matt Moore d8a2a739d6 Eliminate controller registration in favor of passing a list to the shared main. (#447) 2019-06-06 18:17:41 -07:00
mattmoor-sockpuppet 586a88ecb8 Format markdown (#445)
Produced via: `prettier --write --prose-wrap=always $(find -name '*.md' | grep -v vendor | grep -v .github)`
2019-06-06 09:16:40 -07:00
Matt Moore 35bb0fc83b Add code-generation for the various injection stubs. (#438)
This is largely based on work by @n3wscott
2019-06-05 08:50:38 -07:00
Matt Moore 4c630bb1bb Create a library for Reconciler dependency injection. (#423)
This creates a base library that enables us to leverage the dependency
graph to convey injection dependencies.  Our controllers will start
to get their informers off of a `context.Context` via `fooinformers.Get(ctx)`.

By simply linking `fooinformers` to access the informer in this way, we trigger
a cascade of `init`-time registrations for the informer, and its transitive
dependencies (e.g. shared informer factory, client).

The `ctx` is infused with these informers in `package main` by linking the
appropriate reconcilers (transitively registering everything) and then calling
`sharedmain.Main()` (from `github.com/knative/pkg/injection/sharedmain`).
2019-06-05 07:37:38 -07:00