Skip to content

Commit 49fa562

Browse files
authored
Merge pull request #42 from xrstf/kcp-1.28
✨ Rebase kcp modifications onto v0.16.2
2 parents 7db81c7 + 769ed77 commit 49fa562

22 files changed

+444
-48
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://[email protected]/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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
approvers:
2+
- davidfestal
3+
- ncdc
4+
- stevekuznetsov
5+
- sttts
6+
reviewers:
7+
- fabianvf
8+
- varshaprasad96

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.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
936936
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
937937
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
938938
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
939+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34 h1:tom0JX5OmAeOOmkGv8LaYHDtA1xAKDiQL5U0vhYYgdM=
940+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34/go.mod h1:cWoaYGHl1nlzdEM2xvMzIASkEZJZLSf5nhe17M7wDhw=
941+
github.com/kcp-dev/logicalcluster/v3 v3.0.4 h1:q7KngML/QM7sWl8aVzmfZF0TPMnBwYNxsPKfwUvvBvU=
942+
github.com/kcp-dev/logicalcluster/v3 v3.0.4/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY=
939943
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
940944
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
941945
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require (
1010
github.com/go-logr/zapr v1.2.4
1111
github.com/google/go-cmp v0.5.9
1212
github.com/google/gofuzz v1.2.0
13+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34
14+
github.com/kcp-dev/logicalcluster/v3 v3.0.4
1315
github.com/onsi/ginkgo/v2 v2.11.0
1416
github.com/onsi/gomega v1.27.10
1517
github.com/prometheus/client_golang v1.16.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
214214
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
215215
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
216216
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
217+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34 h1:tom0JX5OmAeOOmkGv8LaYHDtA1xAKDiQL5U0vhYYgdM=
218+
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0.0.20230926071920-57d168bcbe34/go.mod h1:cWoaYGHl1nlzdEM2xvMzIASkEZJZLSf5nhe17M7wDhw=
219+
github.com/kcp-dev/logicalcluster/v3 v3.0.4 h1:q7KngML/QM7sWl8aVzmfZF0TPMnBwYNxsPKfwUvvBvU=
220+
github.com/kcp-dev/logicalcluster/v3 v3.0.4/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY=
217221
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
218222
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
219223
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

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
corev1 "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/api/meta"
2728
"k8s.io/apimachinery/pkg/fields"
@@ -159,6 +160,14 @@ type Options struct {
159160
// instead of `reconcile.Result{}`.
160161
SyncPeriod *time.Duration
161162

163+
// NewInformerFunc is a function that is used to create SharedIndexInformers.
164+
// Defaults to cache.NewSharedIndexInformer from client-go
165+
NewInformerFunc client.NewInformerFunc
166+
167+
// Indexers is the indexers that the informers will be configured to use.
168+
// Will always have the standard NamespaceIndex.
169+
Indexers toolscache.Indexers
170+
162171
// ReaderFailOnMissingInformer configures the cache to return a ErrResourceNotCached error when a user
163172
// requests, using Get() and List(), a resource the cache does not already have an informer for.
164173
//
@@ -201,9 +210,6 @@ type Options struct {
201210
// ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
202211
// object, this will fall through to Default* settings.
203212
ByObject map[client.Object]ByObject
204-
205-
// newInformer allows overriding of NewSharedIndexInformer for testing.
206-
newInformer *func(toolscache.ListerWatcher, runtime.Object, time.Duration, toolscache.Indexers) toolscache.SharedIndexInformer
207213
}
208214

209215
// ByObject offers more fine-grained control over the cache's ListWatch by object.
@@ -354,7 +360,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
354360
},
355361
Transform: config.Transform,
356362
UnsafeDisableDeepCopy: pointer.BoolDeref(config.UnsafeDisableDeepCopy, false),
357-
NewInformer: opts.newInformer,
363+
NewInformer: opts.NewInformerFunc,
358364
}),
359365
readerFailOnMissingInformer: opts.ReaderFailOnMissingInformer,
360366
}
@@ -438,6 +444,10 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
438444
if opts.SyncPeriod == nil {
439445
opts.SyncPeriod = &defaultSyncPeriod
440446
}
447+
448+
if opts.NewInformerFunc == nil {
449+
opts.NewInformerFunc = informers.NewSharedIndexInformer
450+
}
441451
return opts, nil
442452
}
443453

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")

pkg/cache/informer_cache.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/cache/internal"
3232
"sigs.k8s.io/controller-runtime/pkg/client"
3333
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
34+
35+
"github.com/kcp-dev/logicalcluster/v3"
3436
)
3537

