Skip to content

Commit

Permalink
Update deps
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Jun 20, 2024
1 parent 3f7bd1f commit 61368ec
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
67 changes: 48 additions & 19 deletions vendor/kmodules.xyz/client-go/apiextensions/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61368ec

Please sign in to comment.