Skip to content

Commit 5e7c0a7

Browse files
xrstfsttts
authored andcommitted
UPSTREAM: <carry>: kcp modifications
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
1 parent d0396a3 commit 5e7c0a7

File tree

23 files changed

+451
-50
lines changed

23 files changed

+451
-50
lines changed

.prow.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
presubmits:
2+
- name: pull-controller-runtime-everything
3+
always_run: true
4+
decorate: true
5+
clone_uri: "ssh://git@github.com/kcp-dev/controller-runtime.git"
6+
labels:
7+
preset-goproxy: "true"
8+
spec:
9+
containers:
10+
- image: ghcr.io/kcp-dev/infra/build:1.20.9-1
11+
command:
12+
- make
13+
- test

DOWNSTREAM_OWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
approvers:
2+
- sttts
3+
- xrstf
4+
- mjudeikis
5+
- embik

DOWNSTREAM_OWNERS_ALIASES

Whitespace-only changes.

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ $(GO_APIDIFF): $(TOOLS_DIR)/go.mod # Build go-apidiff from tools folder.
7373
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
7474
cd $(TOOLS_DIR) && go build -tags=tools -o bin/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
7575

76-
$(GOLANGCI_LINT): .github/workflows/golangci-lint.yml # Download golanci-lint using hack script into tools folder.
77-
hack/ensure-golangci-lint.sh \
78-
-b $(TOOLS_BIN_DIR) \
79-
$(shell cat .github/workflows/golangci-lint.yml | grep "version: v" | sed 's/.*version: //')
76+
$(GOLANGCI_LINT): .github/workflows/golangci-lint.yml # Download golangci-lint using hack script into tools folder.
77+
GOBIN=$(abspath $(TOOLS_BIN_DIR)) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(shell cat .github/workflows/golangci-lint.yml | grep "version: v" | sed 's/.*version: //')
78+
79+
.PHONY: tools
80+
tools: $(GO_APIDIFF) $(CONTROLLER_GEN) $(GOLANGCI_LINT)
8081

8182
## --------------------------------------
8283
## Linting

