Commit Graph

56 Commits

Author SHA1 Message Date
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
navin de3e9cc204
Fixing all deprecated use of sets.String (#2915)
* Fixing all deprecated use of sets.String

* review comments

* Fixing deprecated use of sets.String
2024-01-08 15:21:18 +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
Nghia Tran 29f716f18b
Fix `InitialBuckets()` for statefulSetBuilder's electors (#2483)
* Not all unoppossedElector has universal bucket

Some are for StatefulSet and only owns their own

* Avoid comparing pointers which may be flaky

* Address PR feedback
2022-04-07 16:45:44 +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
Pierangelo Di Pilato 3c4dec9b9f
Take pointer to map in AsOptionalMap for consistency (#2460)
* Take pointer to map in AsOptionalMap for consistency

- Other `As*` functions take pointers.
- It avoids having to initialize the map passed to the function

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

* Remove double pointer

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

* AsOptionalMap -> CollectMapEntriesWithPrefix

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-03-14 09:45:18 -07:00
Pierangelo Di Pilato ce6f2877ce
Initialize prefix remapping map to avoid panic (#2453)
A `nil` `target` passed to `AsOptionalMap` causes a panic.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-03-10 10:24:48 -08:00
Pierangelo Di Pilato a850b9e047
Use t.Setenv instead of os.Setenv in tests (#2454)
Go 1.17 introduced a new handy API for setting env vars scoped for
a single test so we can avoid the hard to read set and reset env
loops.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-03-10 10:00:48 -08:00
Pierangelo Di Pilato fe26417344
Allow overriding lease name for a reconciler (#2435)
Add a `map-lease-prefix` prefix for config keys for
`config-leader-election` that is a map from a generated lease prefix
to a new prefix:

```yaml
map-lease-prefix.<component>.<package>.<reconciler_type_name>: <new_prefix>
map-lease-prefix.<component-x>.<package-x>.<reconciler_type_name-x>: <new_prefix>
```

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-02-28 11:55:09 -08:00
Evan Anderson 1db74d0a18
Adjust leaderelection defaults, add documentation. (#2391) 2022-01-12 20:43:12 -08:00
Dave Protasowski a99300deff
kmap (#2354)
* move some functional map operations to it's own package

* include a new accessor helper for migrating key names

* use kmap methods

* add deprecation notices

* fix boilerplate

* Rename Accessor to OrderedLookup
2021-11-19 09:07:23 -08:00
Dave Protasowski 9179f78dcf
introduce new case convention for leader election config map (#2302)
Part of https://github.com/knative/serving/issues/7300

Majority of serving uses lowercase-hyphens - ie. some-property over
someProperty

This changes the leader election config map parsing to support formats
and to prioritize the lowercase-hyphen case
2021-10-06 14:37:26 -07:00
Matt Moore d60f1a4998
Avoid double-resyncs without leader election. (#2252)
* Avoid double-resyncs without leader election.

tl;dr Without leader election enabled, we've been suffering from double resyncs, this fixes that.

Essentially when the informers are started, prior to starting the controllers, they fill the controller's workqueue with ~the world.  Once we start the controllers, the leader election code calls `Promote` on a `Bucket` so that it starts processing them as their leader, and then is requeues every key that falls into that `Bucket`.

When leader election is disabled, we use the `UniversalBucket`, which always owns everything.  This means that the first pass through the workqueue was already hitting every key, so re-enqueuing every key results in superfluous processing of those keys.

This change makes the `LeaderAwareFuncs` elide the call to `PromoteFunc` when the `enq` function passed is `nil`, and makes the `unopposedElector` have a `nil` `enq` field when we explicitly pass it the `UniversalBucket` because leader election is disabled.

* Add more unit test coverage
2021-09-02 09:46:06 -07:00
Dave Protasowski 7521c9239e
drop deprecated enabledComponents field (#2162) 2021-06-22 07:32:27 -07:00
Markus Thömmes 67897f4ec2
Replace golint with revive (#2126) 2021-05-18 06:10:15 -07:00
Markus Thömmes 620e8d257e
Allow disable via regex in chaosduck (#2117) 2021-05-11 08:22:47 -07:00
Markus Thömmes 71e938e5aa
Fix int conversion in statefulset ordinals (#2074) 2021-03-30 09:09:21 -07:00
Matt Moore 9b9407a76d
Expose the statefulset constructor (#1953) 2020-12-09 09:29:41 -08:00
Dave Protasowski c2474c2aa6
race was fixed in k8s 1.18 (#1864) 2020-10-27 22:05:34 -07:00
Dave Protasowski 8e524a49ba
Eventing no longer needs this constant (#1846)
Revert "Make knativeResourceLock exported (#1656)"

This reverts commit a79802cd78.
2020-10-26 10:53:42 -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
Yanwei Guo 3c4df8c272
clean up (#1790) 2020-10-09 10:51:21 -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
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
Markus Thömmes b4fa6c275e
Add linting config and fix issues. (#1691)
* Add linting config and fix issues.

* Inline unused test helper.
2020-09-09 08:35:50 -07:00
Yanwei Guo 71e8510e93
ingore filed for marshal (#1662) 2020-08-28 14:46:07 -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
Yanwei Guo a79802cd78
Make knativeResourceLock exported (#1656)
* export

* export
2020-08-27 14:15:06 -07:00
Yanwei Guo 21dcafbfa7
Support customizing lease name and identity (#1602)
* add fields

* address comment

* use lease lock

* remove func

* add comment
2020-08-26 19:09:06 -07:00
Victor Agababov 6940870178
Fix the test for go 1.15 (#1574)
The duration parsing errors are now quoted, so check for prefix
2020-07-30 17:51:01 -07:00
Victor Agababov afdc8bb9f4
Fix the race in the test (#1545)
The test was inherently racy and I saw it flake more than once (e.g. https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative_pkg/1526/pull-knative-pkg-unit-tests/1286086935722332160)
So this fixes it.
Also other minor nits around the test to make it more readable.
2020-07-22 18:14:57 -07:00
Yanwei Guo 0166004ef1
Another try to use hash.BucketSet for standard leader election mode (#1530)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* redo

* use local

* typo

* Update leaderelection/context.go

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

* merge another pr

* update dep

* Update hash/bucketer_test.go

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

* Update hash/bucketer_test.go

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

* output diff

* output diff

Co-authored-by: Matt Moore <mattmoor@vmware.com>
Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-07-21 14:02:54 -07:00
Matt Moore c0a9ec7f11
Make the chaosduck jitter (#1527) 2020-07-21 08:53:36 -07:00
Victor Agababov 6cd456823f
Revert "Use hash.BucketSet for standard leader election mode (#1490)" (#1518)
This reverts commit 8d80e63709.
2020-07-17 20:40:33 -07:00
Yanwei Guo 8d80e63709
Use hash.BucketSet for standard leader election mode (#1490)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* for standard

* delete bucket

* add s
2020-07-15 16:13:33 -07:00
Yanwei Guo 258f5b86c2
Use hash.BucketSet for StatefulSet mode (#1481)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* use hash bucektset for statefulset mode

* add test

* address comments from victor

* use make
2020-07-14 12:18:19 -07:00
Matt Moore 3a916efe5c
Add flags to disable chaos per-component and configure period. (#1487)
* Add flags to disable chaos per-component and configure period.

* Use the new hotness for creating the set
2020-07-14 09:30:19 -07:00
Victor Agababov 16eea5bd5b
remove the ResourceLock field from the pkg/LE (#1482)
we only use a single possible way, so no need to have, parse and validate
field that is in effectg a constant.
2020-07-14 09:15:18 -07:00
Victor Agababov ac02cac99b
Preallocate sets in pkg (#1485) 2020-07-14 00:09:18 -07:00
Matt Moore 906cdfd465
Remove ha.ExtractDeployment dependency. (#1484)
This was part of the review feedback, but it inadvertently introduced a dependency that redefined a flag causing the duck to crash loop.

This copies the function instead of pulling in the dependency.
2020-07-13 23:52:18 -07:00
Matt Moore 5f4f82f095
Add a new "chaosduck" e2e test tool for leaderelection. (#1333)
* Add a new "chaosduck" e2e test tool for leaderelection.

This adds a new main package under knative.dev/pkg/leaderelection/chaosduck, which
decodes the leases in the system namespace to establish the set of components and
their leader pod names and kills a leader pod for each component on a certain period.

* Incorporate feedback from vagababov

* super nit
2020-07-13 15:41:18 -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
Dave Protasowski e16ecb840d
use coordination.Leases exclusively for leader election (#1439)
* use coordination.Leases exclusively for leader election

Prior locks were for K8s version <1.16

* fix error message
2020-06-29 12:57:29 -07:00
Victor Agababov fe0740d31f
Some cleanups around LE (#1452)
* Some cleanups around LE

- make funcs and types not expected to be used outside private (we can always make them public, should the need arise)
- add some more checks in tests
- fix some strings

* streamline

* hide new

* review

* more
2020-06-27 12:23:28 -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
Yanwei Guo f1ee372577
Introduce a StatefulSet type elector builder (#1438)
* do not record for empty metric config

* Revert "do not record for empty metric config"

This reverts commit 539a5e4dbb.

* introduce statefulset builder

* change comment

* address victors comment and capsulation

* make exported func

* Update leaderelection/ordinal_test.go

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

* Update leaderelection/ordinal_test.go

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

* address comment

* format

* address comment from matt

Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-06-25 19:26:28 -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