Commit Graph

35 Commits

Author SHA1 Message Date
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 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
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
Dave Protasowski 64fc3e502d
ListPointer flag should also apply to filtered informers (#2620) 2022-11-01 14:38:05 +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
Dave Protasowski 785eb637f6
switch to klog/v2 (#2386) 2022-01-11 13:02:14 -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 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
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
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 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
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
Weston Haught aa30bc3ac0
expect resoruces are krshaped by default (#1430) 2020-06-23 10:21:27 -07:00
Victor Agababov b10849aacf
Some nits in the genreconciler (#1328)
* Some nits in the genreconciler

- make sure we allocate proper amount of slice space
-  `t:=t` is needed only if you're doing goroutines in the loop
- extract constants outside of the loops.
- reformat

* meh, I was wrong
2020-05-12 12:11:30 -07:00
Weston Haught 2a7c3fd8e2
use our tag parser (#1327) 2020-05-12 10:45:58 -07:00
Weston Haught 00ce2bb1b4
krshaped should be part of genereconciler (#1326) 2020-05-12 08:28:03 -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
Matt Moore 3da93ebb24
Properly set hasClass (#1296)
This was changed in #1277
2020-05-05 12:10:44 -07:00
Weston Haught 10ba977860
Create our own comment parser for codegen (#1277)
* Adapt our own comment parser

* Use our new comment parser to extract tags

* Update codegen/cmd/injection-gen/generators/comment_parser.go

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

* Update codegen/cmd/injection-gen/generators/comment_parser_test.go

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

* Update codegen/cmd/injection-gen/generators/comment_parser.go

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

* Update codegen/cmd/injection-gen/generators/comment_parser.go

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

* Update codegen/cmd/injection-gen/generators/comment_parser_test.go

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

* Update codegen/cmd/injection-gen/generators/packages.go

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

* suggestion didn't compile

* Update codegen/cmd/injection-gen/generators/comment_parser.go

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

* trimspace

* include test for ,,, case

* add empty check

* fix comment

Co-authored-by: Victor Agababov <vagababov@gmail.com>
2020-05-04 09:42:43 -07:00
Markus Thömmes c09083a601
Fix a few simple linter warnings: unused code, govet warnings etc. (#1191) 2020-04-06 08:21:20 -07:00
Scott Nichols 8a6d25b309
Generate reconcilers for resources out of tree. (#1175)
* genreconciler:nonNamespaced

* Adding a force-kinds flag to the reconciler generator to allow us to generate reconcilers for non-owned types.

* force-kinds --> force-genreconciler-kinds

* some minor nits with the generators for non-knative types needed to be removed.

* remove whitespace

Co-authored-by: Nacho Cano <nachoacano@gmail.com>
2020-03-25 11:34:51 -07: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
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
Scott Nichols 248c9f0353
fix filtering for reconcilers gen. (#1071) 2020-02-11 05:26:07 -08:00
Scott Nichols 85608a8329
Generate Managed Finalizers for Reconcilers (#1069)
* fix rando issues

* code in the group for finalizer name.

* Use FinalizeKind

* show the Finalizer interface.

* removing isFinalizing

* sync finalizers before calling reconcilekind

* missed the events change.
2020-02-10 19:46:06 -08:00
Scott Nichols b9974987c2
Fix issue with returning errors, and not adding scheme (#1049) 2020-02-04 18:03:30 -08:00
Scott Nichols b317048346
Generate Base Reconciler Code for Injection Based Controllers. (#947)
* adding a reconciler generator to use as the base reconcilers for all of knative.

* mend

* fix tag names.

* use reconciler events

* trying new thing.

* base working reconciler gen

* working cleaned up reconciler generator.

* fix typo

* fix some ordering.

* fix interface path

* fix whitespace

* update deps.

* updates based on feedback.

* Remove core loop.

* reconcilerImpl

* add NewReconciler

* Fix copyright header

* Comment out finalizers

* remove finalizers from generated code.
2020-02-04 10:23:30 -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
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 222dd25986 Migrate pkg to use the knative.dev/pkg import path (#489)
* Manual changes.

* scripted changes.
2019-06-26 13:02:06 -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