From b6b2f1abee30841f03c8939b09d869db6f74e7ce Mon Sep 17 00:00:00 2001 From: Todd Short Date: Wed, 28 Aug 2024 07:55:33 -0400 Subject: [PATCH] :seedling: bump kube to 0.31.0, controller-runtime to v0.19.0, and fix generics issues (#192) Signed-off-by: Per Goncalves da Silva Co-authored-by: Per Goncalves da Silva --- Makefile | 4 +- go.mod | 19 +++++---- go.sum | 44 ++++++++++++--------- handler/enqueue_annotation.go | 10 ++--- handler/enqueue_annotation_test.go | 4 +- handler/instrumented_enqueue_object.go | 7 ++-- handler/instrumented_enqueue_object_test.go | 4 +- handler/pause.go | 3 +- internal/annotation/filter.go | 21 +++++----- internal/annotation/filter_test.go | 8 ++-- 10 files changed, 68 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 25ed899..6898cbb 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,10 @@ include .bingo/Variables.mk build: $(SOURCES) ## Build Test go build -ldflags="-s -w" ./... -lint: golangci-lint ## Run golangci-lint +lint: $(GOLANGCI_LINT) ## Run golangci-lint @$(GOLANGCI_LINT) run -lint-fix: golangci-lint ## Run golangci lint to automatically perform fixes +lint-fix: $(GOLANGCI_LINT) ## Run golangci lint to automatically perform fixes @$(GOLANGCI_LINT) run --fix fmt: ## Run go fmt diff --git a/go.mod b/go.mod index 9729035..d15d101 100644 --- a/go.mod +++ b/go.mod @@ -9,21 +9,22 @@ require ( github.com/operator-framework/api v0.26.0 github.com/prometheus/client_golang v1.20.1 github.com/prometheus/client_model v0.6.1 - k8s.io/api v0.30.1 - k8s.io/apimachinery v0.30.1 - k8s.io/client-go v0.30.1 - k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 - sigs.k8s.io/controller-runtime v0.18.4 + k8s.io/api v0.31.0 + k8s.io/apimachinery v0.31.0 + k8s.io/client-go v0.31.0 + k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 + sigs.k8s.io/controller-runtime v0.19.0 ) require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // 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.9.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-openapi/jsonpointer v0.20.2 // indirect github.com/go-openapi/jsonreference v0.20.4 // indirect github.com/go-openapi/swag v0.22.9 // indirect @@ -48,6 +49,7 @@ require ( github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/x448/float16 v0.8.4 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect @@ -58,11 +60,12 @@ require ( golang.org/x/tools v0.24.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect 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.30.1 // indirect - k8s.io/klog/v2 v2.120.1 // indirect + k8s.io/apiextensions-apiserver v0.31.0 // indirect + k8s.io/klog/v2 v2.130.1 // 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 diff --git a/go.sum b/go.sum index db30eb5..8c99008 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,9 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/go-restful/v3 v3.11.2 h1:1onLa9DcsMYO9P+CXaL0dStDqQ2EHHXLiz+BtnqkLAU= 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= @@ -13,6 +14,8 @@ github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0 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/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= @@ -76,8 +79,9 @@ github.com/operator-framework/api v0.26.0 h1:YVntU2NkVl5zSLLwK5kFcH6P3oSvN9QDgTs github.com/operator-framework/api v0.26.0/go.mod h1:3IxOwzVUeGxYlzfwKCcfCyS+q3EEhWA/4kv7UehbeyM= 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= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.20.1 h1:IMJXHOD6eARkQpxo8KkhgEVFlBNm+nkrFUyGlIu7Na8= github.com/prometheus/client_golang v1.20.1/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= @@ -86,14 +90,16 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -150,6 +156,8 @@ google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWn gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -157,22 +165,22 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 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.30.1 h1:kCm/6mADMdbAxmIh0LBjS54nQBE+U4KmbCfIkF5CpJY= -k8s.io/api v0.30.1/go.mod h1:ddbN2C0+0DIiPntan/bye3SW3PdwLa11/0yqwvuRrJM= -k8s.io/apiextensions-apiserver v0.30.1 h1:4fAJZ9985BmpJG6PkoxVRpXv9vmPUOVzl614xarePws= -k8s.io/apiextensions-apiserver v0.30.1/go.mod h1:R4GuSrlhgq43oRY9sF2IToFh7PVlF1JjfWdoG3pixk4= -k8s.io/apimachinery v0.30.1 h1:ZQStsEfo4n65yAdlGTfP/uSHMQSoYzU/oeEbkmF7P2U= -k8s.io/apimachinery v0.30.1/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= -k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q= -k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc= -k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= -k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= +k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= +k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= +k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= +k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= +k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8= +k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= 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.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw= -sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg= +k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= +k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= +sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= 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 3b32074..4791781 100644 --- a/handler/enqueue_annotation.go +++ b/handler/enqueue_annotation.go @@ -85,17 +85,17 @@ type EnqueueRequestForAnnotation[T client.Object] struct { Type schema.GroupKind } -var _ crtHandler.EventHandler = &EnqueueRequestForAnnotation[client.Object]{} +var _ crtHandler.TypedEventHandler[client.Object, reconcile.Request] = &EnqueueRequestForAnnotation[client.Object]{} // Create implements EventHandler -func (e *EnqueueRequestForAnnotation[T]) Create(_ context.Context, evt event.TypedCreateEvent[T], q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Create(_ context.Context, evt event.TypedCreateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if ok, req := e.getAnnotationRequests(evt.Object); ok { q.Add(req) } } // Update implements EventHandler -func (e *EnqueueRequestForAnnotation[T]) Update(_ context.Context, evt event.TypedUpdateEvent[T], q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Update(_ context.Context, evt event.TypedUpdateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if ok, req := e.getAnnotationRequests(evt.ObjectOld); ok { q.Add(req) } @@ -105,14 +105,14 @@ func (e *EnqueueRequestForAnnotation[T]) Update(_ context.Context, evt event.Typ } // Delete implements EventHandler -func (e *EnqueueRequestForAnnotation[T]) Delete(_ context.Context, evt event.TypedDeleteEvent[T], q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Delete(_ context.Context, evt event.TypedDeleteEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if ok, req := e.getAnnotationRequests(evt.Object); ok { q.Add(req) } } // Generic implements EventHandler -func (e *EnqueueRequestForAnnotation[T]) Generic(_ context.Context, evt event.TypedGenericEvent[T], q workqueue.RateLimitingInterface) { +func (e *EnqueueRequestForAnnotation[T]) Generic(_ context.Context, evt event.TypedGenericEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if ok, req := e.getAnnotationRequests(evt.Object); ok { q.Add(req) } diff --git a/handler/enqueue_annotation_test.go b/handler/enqueue_annotation_test.go index cc0027c..086262b 100644 --- a/handler/enqueue_annotation_test.go +++ b/handler/enqueue_annotation_test.go @@ -35,13 +35,13 @@ import ( var _ = Describe("EnqueueRequestForAnnotation", func() { ctx := context.TODO() - var q workqueue.RateLimitingInterface + var q workqueue.TypedRateLimitingInterface[reconcile.Request] var instance EnqueueRequestForAnnotation[client.Object] var pod *corev1.Pod var podOwner *corev1.Pod BeforeEach(func() { - q = &controllertest.Queue{Interface: workqueue.New()} + q = &controllertest.Queue{TypedInterface: workqueue.NewTyped[reconcile.Request]()} pod = &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Namespace: "biz", diff --git a/handler/instrumented_enqueue_object.go b/handler/instrumented_enqueue_object.go index 6e351a3..e79233b 100644 --- a/handler/instrumented_enqueue_object.go +++ b/handler/instrumented_enqueue_object.go @@ -21,6 +21,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/operator-framework/operator-lib/handler/internal/metrics" ) @@ -41,13 +42,13 @@ type InstrumentedEnqueueRequestForObject[T client.Object] struct { } // Create implements EventHandler, and creates the metrics. -func (h InstrumentedEnqueueRequestForObject[T]) Create(ctx context.Context, e event.TypedCreateEvent[T], q workqueue.RateLimitingInterface) { +func (h InstrumentedEnqueueRequestForObject[T]) Create(ctx context.Context, e event.TypedCreateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { setResourceMetric(e.Object) h.TypedEnqueueRequestForObject.Create(ctx, e, q) } // Update implements EventHandler, and updates the metrics. -func (h InstrumentedEnqueueRequestForObject[T]) Update(ctx context.Context, e event.TypedUpdateEvent[T], q workqueue.RateLimitingInterface) { +func (h InstrumentedEnqueueRequestForObject[T]) Update(ctx context.Context, e event.TypedUpdateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { setResourceMetric(e.ObjectOld) setResourceMetric(e.ObjectNew) @@ -55,7 +56,7 @@ func (h InstrumentedEnqueueRequestForObject[T]) Update(ctx context.Context, e ev } // Delete implements EventHandler, and deletes metrics. -func (h InstrumentedEnqueueRequestForObject[T]) Delete(ctx context.Context, e event.TypedDeleteEvent[T], q workqueue.RateLimitingInterface) { +func (h InstrumentedEnqueueRequestForObject[T]) Delete(ctx context.Context, e event.TypedDeleteEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { deleteResourceMetric(e.Object) h.TypedEnqueueRequestForObject.Delete(ctx, e, q) } diff --git a/handler/instrumented_enqueue_object_test.go b/handler/instrumented_enqueue_object_test.go index dcc7464..e9e0fec 100644 --- a/handler/instrumented_enqueue_object_test.go +++ b/handler/instrumented_enqueue_object_test.go @@ -36,7 +36,7 @@ import ( var _ = Describe("InstrumentedEnqueueRequestForObject", func() { ctx := context.TODO() - var q workqueue.RateLimitingInterface + var q workqueue.TypedRateLimitingInterface[reconcile.Request] var instance InstrumentedEnqueueRequestForObject[client.Object] var pod *corev1.Pod @@ -44,7 +44,7 @@ var _ = Describe("InstrumentedEnqueueRequestForObject", func() { registry.MustRegister(metrics.ResourceCreatedAt) BeforeEach(func() { - q = &controllertest.Queue{Interface: workqueue.New()} + q = &controllertest.Queue{TypedInterface: workqueue.NewTyped[reconcile.Request]()} instance = InstrumentedEnqueueRequestForObject[client.Object]{} pod = &corev1.Pod{ TypeMeta: metav1.TypeMeta{ diff --git a/handler/pause.go b/handler/pause.go index aee2338..925f808 100644 --- a/handler/pause.go +++ b/handler/pause.go @@ -17,6 +17,7 @@ package handler import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/operator-framework/operator-lib/internal/annotation" ) @@ -32,6 +33,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[T client.Object](key string) (handler.TypedEventHandler[T], error) { +func NewPause[T client.Object](key string) (handler.TypedEventHandler[T, reconcile.Request], error) { return annotation.NewFalsyEventHandler[T](key, annotation.Options{Log: log}) } diff --git a/internal/annotation/filter.go b/internal/annotation/filter.go index c6257b7..6eab4d2 100644 --- a/internal/annotation/filter.go +++ b/internal/annotation/filter.go @@ -35,6 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" + "sigs.k8s.io/controller-runtime/pkg/reconcile" ) // Options configures a filter. @@ -54,7 +55,7 @@ func NewFalsyPredicate[T client.Object](key string, opts Options) (predicate.Typ // NewFalsyEventHandler returns an event handler that enqueues objects // that do not have annotation with key string key or whose value is falsy. -func NewFalsyEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T], error) { +func NewFalsyEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T, reconcile.Request], error) { opts.truthy = false return newEventHandler[T](key, opts) } @@ -68,7 +69,7 @@ func NewTruthyPredicate[T client.Object](key string, opts Options) (predicate.Ty // NewTruthyEventHandler returns an event handler that enqueues objects // that do have annotation with key string key and whose value is truthy. -func NewTruthyEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T], error) { +func NewTruthyEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T, reconcile.Request], error) { opts.truthy = true return newEventHandler[T](key, opts) } @@ -80,30 +81,30 @@ func defaultOptions(opts *Options) { } // newEventHandler returns a filter for use as an event handler. -func newEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T], error) { +func newEventHandler[T client.Object](key string, opts Options) (handler.TypedEventHandler[T, reconcile.Request], error) { f, err := newFilter[T](key, opts) if err != nil { return nil, err } f.hdlr = &handler.TypedEnqueueRequestForObject[T]{} - return handler.TypedFuncs[T]{ - CreateFunc: func(ctx context.Context, evt event.TypedCreateEvent[T], q workqueue.RateLimitingInterface) { + return handler.TypedFuncs[T, reconcile.Request]{ + CreateFunc: func(ctx context.Context, evt event.TypedCreateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if f.Create(evt) { f.hdlr.Create(ctx, evt, q) } }, - UpdateFunc: func(ctx context.Context, evt event.TypedUpdateEvent[T], q workqueue.RateLimitingInterface) { + UpdateFunc: func(ctx context.Context, evt event.TypedUpdateEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if f.Update(evt) { f.hdlr.Update(ctx, evt, q) } }, - DeleteFunc: func(ctx context.Context, evt event.TypedDeleteEvent[T], q workqueue.RateLimitingInterface) { + DeleteFunc: func(ctx context.Context, evt event.TypedDeleteEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if f.Delete(evt) { f.hdlr.Delete(ctx, evt, q) } }, - GenericFunc: func(ctx context.Context, evt event.TypedGenericEvent[T], q workqueue.RateLimitingInterface) { + GenericFunc: func(ctx context.Context, evt event.TypedGenericEvent[T], q workqueue.TypedRateLimitingInterface[reconcile.Request]) { if f.Generic(evt) { f.hdlr.Generic(ctx, evt, q) } @@ -149,9 +150,7 @@ type filter[T client.Object] struct { 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) - } + f.log.Error(nil, "CreateEvent received with no object", "event", evt) return f.ret } return f.run(obj) diff --git a/internal/annotation/filter_test.go b/internal/annotation/filter_test.go index b221c3a..c3bb7ba 100644 --- a/internal/annotation/filter_test.go +++ b/internal/annotation/filter_test.go @@ -38,11 +38,11 @@ var _ = Describe("filter", func() { var ( ctx = context.TODO() err error - q workqueue.RateLimitingInterface + q workqueue.TypedRateLimitingInterface[reconcile.Request] pod *corev1.Pod ) BeforeEach(func() { - q = &controllertest.Queue{Interface: workqueue.New()} + q = &controllertest.Queue{TypedInterface: workqueue.NewTyped[reconcile.Request]()} pod = &corev1.Pod{} pod.SetName("foo") @@ -577,7 +577,7 @@ var _ = Describe("filter", func() { }) -func verifyQueueHasPod(q workqueue.RateLimitingInterface, pod *corev1.Pod) { +func verifyQueueHasPod(q workqueue.TypedRateLimitingInterface[reconcile.Request], pod *corev1.Pod) { ExpectWithOffset(1, q.Len()).To(Equal(1)) i, _ := q.Get() ExpectWithOffset(1, i).To(Equal(reconcile.Request{ @@ -585,6 +585,6 @@ func verifyQueueHasPod(q workqueue.RateLimitingInterface, pod *corev1.Pod) { })) } -func verifyQueueEmpty(q workqueue.RateLimitingInterface) { +func verifyQueueEmpty(q workqueue.TypedRateLimitingInterface[reconcile.Request]) { ExpectWithOffset(1, q.Len()).To(Equal(0)) }