From 61368ec21c98293a5558dbaededf8706a6a2de2c Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Thu, 20 Jun 2024 13:40:22 -0700 Subject: [PATCH] Update deps Signed-off-by: Tamal Saha --- go.mod | 2 +- go.sum | 4 +- .../client-go/apiextensions/controller.go | 67 +++++++++++++------ vendor/modules.txt | 2 +- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 7be9542bd..7cb610f02 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( k8s.io/klog/v2 v2.120.1 k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f kmodules.xyz/apiversion v0.2.0 - kmodules.xyz/client-go v0.30.6 + kmodules.xyz/client-go v0.30.7 kmodules.xyz/crd-schema-fuzz v0.29.1 kmodules.xyz/go-containerregistry v0.0.12 kmodules.xyz/resource-metrics v0.30.1 diff --git a/go.sum b/go.sum index c4b1a5204..d11203c33 100644 --- a/go.sum +++ b/go.sum @@ -340,8 +340,8 @@ k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCf k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk= kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80= -kmodules.xyz/client-go v0.30.6 h1:TvcN+8Grhj+LUU19nfFKDmg5VnB9NRXkCXF4tZ5+vCM= -kmodules.xyz/client-go v0.30.6/go.mod h1:XL3PDQIXG4s3xNRL2SSxIvi8b2WyMGpn26dFnOBz0j4= +kmodules.xyz/client-go v0.30.7 h1:QcZ3pmyK6YZlqtx1gc8IGK1MyrsapaOW14pc6R7klZA= +kmodules.xyz/client-go v0.30.7/go.mod h1:XL3PDQIXG4s3xNRL2SSxIvi8b2WyMGpn26dFnOBz0j4= kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs= kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE= kmodules.xyz/go-containerregistry v0.0.12 h1:Tl32QGmSqRVm9PUEb/f3dgDeu9zW5fVzt3qmAFIE37I= diff --git a/vendor/kmodules.xyz/client-go/apiextensions/controller.go b/vendor/kmodules.xyz/client-go/apiextensions/controller.go index e7b14507b..b9edf5341 100644 --- a/vendor/kmodules.xyz/client-go/apiextensions/controller.go +++ b/vendor/kmodules.xyz/client-go/apiextensions/controller.go @@ -29,15 +29,20 @@ import ( type ( SetupFn func(ctx context.Context, mgr ctrl.Manager) - TestFn func(*apiextensionsv1.CustomResourceDefinition) (bool, any) + TestFn func(*apiextensionsv1.CustomResourceDefinition) bool ) +type setupGroup struct { + gks []schema.GroupKind + fn SetupFn +} + var ( - setupFns = make(map[schema.GroupKind]SetupFn) - testFns = make(map[schema.GroupKind]TestFn) - setupDone = map[schema.GroupKind]bool{} - ExtraSetupParam = struct{}{} - mu sync.Mutex + setupFns = make(map[schema.GroupKind]setupGroup) + testFns = make(map[schema.GroupKind]TestFn) + setupDone = map[schema.GroupKind]bool{} + CRDParam = struct{}{} + mu sync.Mutex ) type Reconciler struct { @@ -72,18 +77,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if !setupFnExists { return ctrl.Result{}, nil } - - ctxSetup := r.ctx - if test, testFnExists := testFns[gk]; testFnExists { - passed, extra := test(&crd) - if !passed { - return ctrl.Result{}, nil - } - ctxSetup = context.WithValue(r.ctx, ExtraSetupParam, extra) + if !testFns[gk](&crd) { + return ctrl.Result{}, nil } - setup(ctxSetup, r.mgr) - setupDone[gk] = true + ctxSetup := context.WithValue(r.ctx, CRDParam, &crd) + setup.fn(ctxSetup, r.mgr) + + for _, gk := range setup.gks { + setupDone[gk] = true + } return ctrl.Result{}, nil } @@ -97,8 +100,34 @@ func RegisterSetup(gk schema.GroupKind, fn SetupFn, tn ...TestFn) { mu.Lock() defer mu.Unlock() - setupFns[gk] = fn - if len(tn) == 1 { - testFns[gk] = tn[0] + setupFns[gk] = setupGroup{ + gks: []schema.GroupKind{gk}, + fn: fn, + } + testFns[gk] = andTestFn(tn...) +} + +func MultiRegisterSetup(gks []schema.GroupKind, fn SetupFn, tn ...TestFn) { + mu.Lock() + defer mu.Unlock() + + testFN := andTestFn(tn...) + for _, gk := range gks { + setupFns[gk] = setupGroup{ + gks: gks, + fn: fn, + } + testFns[gk] = testFN + } +} + +func andTestFn(fns ...TestFn) TestFn { + return func(crd *apiextensionsv1.CustomResourceDefinition) bool { + for _, fn := range fns { + if !fn(crd) { + return false + } + } + return true } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 8dab3ac69..6119d6199 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -716,7 +716,7 @@ k8s.io/utils/trace # kmodules.xyz/apiversion v0.2.0 ## explicit; go 1.14 kmodules.xyz/apiversion -# kmodules.xyz/client-go v0.30.6 +# kmodules.xyz/client-go v0.30.7 ## explicit; go 1.22.0 kmodules.xyz/client-go kmodules.xyz/client-go/api/v1