Commit Graph

109 Commits

Author SHA1 Message Date
Dave Protasowski ae2c6bcc1f
Bump K8s min version to v1.31 (#3149)
* bump k8s deps to v0.32.1

* bump k8s min version to v1.31

* bump to v0.32.2
2025-02-14 14:05:53 +00:00
Dave Protasowski 36226ee206
Update Knative injection-gen to use gengov2 (#3146)
* refactor codegen into different packages and use gengo v2

This allows us to run this injection against types that have newer golang features - eg. 'any'

* updated go.mod drops gengo v1

* tweak scripts to support gengov2 framework

* drop verbose output
2025-02-11 17:07:50 +00:00
Dave Protasowski cd3311cbab
bump k8s deps to v0.30.3 (#3084)
* bump k8s version

* vendor k8s code from 1.29

* don't pin go to a patch version

* don't bump websocket lib

* set go.mod to include patch
2024-08-12 05:32:09 +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
Stavros Kontopoulos f69f148b7c
Optionally generate an init func for an informer (#2989)
* Optionally generate an init func for an informer

* lint

* move condition to go template

* rename flag and fixes

* pass flag value via the generator
2024-03-28 13:51:56 +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
Reto Lehmann fac3a4ffbc
fix closure variable in filtered factory (#2884) 2023-11-02 20:06:04 +00:00
pradnyavmw 05bfcf66c2
bump k8s dependencies and update min version to v1.25 (#2745)
* Update defaultMinimumVersion

* Fix issues that occurred after running update-k8s-deps

* Adding changes to vendor and other folders

* Add new files after running update-codegen

* Add newLine
2023-05-23 14:06:11 +00:00
Dave Protasowski dfb4bf0463
Drop dynamic wrapper injection code generation (#2742)
* drop dynamic wrapper injection codegen

* run update codegen
2023-05-18 10:57:12 +00:00
Pierangelo Di Pilato 2fdd6bf8be
Allow reconcilers to listen to leader promotion events (#2688)
* Generator: allow reconcilers to listen to leader promotion events

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

* Run hack/update-codegen.sh

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

---------

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2023-02-22 15:02:28 +00:00
Rafał Bigaj 33e6b88010
fix: `reconcilerImpl.updateStatus` calculates state difference in debug mode only (#2678)
The state comparison using `kmp.SafeDiff(existing.Status, desired.Status)` in the `reconcilerImpl.updateStatus` method is costly and performed for debug logging purposes.

Issue: https://github.com/knative/pkg/issues/2677
2023-02-15 23:08:51 +00:00
Dave Protasowski 44d1d7d978
Go1.19 changes (#2631)
* run goimports

* ignore linter errors for now

* fix boilerplate
2022-11-03 22:34:05 +00:00
Dave Protasowski 64fc3e502d
ListPointer flag should also apply to filtered informers (#2620) 2022-11-01 14:38:05 +00:00
Matt Moore 2f194914a4
Feature: Implement Apply codegen. (#2624)
🎁 Now that the K8s client libraries have an Apply method for the dynamic client, plumb it through the client code generation.

/kind feature
2022-10-31 20:24:13 +00:00
Dave Protasowski 5dd89c68db
Support istio *List types where Items is an array of pointer types (#2613)
Generally K8s types have a list type where the 'Items' member is an
array of structs.

ie. https://pkg.go.dev/k8s.io/api@v0.25.3/apps/v1#DeploymentList

type DeploymentList struct {
	...
	// Items is the list of Deployments.
	Items []Deployment `json:"items" protobuf:"bytes,2,rep,name=items"`
}

Istio is an exception where the list contains pointers to structs

type GatewayList struct {
	...
	Items       []*Gateway `json:"items" protobuf:"bytes,2,rep,name=items"`
}

To hint that the list types are pointers you can now pass the flag
'--lister-has-pointer-elem'.

Ideally we could infer this info by inspecting the types but
unfortunately the generator doesn't load this information
2022-10-20 14:09:13 +00:00
Matt Moore df29e2a20a
Avoid second lister fetch during finalizer reconciliation. (#2596)
I noticed that the finalizer manipulation code was performing a second fetch of the resource from the lister cache to determine the differences in finalizers when the finalizers are being modify immediately above each callsite.

This changes both call sites to simply pass through the "desired finalizers" as a new parameter (instead of assigning them), which lets us use the unmodified resource and avoid the redundant lister cache fetch.
2022-09-20 22:43:09 +00:00
Dave Protasowski 3764d73bf9
fix linting (#2555) 2022-07-22 15:28:21 +00:00
Dave Protasowski 785eb637f6
switch to klog/v2 (#2386) 2022-01-11 13:02:14 -08:00
Matt Moore 52e42b760b
Extend Apply verb to extensions, Bump to K8s 1.22. (#2327)
* Extend Apply verb to extensions, Bump to K8s 1.22.

This was motivated by the linked issue, and does the work to upgrade PKG to 1.22 libs.

Fixes: https://github.com/knative/pkg/issues/2320

* 0.22.2 -> 0.22.5
2022-01-04 10:58:30 -08:00
Dave Protasowski 5708c4c442
codegen - support multiple annotation keys (#2350)
* allow multiple values for comment tag keys

this will allow us to support multiple annotation keys

* add OR filter chain

* update codegen to support multiple annotation keys

* Preserve previous code & formatting if the number of annotation keys is 1

- preserve the order of the annotations vs. sorting it
- deprecate and don't remove ClassAnnotationKey to allow migration to happen smoothly

* fix default value for krshape

* include clarifying comment
2021-11-17 13:53:28 -08:00
Matt Moore 819d556cda
Allow configuring bounded staleness for dynamic injection. (#2323)
Unfortunately the lister interfaces didn't plumb through `ctx` so
this is slightly more complex than I'd have liked.  Instead of
threading the `resourceVersion` (bounded-staleness) through `ctx`
it is stored on the lister implementation.

It is seeded with `injection.WithResourceVersion` (ideally this
would have been all we needed, w/o state), and this state can be
updated by calling `SetResourceVersion`.

The stored `resourceVersion` is passed via `FooOptions` to `Get`
and `List` calls.

Fixes: a long-standing `TODO(mattmoor)`
2021-10-25 08:17:38 -07:00
Markus Thömmes bfab3c8fc5
Add back inadvertedly deleted call to ObserveKind (#2282) 2021-09-09 08:40:59 -07:00
Markus Thömmes d9b35c4013
Delete deprecated ObserveFinalizeKind API (#2248)
* Delete deprecated ObserveFinalizeKind API

* Add back global to allow changes to propagate cleanly
2021-09-08 13:17:58 -07:00
Markus Thömmes 2bd91f7557
Bump K8s dependencies to 1.21.4 (#2242)
* Bump apimachinery

* Update code-generator

* Update API and client, some progress

* Hack the generator to work at all

* Hack the PodDisruptionBudget extension to fulfill the interfaces

* Bump apiextensions as well

* Fix conflict

* Better condition

* Roll back unnecessary codegen change

* Fix PodDisruptionBudget extensions

* Panic on not-yet-implemented like others
2021-08-27 11:45:38 -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 52d2a0db1e
Deprecate ReadOnlyFinalizer interface over OnDeletionInterface (#2212)
* Deprecate ReadOnlyFinalizer interface over OnDeletionInterface

* Fix deprecated
2021-08-20 09:41:05 -07:00
Matt Moore 7b5ecbc0e4
Sketch out an alternate way of injecting clients/informers (#2210)
* This commit contains the actual changes to support dynamic client injection.

* Incorporate n3wscott review nits

* This includes the code-generation for the dynamic client-based injection.

This also includes a number of manually created files of the form `*_expansion.go`, which are needed to satisfy some of the Kubernetes manual type "expansions".  At present, these are all simply `panic("NYI")`, but may become more than that in the future.
2021-08-18 06:52:08 -07:00
Matt Moore bf176d5654
Sink two codegen passes below loop. (#2209)
I noticed doing some tinkering that these were running on every iteration, but the inputs don't change.  This sinks the calls to below the loop, and reduces things to a single call for each.
2021-08-16 15:37:16 -07:00
Matt Moore bb4aaf09c4
Ignore special errors in codegen for events (#2202) 2021-07-30 10:21:32 -07:00
Ben Moss 7d1b0f19ef
Add ability to filter objects on injection controller promotion (#2180)
Currently we enqueue every object with no way to filter, which causes
problems for eventing's source controller which reconciles duck CRDs.
2021-07-13 10:55:50 -07:00
ying e2947dba20
update the multiple label selector implemention to avoid clobber in filtered factory (#2120) 2021-05-25 00:14:38 -07:00
Ben Moss cfc1eed828
Better support for error wrapping with ReconcilerEvents (#2106)
* Fix codegen to work outside GOPATH

* Fix ReconcilerEvent handling of %w format strings

Using fmt.Errorf(...).Error() means we get %w's translated to %v's for
printing
2021-04-26 11:00:40 -07:00
Markus Thömmes 78b8140ed1
Use semantic equality for status update retries (#2103) 2021-04-23 09:26:38 -07:00
Markus Thömmes 2e62ba6a9d
Add possibility to implement a deletion handler in a reconciler. (#2089)
* Add possibility to implement a deletion handler in a reconciler.

ObserveFinalizeKind is not guaranteed to be called for every resource
that gets deleted, even if they do have a finalizer. The leader can race
the observers in removing the finalizer so the observers would not even
see the deletion.

Using the OnDelete handler on the informer is equally racy in that it
can trigger the deletion handler while a potential "normal" reconcile is
still in-flight.

This adds an ObserveDeletedKind handler that can be implemented by
reconcilers. The events still go via the workQueue, so proper order and
deduplication is guaranteed. Observation is guaranteed as well. In most
if not all cases, this handler should replace the ObserveFinalizeKind
handler.

* Move interface to its own file

* Fix license

* Fix comment
2021-04-19 08:38:00 -07:00
Markus Thömmes b51994e3b3
Fix a few comments in reconciler-gen (#2090) 2021-04-12 10:37:42 -07:00
Sameer Vohra 9d92ea16c0
Update reconciler_controller.go (#2066)
* Update reconciler_controller.go

nit: fix tiny typo

* Ran ./hack/update-codegen.sh

Signed-off-by: Sameer Vohra <vsameer@vmware.com>
2021-03-28 23:52:22 -07:00
Markus Thömmes bbe0bb3eb1
Implement getter machinery to generically fetch all injected clients (#2054) 2021-03-10 09:35:25 -08:00
Lionel Villard 07b5ddfaea
add demoteFunc controller option (#2033)
* add demoteFunc controller option

* use tab instead of space for indent

* run codegen
2021-02-25 14:10:47 -08:00
Francesco Guardiani ca02ef752a
Genreconciler properly generates reconciler for Resources with Status (#2004)
* Fix #2003

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Removed useless newline

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Removed useless check

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Now we don't have any newlines anymore

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
2021-01-29 16:18:31 -08:00
qibobo 1bbf0a6436
add LabelSelector to InformerFactory so that the informers only list and watch resources with the given labels (#1940)
* add  filtered InformerFactory and informers which only list and watch resources with the given labels

* rename to RegisterFilteredInformers

* generated files

* typo

* update per comments

* rename file

* rm old files
2021-01-19 08:21:23 -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 a1d2289bb5
Remove useless logger creation (#1966) 2020-12-15 10:22:58 -08:00
Jon Donovan 9bf616d2f4
Fail louder when bad context given to injection (#1768)
This uses the presence of the config key to determine whether
this is an injection context, and if it is not, the panic
message includes a notice about injection context behavior.
2020-11-25 01:50:35 -08:00
Markus Thömmes a2394e8895
Fix produced events if patching a finalizer fails (#1843) 2020-10-26 09:05:41 -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 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 5d1dfa9ef7
Improve the logging messages in the reconciler generator. (#1750)
And other minor nits.
2020-09-28 13:32:28 -07:00
Markus Thömmes 754da4653a
Enable unparam linter to catch unused parameters (#1731) 2020-09-22 09:13:40 -07:00