3638
var (
@@ -222,6 +224,13 @@ func indexByField(informer Informer, field string, extractValue client.IndexerFu
222224
}
223225
ns := meta.GetNamespace()
224226

227+
keyFunc := internal.KeyToNamespacedKey
228+
if clusterName := logicalcluster.From(obj); !clusterName.Empty() {
229+
keyFunc = func(ns, val string) string {
230+
return internal.KeyToClusteredKey(clusterName.String(), ns, val)
231+
}
232+
}
233+
225234
rawVals := extractValue(obj)
226235
var vals []string
227236
if ns == "" {
@@ -231,14 +240,15 @@ func indexByField(informer Informer, field string, extractValue client.IndexerFu
231240
// if we need to add non-namespaced versions too, double the length
232241
vals = make([]string, len(rawVals)*2)
233242
}
243+
234244
for i, rawVal := range rawVals {
235245
// save a namespaced variant, so that we can ask
236246
// "what are all the object matching a given index *in a given namespace*"
237-
vals[i] = internal.KeyToNamespacedKey(ns, rawVal)
247+
vals[i] = keyFunc(ns, rawVal)
238248
if ns != "" {
239249
// if we have a namespace, also inject a special index key for listing
240250
// regardless of the object namespace
241-
vals[i+len(rawVals)] = internal.KeyToNamespacedKey("", rawVal)
251+
vals[i+len(rawVals)] = keyFunc("", rawVal)
242252
}
243253
}
244254

pkg/cache/internal/cache_reader.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"reflect"
2323

24+
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
25+
2426
apierrors "k8s.io/apimachinery/pkg/api/errors"
2527
apimeta "k8s.io/apimachinery/pkg/api/meta"
2628
"k8s.io/apimachinery/pkg/labels"
@@ -30,6 +32,7 @@ import (
3032

3133
"sigs.k8s.io/controller-runtime/pkg/client"
3234
"sigs.k8s.io/controller-runtime/pkg/internal/field/selector"
35+
"sigs.k8s.io/controller-runtime/pkg/kontext"
3336
)
3437

3538
// CacheReader is a client.Reader.
@@ -53,11 +56,11 @@ type CacheReader struct {
5356
}
5457

5558
// Get checks the indexer for the object and writes a copy of it if found.
56-
func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Object, _ ...client.GetOption) error {
59+
func (c *CacheReader) Get(ctx context.Context, key client.ObjectKey, out client.Object, _ ...client.GetOption) error {
5760
if c.scopeName == apimeta.RESTScopeNameRoot {
5861
key.Namespace = ""
5962
}
60-
storeKey := objectKeyToStoreKey(key)
63+
storeKey := objectKeyToStoreKey(ctx, key)
6164

6265
// Lookup the object from the indexer cache
6366
obj, exists, err := c.indexer.GetByKey(storeKey)
@@ -104,7 +107,7 @@ func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Ob
104107
}
105108

106109
// List lists items out of the indexer and writes them to out.
107-
func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...client.ListOption) error {
110+
func (c *CacheReader) List(ctx context.Context, out client.ObjectList, opts ...client.ListOption) error {
108111
var objs []interface{}
109112
var err error
110113

@@ -115,6 +118,8 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
115118
return fmt.Errorf("continue list option is not supported by the cache")
116119
}
117120

121+
clusterName, _ := kontext.ClusterFrom(ctx)
122+
118123
switch {
119124
case listOpts.FieldSelector != nil:
120125
// TODO(directxman12): support more complicated field selectors by
@@ -126,11 +131,23 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
126131
// list all objects by the field selector. If this is namespaced and we have one, ask for the
127132
// namespaced index key. Otherwise, ask for the non-namespaced variant by using the fake "all namespaces"
128133
// namespace.
129-
objs, err = c.indexer.ByIndex(FieldIndexName(field), KeyToNamespacedKey(listOpts.Namespace, val))
134+
if clusterName.Empty() {
135+
objs, err = c.indexer.ByIndex(FieldIndexName(field), KeyToNamespacedKey(listOpts.Namespace, val))
136+
} else {
137+
objs, err = c.indexer.ByIndex(FieldIndexName(field), KeyToClusteredKey(clusterName.String(), listOpts.Namespace, val))
138+
}
130139
case listOpts.Namespace != "":
131-
objs, err = c.indexer.ByIndex(cache.NamespaceIndex, listOpts.Namespace)
140+
if clusterName.Empty() {
141+
objs, err = c.indexer.ByIndex(cache.NamespaceIndex, listOpts.Namespace)
142+
} else {
143+
objs, err = c.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ClusterAndNamespaceIndexKey(clusterName, listOpts.Namespace))
144+
}
132145
default:
133-
objs = c.indexer.List()
146+
if clusterName.Empty() {
147+
objs = c.indexer.List()
148+
} else {
149+
objs, err = c.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ClusterIndexKey(clusterName))
150+
}
134151
}
135152
if err != nil {
136153
return err
@@ -182,7 +199,12 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
182199
// It's akin to MetaNamespaceKeyFunc. It's separate from
183200
// String to allow keeping the key format easily in sync with
184201
// MetaNamespaceKeyFunc.
185-
func objectKeyToStoreKey(k client.ObjectKey) string {
202+
func objectKeyToStoreKey(ctx context.Context, k client.ObjectKey) string {
203+
cluster, ok := kontext.ClusterFrom(ctx)
204+
if ok {
205+
return kcpcache.ToClusterAwareKey(cluster.String(), k.Namespace, k.Name)
206+
}
207+
186208
if k.Namespace == "" {
187209
return k.Name
188210
}
@@ -206,3 +228,9 @@ func KeyToNamespacedKey(ns string, baseKey string) string {
206228
}
207229
return allNamespacesNamespace + "/" + baseKey
208230
}
231+
232+
// KeyToClusteredKey prefixes the given index key with a cluster name
233+
// for use in field selector indexes.
234+
func KeyToClusteredKey(clusterName string, ns string, baseKey string) string {
235+
return clusterName + "/" + KeyToNamespacedKey(ns, baseKey)
236+
}

pkg/cache/internal/informers.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"sync"
2525
"time"
2626

27+
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
28+
"github.com/kcp-dev/apimachinery/v2/third_party/informers"
2729
apierrors "k8s.io/apimachinery/pkg/api/errors"
2830
"k8s.io/apimachinery/pkg/api/meta"
2931
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -45,17 +47,17 @@ type InformersOpts struct {
4547
Mapper meta.RESTMapper
4648
ResyncPeriod time.Duration
4749
Namespace string
48-
NewInformer *func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer
50+
NewInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) kcpcache.ScopeableSharedIndexInformer
4951
Selector Selector
5052
Transform cache.TransformFunc
5153
UnsafeDisableDeepCopy bool
5254
}
5355

5456
// NewInformers creates a new InformersMap that can create informers under the hood.
5557
func NewInformers(config *rest.Config, options *InformersOpts) *Informers {
56-
newInformer := cache.NewSharedIndexInformer
58+
newInformer := informers.NewSharedIndexInformer
5759
if options.NewInformer != nil {
58-
newInformer = *options.NewInformer
60+
newInformer = options.NewInformer
5961
}
6062
return &Informers{
6163
config: config,
@@ -158,7 +160,7 @@ type Informers struct {
158160
unsafeDisableDeepCopy bool
159161

160162
// NewInformer allows overriding of the shared index informer constructor for testing.
161-
newInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer
163+
newInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) kcpcache.ScopeableSharedIndexInformer
162164
}
163165

164166
// Start calls Run on each of the informers and sets started to true. Blocks on the context.

pkg/client/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ type CacheOptions struct {
8989
// NewClientFunc allows a user to define how to create a client.
9090
type NewClientFunc func(config *rest.Config, options Options) (Client, error)
9191

92+
// NewAPIReaderFunc allows a user to define how to create an API server reader.
93+
type NewAPIReaderFunc func(config *rest.Config, options Options) (Reader, error)
94+
95+
// NewAPIReader creates a new API server reader.
96+
func NewAPIReader(config *rest.Config, options Options) (Reader, error) {
97+
return New(config, options)
98+
}
99+
92100
// New returns a new Client using the provided config and Options.
93101
// The returned client reads *and* writes directly from the server
94102
// (it doesn't use object caches). It understands how to work with

pkg/client/interfaces.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ package client
1818

1919
import (
2020
"context"
21+
"time"
2122

23+
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
2224
apierrors "k8s.io/apimachinery/pkg/api/errors"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
26+
"k8s.io/client-go/tools/cache"
2427

2528
"k8s.io/apimachinery/pkg/api/meta"
2629
"k8s.io/apimachinery/pkg/runtime"
@@ -44,6 +47,10 @@ type Patch interface {
4447
Data(obj Object) ([]byte, error)
4548
}
4649

50+
// NewInformerFunc describes a function that creates SharedIndexInformers.
51+
// Its signature matches cache.NewSharedIndexInformer from client-go.
52+
type NewInformerFunc func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) kcpcache.ScopeableSharedIndexInformer
53+
4754
// TODO(directxman12): is there a sane way to deal with get/delete options?
4855

4956
// Reader knows how to read and list Kubernetes objects.

pkg/cluster/cluster.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ type Options struct {
121121
// By default, the client will use the cache for reads and direct calls for writes.
122122
Client client.Options
123123

124+
// NewAPIReaderFunc is the function that creates the APIReader client to be
125+
// used by the manager. If not set this will use the default new APIReader
126+
// function.
127+
NewAPIReader client.NewAPIReaderFunc
128+
124129
// NewClient is the func that creates the client to be used by the manager.
125130
// If not set this will create a Client backed by a Cache for read operations
126131
// and a direct Client for write operations.
@@ -230,7 +235,7 @@ func New(config *rest.Config, opts ...Option) (Cluster, error) {
230235
}
231236

232237
// Create the API Reader, a client with no cache.
233-
clientReader, err := client.New(config, client.Options{
238+
clientReader, err := options.NewAPIReader(config, client.Options{
234239
HTTPClient: options.HTTPClient,
235240
Scheme: options.Scheme,
236241
Mapper: mapper,
@@ -280,6 +285,10 @@ func setOptionsDefaults(options Options, config *rest.Config) (Options, error) {
280285
options.MapperProvider = apiutil.NewDynamicRESTMapper
281286
}
282287

288+
if options.NewAPIReader == nil {
289+
options.NewAPIReader = client.NewAPIReader
290+
}
291+
283292
// Allow users to define how to create a new client
284293
if options.NewClient == nil {
285294
options.NewClient = client.New

0 commit comments

Comments
 (0)