examples/scratch-env/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ require (
3232
github.com/imdario/mergo v0.3.6 // indirect
3333
github.com/josharian/intern v1.0.0 // indirect
3434
github.com/json-iterator/go v1.1.12 // indirect
35+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34 // indirect
36+
github.com/kcp-dev/logicalcluster/v3 v3.0.4 // indirect
3537
github.com/mailru/easyjson v0.7.7 // indirect
3638
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
3739
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect

examples/scratch-env/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
5454
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
5555
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
5656
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
57+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34 h1:tom0JX5OmAeOOmkGv8LaYHDtA1xAKDiQL5U0vhYYgdM=
58+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34/go.mod h1:cWoaYGHl1nlzdEM2xvMzIASkEZJZLSf5nhe17M7wDhw=
59+
github.com/kcp-dev/logicalcluster/v3 v3.0.4 h1:q7KngML/QM7sWl8aVzmfZF0TPMnBwYNxsPKfwUvvBvU=
60+
github.com/kcp-dev/logicalcluster/v3 v3.0.4/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY=
5761
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
5862
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
5963
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ require (
1212
github.com/go-logr/zapr v1.3.0
1313
github.com/google/go-cmp v0.6.0
1414
github.com/google/gofuzz v1.2.0
15+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34
16+
github.com/kcp-dev/logicalcluster/v3 v3.0.4
1517
github.com/onsi/ginkgo/v2 v2.14.0
1618
github.com/onsi/gomega v1.30.0
1719
github.com/prometheus/client_golang v1.18.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
7575
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
7676
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
7777
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
78+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34 h1:tom0JX5OmAeOOmkGv8LaYHDtA1xAKDiQL5U0vhYYgdM=
79+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34/go.mod h1:cWoaYGHl1nlzdEM2xvMzIASkEZJZLSf5nhe17M7wDhw=
80+
github.com/kcp-dev/logicalcluster/v3 v3.0.4 h1:q7KngML/QM7sWl8aVzmfZF0TPMnBwYNxsPKfwUvvBvU=
81+
github.com/kcp-dev/logicalcluster/v3 v3.0.4/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY=
7882
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
7983
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
8084
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=

pkg/cache/cache.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/http"
2323
"time"
2424

25+
"github.com/kcp-dev/apimachinery/v2/third_party/informers"
2526
"golang.org/x/exp/maps"
2627
corev1 "k8s.io/api/core/v1"
2728
"k8s.io/apimachinery/pkg/api/meta"
@@ -170,6 +171,14 @@ type Options struct {
170171
// instead of `reconcile.Result{}`.
171172
SyncPeriod *time.Duration
172173

174+
// NewInformerFunc is a function that is used to create SharedIndexInformers.
175+
// Defaults to cache.NewSharedIndexInformer from client-go
176+
NewInformerFunc client.NewInformerFunc
177+
178+
// Indexers is the indexers that the informers will be configured to use.
179+
// Will always have the standard NamespaceIndex.
180+
Indexers toolscache.Indexers
181+
173182
// ReaderFailOnMissingInformer configures the cache to return a ErrResourceNotCached error when a user
174183
// requests, using Get() and List(), a resource the cache does not already have an informer for.
175184
//
@@ -223,9 +232,6 @@ type Options struct {
223232
// ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
224233
// object, this will fall through to Default* settings.
225234
ByObject map[client.Object]ByObject
226-
227-
// newInformer allows overriding of NewSharedIndexInformer for testing.
228-
newInformer *func(toolscache.ListerWatcher, runtime.Object, time.Duration, toolscache.Indexers) toolscache.SharedIndexInformer
229235
}
230236

231237
// ByObject offers more fine-grained control over the cache's ListWatch by object.
@@ -382,7 +388,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
382388
Transform: config.Transform,
383389
WatchErrorHandler: opts.DefaultWatchErrorHandler,
384390
UnsafeDisableDeepCopy: ptr.Deref(config.UnsafeDisableDeepCopy, false),
385-
NewInformer: opts.newInformer,
391+
NewInformer: opts.NewInformerFunc,
386392
}),
387393
readerFailOnMissingInformer: opts.ReaderFailOnMissingInformer,
388394
}
@@ -478,6 +484,10 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
478484
if opts.SyncPeriod == nil {
479485
opts.SyncPeriod = &defaultSyncPeriod
480486
}
487+
488+
if opts.NewInformerFunc == nil {
489+
opts.NewInformerFunc = informers.NewSharedIndexInformer
490+
}
481491
return opts, nil
482492
}
483493

pkg/cache/cache_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strings"
2727
"time"
2828

29+
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
2930
. "github.com/onsi/ginkgo/v2"
3031
. "github.com/onsi/gomega"
3132
corev1 "k8s.io/api/core/v1"
@@ -545,13 +546,13 @@ func NonBlockingGetTest(createCacheFunc func(config *rest.Config, opts cache.Opt
545546

546547
By("creating the informer cache")
547548
v := reflect.ValueOf(&opts).Elem()
548-
newInformerField := v.FieldByName("newInformer")
549-
newFakeInformer := func(_ kcache.ListerWatcher, _ runtime.Object, _ time.Duration, _ kcache.Indexers) kcache.SharedIndexInformer {
549+
newInformerField := v.FieldByName("NewInformerFunc")
550+
newFakeInformer := func(_ kcache.ListerWatcher, _ runtime.Object, _ time.Duration, _ kcache.Indexers) kcpcache.ScopeableSharedIndexInformer {
550551
return &controllertest.FakeInformer{Synced: false}
551552
}
552553
reflect.NewAt(newInformerField.Type(), newInformerField.Addr().UnsafePointer()).
553554
Elem().
554-
Set(reflect.ValueOf(&newFakeInformer))
555+
Set(reflect.ValueOf(newFakeInformer))
555556
informerCache, err = createCacheFunc(cfg, opts)
556557
Expect(err).NotTo(HaveOccurred())
557558
By("running the cache and waiting for it to sync")

0 commit comments

Comments
 (0)