From bf5fa8873fd7d5be3ff9832fe8e7b081b4d4a504 Mon Sep 17 00:00:00 2001 From: Bryce Palmer Date: Thu, 16 May 2024 16:20:22 -0400 Subject: [PATCH] bump to go 1.22 and k8s 0.30.0 (#176) Signed-off-by: everettraven --- go.mod | 29 ++++---- go.sum | 54 +++++++------- handler/enqueue_annotation.go | 14 ++-- handler/enqueue_annotation_test.go | 26 ++++--- handler/example_test.go | 4 +- handler/instrumented_enqueue_object.go | 16 ++--- handler/instrumented_enqueue_object_test.go | 8 +-- handler/pause.go | 5 +- internal/annotation/filter.go | 78 ++++++++++++--------- internal/annotation/filter_test.go | 8 +-- predicate/example_test.go | 3 +- predicate/pause.go | 5 +- 12 files changed, 131 insertions(+), 119 deletions(-) diff --git a/go.mod b/go.mod index 506c50e..02634ca 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,19 @@ module github.com/operator-framework/operator-lib -go 1.21 +go 1.22.0 require ( github.com/go-logr/logr v1.4.1 github.com/onsi/ginkgo/v2 v2.17.1 github.com/onsi/gomega v1.32.0 - github.com/operator-framework/api v0.23.0 + github.com/operator-framework/api v0.24.0 github.com/prometheus/client_golang v1.19.0 github.com/prometheus/client_model v0.6.1 - k8s.io/api v0.29.2 - k8s.io/apimachinery v0.29.2 - k8s.io/client-go v0.29.2 - k8s.io/utils v0.0.0-20240102154912-e7106e64919e - sigs.k8s.io/controller-runtime v0.17.2 + k8s.io/api v0.30.0 + k8s.io/apimachinery v0.30.0 + k8s.io/client-go v0.30.0 + k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 + sigs.k8s.io/controller-runtime v0.18.2 ) require ( @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.11.2 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect - github.com/evanphx/json-patch/v5 v5.8.0 // indirect + github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-openapi/jsonpointer v0.20.2 // indirect github.com/go-openapi/jsonreference v0.20.4 // indirect @@ -30,7 +30,7 @@ require ( github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect @@ -48,10 +48,10 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect - golang.org/x/net v0.21.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.17.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/term v0.17.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.18.0 // indirect @@ -61,10 +61,9 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.29.2 // indirect - k8s.io/component-base v0.29.2 // indirect + k8s.io/apiextensions-apiserver v0.30.0 // indirect k8s.io/klog/v2 v2.120.1 // indirect - k8s.io/kube-openapi v0.0.0-20240221221325-2ac9dc51f3f1 // indirect + k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect diff --git a/go.sum b/go.sum index 2191f29..ee0c9a3 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/emicklei/go-restful/v3 v3.11.2 h1:1onLa9DcsMYO9P+CXaL0dStDqQ2EHHXLiz+ github.com/emicklei/go-restful/v3 v3.11.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1u0KQro= -github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= +github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= @@ -31,8 +31,8 @@ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -71,8 +71,8 @@ github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8 github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= -github.com/operator-framework/api v0.23.0 h1:kHymOwcHBpBVujT49SKOCd4EVG7Odwj4wl3NbOR2LLA= -github.com/operator-framework/api v0.23.0/go.mod h1:oKcFOz+Xc1UhMi2Pzcp6qsO7wjS4r+yP7EQprQBXrfM= +github.com/operator-framework/api v0.24.0 h1:fHynWEzuY/YhUTlsK9hd+QQ0bZcFakxCTdaZbFaVXbc= +github.com/operator-framework/api v0.24.0/go.mod h1:EXKrka63NyQDDpWZ+DGTDEliNV0xRq6UMZRoUPhilVM= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -118,8 +118,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ= golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -133,12 +133,12 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -177,24 +177,22 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.29.2 h1:hBC7B9+MU+ptchxEqTNW2DkUosJpp1P+Wn6YncZ474A= -k8s.io/api v0.29.2/go.mod h1:sdIaaKuU7P44aoyyLlikSLayT6Vb7bvJNCX105xZXY0= -k8s.io/apiextensions-apiserver v0.29.2 h1:UK3xB5lOWSnhaCk0RFZ0LUacPZz9RY4wi/yt2Iu+btg= -k8s.io/apiextensions-apiserver v0.29.2/go.mod h1:aLfYjpA5p3OwtqNXQFkhJ56TB+spV8Gc4wfMhUA3/b8= -k8s.io/apimachinery v0.29.2 h1:EWGpfJ856oj11C52NRCHuU7rFDwxev48z+6DSlGNsV8= -k8s.io/apimachinery v0.29.2/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU= -k8s.io/client-go v0.29.2 h1:FEg85el1TeZp+/vYJM7hkDlSTFZ+c5nnK44DJ4FyoRg= -k8s.io/client-go v0.29.2/go.mod h1:knlvFZE58VpqbQpJNbCbctTVXcd35mMyAAwBdpt4jrA= -k8s.io/component-base v0.29.2 h1:lpiLyuvPA9yV1aQwGLENYyK7n/8t6l3nn3zAtFTJYe8= -k8s.io/component-base v0.29.2/go.mod h1:BfB3SLrefbZXiBfbM+2H1dlat21Uewg/5qtKOl8degM= +k8s.io/api v0.30.0 h1:siWhRq7cNjy2iHssOB9SCGNCl2spiF1dO3dABqZ8niA= +k8s.io/api v0.30.0/go.mod h1:OPlaYhoHs8EQ1ql0R/TsUgaRPhpKNxIMrKQfWUp8QSE= +k8s.io/apiextensions-apiserver v0.30.0 h1:jcZFKMqnICJfRxTgnC4E+Hpcq8UEhT8B2lhBcQ+6uAs= +k8s.io/apiextensions-apiserver v0.30.0/go.mod h1:N9ogQFGcrbWqAY9p2mUAL5mGxsLqwgtUce127VtRX5Y= +k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= +k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/client-go v0.30.0 h1:sB1AGGlhY/o7KCyCEQ0bPWzYDL0pwOZO4vAtTSh/gJQ= +k8s.io/client-go v0.30.0/go.mod h1:g7li5O5256qe6TYdAMyX/otJqMhIiGgTapdLchhmOaY= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20240221221325-2ac9dc51f3f1 h1:rtdnaWfP40MTKv7izH81gkWpZB45pZrwIxyZdPSn1mI= -k8s.io/kube-openapi v0.0.0-20240221221325-2ac9dc51f3f1/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw= -k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= -k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.17.2 h1:FwHwD1CTUemg0pW2otk7/U5/i5m2ymzvOXdbeGOUvw0= -sigs.k8s.io/controller-runtime v0.17.2/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s= +k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= +k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= +k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= +k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/controller-runtime v0.18.2 h1:RqVW6Kpeaji67CY5nPEfRz6ZfFMk0lWQlNrLqlNpx+Q= +sigs.k8s.io/controller-runtime v0.18.2/go.mod h1:tuAt1+wbVsXIT8lPtk5RURxqAnq7xkpv2Mhttslg7Hw= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/handler/enqueue_annotation.go b/handler/enqueue_annotation.go index fe882d5..3b32074 100644 --- a/handler/enqueue_annotation.go +++ b/handler/enqueue_annotation.go @@ -81,21 +81,21 @@ const ( // if a parent creates a child resource across scopes not supported by owner references, it becomes the // responsibility of the reconciler to clean up the child resource. Hence, the resource utilizing this handler // SHOULD ALWAYS BE IMPLEMENTED WITH A FINALIZER. -type EnqueueRequestForAnnotation struct { +type EnqueueRequestForAnnotation[T client.Object] struct { Type schema.GroupKind } -var _ crtHandler.EventHandler = &EnqueueRequestForAnnotation{} +var _ crtHandler.EventHandler = &EnqueueRequestForAnnotation[client.Object]{} // Create implements EventHandler -func (e *EnqueueRequestForAnnotation) Create(_ context.Context, evt event.CreateEvent, q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Create(_ context.Context, evt event.TypedCreateEvent[T], q workqueue.RateLimitingInterface) { if ok, req := e.getAnnotationRequests(evt.Object); ok { q.Add(req) } } // Update implements EventHandler -func (e *EnqueueRequestForAnnotation) Update(_ context.Context, evt event.UpdateEvent, q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Update(_ context.Context, evt event.TypedUpdateEvent[T], q workqueue.RateLimitingInterface) { if ok, req := e.getAnnotationRequests(evt.ObjectOld); ok { q.Add(req) } @@ -105,21 +105,21 @@ func (e *EnqueueRequestForAnnotation) Update(_ context.Context, evt event.Update } // Delete implements EventHandler -func (e *EnqueueRequestForAnnotation) Delete(_ context.Context, evt event.DeleteEvent, q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Delete(_ context.Context, evt event.TypedDeleteEvent[T], q workqueue.RateLimitingInterface) { if ok, req := e.getAnnotationRequests(evt.Object); ok { q.Add(req) } } // Generic implements EventHandler -func (e *EnqueueRequestForAnnotation) Generic(_ context.Context, evt event.GenericEvent, q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Generic(_ context.Context, evt event.TypedGenericEvent[T], q workqueue.RateLimitingInterface) { if ok, req := e.getAnnotationRequests(evt.Object); ok { q.Add(req) } } // getAnnotationRequests checks if the provided object has the annotations so as to enqueue the reconcile request. -func (e *EnqueueRequestForAnnotation) getAnnotationRequests(object metav1.Object) (bool, reconcile.Request) { +func (e *EnqueueRequestForAnnotation[T]) getAnnotationRequests(object metav1.Object) (bool, reconcile.Request) { if len(object.GetAnnotations()) == 0 { return false, reconcile.Request{} } diff --git a/handler/enqueue_annotation_test.go b/handler/enqueue_annotation_test.go index 8835aa9..cc0027c 100644 --- a/handler/enqueue_annotation_test.go +++ b/handler/enqueue_annotation_test.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllertest" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -32,10 +33,10 @@ import ( ) var _ = Describe("EnqueueRequestForAnnotation", func() { - var ctx = context.TODO() + ctx := context.TODO() var q workqueue.RateLimitingInterface - var instance EnqueueRequestForAnnotation + var instance EnqueueRequestForAnnotation[client.Object] var pod *corev1.Pod var podOwner *corev1.Pod @@ -57,11 +58,12 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { podOwner.SetGroupVersionKind(schema.GroupVersionKind{Group: "", Kind: "Pod"}) Expect(SetOwnerAnnotations(podOwner, pod)).To(Succeed()) - instance = EnqueueRequestForAnnotation{ + instance = EnqueueRequestForAnnotation[client.Object]{ Type: schema.GroupKind{ Group: "", Kind: "Pod", - }} + }, + } }) Describe("Create", func() { @@ -181,7 +183,8 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { i, _ := q.Get() Expect(i).To(Equal(reconcile.Request{ - NamespacedName: types.NamespacedName{Namespace: "", Name: "AppService"}})) + NamespacedName: types.NamespacedName{Namespace: "", Name: "AppService"}, + })) }) It("should enqueue a Request for an object that is cluster scoped which has the annotations", func() { nd := &corev1.Node{ @@ -194,7 +197,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { }, } - instance = EnqueueRequestForAnnotation{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}} + instance = EnqueueRequestForAnnotation[client.Object]{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}} evt := event.CreateEvent{ Object: nd, @@ -205,14 +208,15 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { i, _ := q.Get() Expect(i).To(Equal(reconcile.Request{ - NamespacedName: types.NamespacedName{Namespace: "", Name: "myapp"}})) + NamespacedName: types.NamespacedName{Namespace: "", Name: "myapp"}, + })) }) It("should not enqueue a Request for an object that is cluster scoped which does not have annotations", func() { nd := &corev1.Node{ ObjectMeta: metav1.ObjectMeta{Name: "node-1"}, } - instance = EnqueueRequestForAnnotation{Type: nd.GetObjectKind().GroupVersionKind().GroupKind()} + instance = EnqueueRequestForAnnotation[client.Object]{Type: nd.GetObjectKind().GroupVersionKind().GroupKind()} evt := event.CreateEvent{ Object: nd, } @@ -293,7 +297,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { Name: "faz", }, } - instance = EnqueueRequestForAnnotation{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}} + instance = EnqueueRequestForAnnotation[client.Object]{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}} evt := event.CreateEvent{ Object: repl, @@ -311,7 +315,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { NamespacedNameAnnotation: "foo/faz", } - instance2 := EnqueueRequestForAnnotation{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}} + instance2 := EnqueueRequestForAnnotation[client.Object]{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}} evt2 := event.UpdateEvent{ ObjectOld: repl, @@ -336,7 +340,7 @@ var _ = Describe("EnqueueRequestForAnnotation", func() { Expect(SetOwnerAnnotations(podOwner, pod)).To(Succeed()) - var podOwner2 = &corev1.Pod{ + podOwner2 := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Namespace: "podOwnerNsTest", Name: "podOwnerNameTest", diff --git a/handler/example_test.go b/handler/example_test.go index a0ff195..d702b32 100644 --- a/handler/example_test.go +++ b/handler/example_test.go @@ -51,11 +51,11 @@ func ExampleNewPause() { } // Filter out Pods with the "my.app/paused: true" annotation. - pause, err := handler.NewPause("my.app/paused") + pause, err := handler.NewPause[*corev1.Pod]("my.app/paused") if err != nil { os.Exit(1) } - if err := c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}), pause); err != nil { + if err := c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}, pause)); err != nil { os.Exit(1) } diff --git a/handler/instrumented_enqueue_object.go b/handler/instrumented_enqueue_object.go index c489abb..6e351a3 100644 --- a/handler/instrumented_enqueue_object.go +++ b/handler/instrumented_enqueue_object.go @@ -36,28 +36,28 @@ import ( // To call the handler use: // // &handler.InstrumentedEnqueueRequestForObject{} -type InstrumentedEnqueueRequestForObject struct { - handler.EnqueueRequestForObject +type InstrumentedEnqueueRequestForObject[T client.Object] struct { + handler.TypedEnqueueRequestForObject[T] } // Create implements EventHandler, and creates the metrics. -func (h InstrumentedEnqueueRequestForObject) Create(ctx context.Context, e event.CreateEvent, q workqueue.RateLimitingInterface) { +func (h InstrumentedEnqueueRequestForObject[T]) Create(ctx context.Context, e event.TypedCreateEvent[T], q workqueue.RateLimitingInterface) { setResourceMetric(e.Object) - h.EnqueueRequestForObject.Create(ctx, e, q) + h.TypedEnqueueRequestForObject.Create(ctx, e, q) } // Update implements EventHandler, and updates the metrics. -func (h InstrumentedEnqueueRequestForObject) Update(ctx context.Context, e event.UpdateEvent, q workqueue.RateLimitingInterface) { +func (h InstrumentedEnqueueRequestForObject[T]) Update(ctx context.Context, e event.TypedUpdateEvent[T], q workqueue.RateLimitingInterface) { setResourceMetric(e.ObjectOld) setResourceMetric(e.ObjectNew) - h.EnqueueRequestForObject.Update(ctx, e, q) + h.TypedEnqueueRequestForObject.Update(ctx, e, q) } // Delete implements EventHandler, and deletes metrics. -func (h InstrumentedEnqueueRequestForObject) Delete(ctx context.Context, e event.DeleteEvent, q workqueue.RateLimitingInterface) { +func (h InstrumentedEnqueueRequestForObject[T]) Delete(ctx context.Context, e event.TypedDeleteEvent[T], q workqueue.RateLimitingInterface) { deleteResourceMetric(e.Object) - h.EnqueueRequestForObject.Delete(ctx, e, q) + h.TypedEnqueueRequestForObject.Delete(ctx, e, q) } func setResourceMetric(obj client.Object) { diff --git a/handler/instrumented_enqueue_object_test.go b/handler/instrumented_enqueue_object_test.go index 946854b..dcc7464 100644 --- a/handler/instrumented_enqueue_object_test.go +++ b/handler/instrumented_enqueue_object_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/workqueue" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllertest" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -33,10 +34,10 @@ import ( ) var _ = Describe("InstrumentedEnqueueRequestForObject", func() { - var ctx = context.TODO() + ctx := context.TODO() var q workqueue.RateLimitingInterface - var instance InstrumentedEnqueueRequestForObject + var instance InstrumentedEnqueueRequestForObject[client.Object] var pod *corev1.Pod registry := prometheus.NewRegistry() @@ -44,7 +45,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() { BeforeEach(func() { q = &controllertest.Queue{Interface: workqueue.New()} - instance = InstrumentedEnqueueRequestForObject{} + instance = InstrumentedEnqueueRequestForObject[client.Object]{} pod = &corev1.Pod{ TypeMeta: metav1.TypeMeta{ Kind: "Pod", @@ -142,7 +143,6 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() { Expect(gauges).To(BeEmpty()) }) }) - }) Describe("Update", func() { diff --git a/handler/pause.go b/handler/pause.go index 9ce2b4a..aee2338 100644 --- a/handler/pause.go +++ b/handler/pause.go @@ -15,6 +15,7 @@ package handler import ( + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" "github.com/operator-framework/operator-lib/internal/annotation" @@ -31,6 +32,6 @@ import ( // a stricter annotation modification policy. See AdmissionReview configuration for user info available // to a webhook: // https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#request -func NewPause(key string) (handler.EventHandler, error) { - return annotation.NewFalsyEventHandler(key, annotation.Options{Log: log}) +func NewPause[T client.Object](key string) (handler.TypedEventHandler[T], error) { + return annotation.NewFalsyEventHandler[T](key, annotation.Options{Log: log}) } diff --git a/internal/annotation/filter.go b/internal/annotation/filter.go index f56a03e..c6257b7 100644 --- a/internal/annotation/filter.go +++ b/internal/annotation/filter.go @@ -47,30 +47,30 @@ type Options struct { // NewFalsyPredicate returns a predicate that passes objects // that do not have annotation with key string key or whose value is falsy. -func NewFalsyPredicate(key string, opts Options) (predicate.Predicate, error) { +func NewFalsyPredicate[T client.Object](key string, opts Options) (predicate.TypedPredicate[T], error) { opts.truthy = false - return newFilter(key, opts) + return newFilter[T](key, opts) } // NewFalsyEventHandler returns an event handler that enqueues objects // that do not have annotation with key string key or whose value is falsy. -func NewFalsyEventHandler(key string, opts Options) (handler.EventHandler, error) { +func NewFalsyEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T], error) { opts.truthy = false - return newEventHandler(key, opts) + return newEventHandler[T](key, opts) } // NewTruthyPredicate returns a predicate that passes objects // that do have annotation with key string key and whose value is truthy. -func NewTruthyPredicate(key string, opts Options) (predicate.Predicate, error) { +func NewTruthyPredicate[T client.Object](key string, opts Options) (predicate.TypedPredicate[T], error) { opts.truthy = true - return newFilter(key, opts) + return newFilter[T](key, opts) } // NewTruthyEventHandler returns an event handler that enqueues objects // that do have annotation with key string key and whose value is truthy. -func NewTruthyEventHandler(key string, opts Options) (handler.EventHandler, error) { +func NewTruthyEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T], error) { opts.truthy = true - return newEventHandler(key, opts) + return newEventHandler[T](key, opts) } func defaultOptions(opts *Options) { @@ -80,30 +80,30 @@ func defaultOptions(opts *Options) { } // newEventHandler returns a filter for use as an event handler. -func newEventHandler(key string, opts Options) (handler.EventHandler, error) { - f, err := newFilter(key, opts) +func newEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T], error) { + f, err := newFilter[T](key, opts) if err != nil { return nil, err } - f.hdlr = &handler.EnqueueRequestForObject{} - return handler.Funcs{ - CreateFunc: func(ctx context.Context, evt event.CreateEvent, q workqueue.RateLimitingInterface) { + f.hdlr = &handler.TypedEnqueueRequestForObject[T]{} + return handler.TypedFuncs[T]{ + CreateFunc: func(ctx context.Context, evt event.TypedCreateEvent[T], q workqueue.RateLimitingInterface) { if f.Create(evt) { f.hdlr.Create(ctx, evt, q) } }, - UpdateFunc: func(ctx context.Context, evt event.UpdateEvent, q workqueue.RateLimitingInterface) { + UpdateFunc: func(ctx context.Context, evt event.TypedUpdateEvent[T], q workqueue.RateLimitingInterface) { if f.Update(evt) { f.hdlr.Update(ctx, evt, q) } }, - DeleteFunc: func(ctx context.Context, evt event.DeleteEvent, q workqueue.RateLimitingInterface) { + DeleteFunc: func(ctx context.Context, evt event.TypedDeleteEvent[T], q workqueue.RateLimitingInterface) { if f.Delete(evt) { f.hdlr.Delete(ctx, evt, q) } }, - GenericFunc: func(ctx context.Context, evt event.GenericEvent, q workqueue.RateLimitingInterface) { + GenericFunc: func(ctx context.Context, evt event.TypedGenericEvent[T], q workqueue.RateLimitingInterface) { if f.Generic(evt) { f.hdlr.Generic(ctx, evt, q) } @@ -112,7 +112,7 @@ func newEventHandler(key string, opts Options) (handler.EventHandler, error) { } // newFilter returns a filter for use as a predicate. -func newFilter(key string, opts Options) (*filter, error) { +func newFilter[T client.Object](key string, opts Options) (*filter[T], error) { defaultOptions(&opts) // Make sure the annotation key and eventual value are valid together. @@ -120,7 +120,7 @@ func newFilter(key string, opts Options) (*filter, error) { return nil, err } - f := filter{} + f := filter[T]{} f.key = key // Falsy filters return true in all cases except when the annotation is present and true. // Truthy filters only return true when the annotation is present and true. @@ -138,31 +138,37 @@ func validateAnnotation(key string, truthy bool) error { // filter implements a filter for objects with a truthy "paused" annotation (see Key). // When this annotation is removed or value does not evaluate to "true", // the controller will see events from these objects again. -type filter struct { +type filter[T client.Object] struct { key string ret bool log logr.Logger - hdlr *handler.EnqueueRequestForObject + hdlr *handler.TypedEnqueueRequestForObject[T] } // Create implements predicate.Predicate.Create(). -func (f *filter) Create(evt event.CreateEvent) bool { - if evt.Object == nil { +func (f *filter[T]) Create(evt event.TypedCreateEvent[T]) bool { + var obj client.Object = evt.Object + if obj == nil { if f.hdlr == nil { f.log.Error(nil, "CreateEvent received with no metadata", "event", evt) } return f.ret } - return f.run(evt.Object) + return f.run(obj) } // Update implements predicate.Predicate.Update(). -func (f *filter) Update(evt event.UpdateEvent) bool { - if evt.ObjectNew != nil { - return f.run(evt.ObjectNew) - } else if evt.ObjectOld != nil { - return f.run(evt.ObjectOld) +func (f *filter[T]) Update(evt event.TypedUpdateEvent[T]) bool { + var newObj client.Object = evt.ObjectNew + if newObj != nil { + return f.run(newObj) } + + var oldObj client.Object = evt.ObjectOld + if oldObj != nil { + return f.run(oldObj) + } + if f.hdlr == nil { f.log.Error(nil, "UpdateEvent received with no metadata", "event", evt) } @@ -170,28 +176,30 @@ func (f *filter) Update(evt event.UpdateEvent) bool { } // Delete implements predicate.Predicate.Delete(). -func (f *filter) Delete(evt event.DeleteEvent) bool { - if evt.Object == nil { +func (f *filter[T]) Delete(evt event.TypedDeleteEvent[T]) bool { + var obj client.Object = evt.Object + if obj == nil { if f.hdlr == nil { f.log.Error(nil, "DeleteEvent received with no metadata", "event", evt) } return f.ret } - return f.run(evt.Object) + return f.run(obj) } // Generic implements predicate.Predicate.Generic(). -func (f *filter) Generic(evt event.GenericEvent) bool { - if evt.Object == nil { +func (f *filter[T]) Generic(evt event.TypedGenericEvent[T]) bool { + var obj client.Object = evt.Object + if obj == nil { if f.hdlr == nil { f.log.Error(nil, "GenericEvent received with no metadata", "event", evt) } return f.ret } - return f.run(evt.Object) + return f.run(obj) } -func (f *filter) run(obj client.Object) bool { +func (f *filter[T]) run(obj client.Object) bool { annotations := obj.GetAnnotations() if len(annotations) == 0 { return f.ret diff --git a/internal/annotation/filter_test.go b/internal/annotation/filter_test.go index 4e470b7..b221c3a 100644 --- a/internal/annotation/filter_test.go +++ b/internal/annotation/filter_test.go @@ -56,9 +56,9 @@ var _ = Describe("filter", func() { hdlr handler.EventHandler ) BeforeEach(func() { - pred, err = annotation.NewFalsyPredicate(annotationKey, annotation.Options{Log: logf.Log}) + pred, err = annotation.NewFalsyPredicate[client.Object](annotationKey, annotation.Options{Log: logf.Log}) Expect(err).NotTo(HaveOccurred()) - hdlr, err = annotation.NewFalsyEventHandler(annotationKey, annotation.Options{Log: logf.Log}) + hdlr, err = annotation.NewFalsyEventHandler[client.Object](annotationKey, annotation.Options{Log: logf.Log}) Expect(err).NotTo(HaveOccurred()) }) @@ -319,9 +319,9 @@ var _ = Describe("filter", func() { hdlr handler.EventHandler ) BeforeEach(func() { - pred, err = annotation.NewTruthyPredicate(annotationKey, annotation.Options{Log: logf.Log}) + pred, err = annotation.NewTruthyPredicate[client.Object](annotationKey, annotation.Options{Log: logf.Log}) Expect(err).NotTo(HaveOccurred()) - hdlr, err = annotation.NewTruthyEventHandler(annotationKey, annotation.Options{Log: logf.Log}) + hdlr, err = annotation.NewTruthyEventHandler[client.Object](annotationKey, annotation.Options{Log: logf.Log}) Expect(err).NotTo(HaveOccurred()) }) diff --git a/predicate/example_test.go b/predicate/example_test.go index f420112..fb167b2 100644 --- a/predicate/example_test.go +++ b/predicate/example_test.go @@ -20,6 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/builder" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/manager/signals" @@ -46,7 +47,7 @@ func ExampleNewPause() { } // Filter out Pods with the "my.app/paused: true" annotation. - pause, err := predicate.NewPause("my.app/paused") + pause, err := predicate.NewPause[client.Object]("my.app/paused") if err != nil { os.Exit(1) } diff --git a/predicate/pause.go b/predicate/pause.go index b008f66..1bd2bf7 100644 --- a/predicate/pause.go +++ b/predicate/pause.go @@ -15,6 +15,7 @@ package predicate import ( + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/predicate" "github.com/operator-framework/operator-lib/internal/annotation" @@ -31,6 +32,6 @@ import ( // a stricter annotation modification policy. See AdmissionReview configuration for user info available // to a webhook: // https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#request -func NewPause(key string) (predicate.Predicate, error) { - return annotation.NewFalsyPredicate(key, annotation.Options{Log: log}) +func NewPause[T client.Object](key string) (predicate.TypedPredicate[T], error) { + return annotation.NewFalsyPredicate[T](key, annotation.Options{Log: log}) }