Skip to content

Commit e8b4ff6

Browse files
authored
Merge pull request #48 from sttts/sttts-kcp-0.17-rebase
✨ Rebase to v0.17.2
2 parents d0396a3 + cae0049 commit e8b4ff6

25 files changed

+454
-53
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ jobs:
2222
- name: golangci-lint
2323
uses: golangci/golangci-lint-action@v3
2424
with:
25-
version: v1.54.0
25+
version: v1.56.2
2626
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ linters:
1212
- errorlint
1313
- exhaustive
1414
- exportloopref
15-
- ginkgolinter
16-
- goconst
15+
# - ginkgolinter
16+
# - goconst
1717
- gocritic
1818
- gocyclo
1919
- gofmt

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

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 (
@@ -233,6 +235,13 @@ func indexByField(informer Informer, field string, extractValue client.IndexerFu
233235
}
234236
ns := meta.GetNamespace()
235237

238+
keyFunc := internal.KeyToNamespacedKey
239+
if clusterName := logicalcluster.From(obj); !clusterName.Empty() {
240+
keyFunc = func(ns, val string) string {
241+
return internal.KeyToClusteredKey(clusterName.String(), ns, val)
242+
}
243+
}
244+
236245
rawVals := extractValue(obj)
237246
var vals []string
238247
if ns == "" {
@@ -242,14 +251,15 @@ func indexByField(informer Informer, field string, extractValue client.IndexerFu
242251
// if we need to add non-namespaced versions too, double the length
243252
vals = make([]string, len(rawVals)*2)
244253
}
254+
245255
for i, rawVal := range rawVals {
246256
// save a namespaced variant, so that we can ask
247257
// "what are all the object matching a given index *in a given namespace*"
248-
vals[i] = internal.KeyToNamespacedKey(ns, rawVal)
258+
vals[i] = keyFunc(ns, rawVal)
249259
if ns != "" {
250260
// if we have a namespace, also inject a special index key for listing
251261
// regardless of the object namespace
252-
vals[i+len(rawVals)] = internal.KeyToNamespacedKey("", rawVal)
262+
vals[i+len(rawVals)] = keyFunc("", rawVal)
253263
}
254264
}
255265

pkg/cache/internal/cache_reader.go

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

24+
kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
25+
"github.com/kcp-dev/logicalcluster/v3"
26+
2427
apierrors "k8s.io/apimachinery/pkg/api/errors"
2528
apimeta "k8s.io/apimachinery/pkg/api/meta"
2629
"k8s.io/apimachinery/pkg/fields"
@@ -31,6 +34,7 @@ import (
3134

3235
"sigs.k8s.io/controller-runtime/pkg/client"
3336
"sigs.k8s.io/controller-runtime/pkg/internal/field/selector"
37+
"sigs.k8s.io/controller-runtime/pkg/kontext"
3438
)
3539

3640
// CacheReader is a client.Reader.
@@ -54,11 +58,11 @@ type CacheReader struct {
5458
}
5559

5660
// Get checks the indexer for the object and writes a copy of it if found.
57-
func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Object, _ ...client.GetOption) error {
61+
func (c *CacheReader) Get(ctx context.Context, key client.ObjectKey, out client.Object, _ ...client.GetOption) error {
5862
if c.scopeName == apimeta.RESTScopeNameRoot {
5963
key.Namespace = ""
6064
}
61-
storeKey := objectKeyToStoreKey(key)
65+
storeKey := objectKeyToStoreKey(ctx, key)
6266

6367
// Lookup the object from the indexer cache
6468
obj, exists, err := c.indexer.GetByKey(storeKey)
@@ -105,7 +109,7 @@ func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Ob
105109
}
106110

107111
// List lists items out of the indexer and writes them to out.
108-
func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...client.ListOption) error {
112+
func (c *CacheReader) List(ctx context.Context, out client.ObjectList, opts ...client.ListOption) error {
109113
var objs []interface{}
110114
var err error
111115

@@ -116,6 +120,8 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
116120
return fmt.Errorf("continue list option is not supported by the cache")
117121
}
118122

123+
clusterName, _ := kontext.ClusterFrom(ctx)
124+
119125
switch {
120126
case listOpts.FieldSelector != nil:
121127
requiresExact := selector.RequiresExactMatch(listOpts.FieldSelector)
@@ -125,11 +131,19 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
125131
// list all objects by the field selector. If this is namespaced and we have one, ask for the
126132
// namespaced index key. Otherwise, ask for the non-namespaced variant by using the fake "all namespaces"
127133
// namespace.
128-
objs, err = byIndexes(c.indexer, listOpts.FieldSelector.Requirements(), listOpts.Namespace)
134+
objs, err = byIndexes(c.indexer, listOpts.FieldSelector.Requirements(), clusterName, listOpts.Namespace)
129135
case listOpts.Namespace != "":
130-
objs, err = c.indexer.ByIndex(cache.NamespaceIndex, listOpts.Namespace)
136+
if clusterName.Empty() {
137+
objs, err = c.indexer.ByIndex(cache.NamespaceIndex, listOpts.Namespace)
138+
} else {
139+
objs, err = c.indexer.ByIndex(kcpcache.ClusterAndNamespaceIndexName, kcpcache.ClusterAndNamespaceIndexKey(clusterName, listOpts.Namespace))
140+
}
131141
default:
132-
objs = c.indexer.List()
142+
if clusterName.Empty() {
143+
objs = c.indexer.List()
144+
} else {
145+
objs, err = c.indexer.ByIndex(kcpcache.ClusterIndexName, kcpcache.ClusterIndexKey(clusterName))
146+
}
133147
}
134148
if err != nil {
135149
return err
@@ -177,7 +191,7 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
177191
return apimeta.SetList(out, runtimeObjs)
178192
}
179193

180-
func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace string) ([]interface{}, error) {
194+
func byIndexes(indexer cache.Indexer, requires fields.Requirements, clusterName logicalcluster.Name, namespace string) ([]interface{}, error) {
181195
var (
182196
err error
183197
objs []interface{}
@@ -186,7 +200,12 @@ func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace st
186200
indexers := indexer.GetIndexers()
187201
for idx, req := range requires {
188202
indexName := FieldIndexName(req.Field)
189-
indexedValue := KeyToNamespacedKey(namespace, req.Value)
203+
var indexedValue string
204+
if clusterName.Empty() {
205+
indexedValue = KeyToNamespacedKey(namespace, req.Value)
206+
} else {
207+
indexedValue = KeyToClusteredKey(clusterName.String(), namespace, req.Value)
208+
}
190209
if idx == 0 {
191210
// we use first require to get snapshot data
192211
// TODO(halfcrazy): use complicated index when client-go provides byIndexes
@@ -229,7 +248,12 @@ func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace st
229248
// It's akin to MetaNamespaceKeyFunc. It's separate from
230249
// String to allow keeping the key format easily in sync with
231250
// MetaNamespaceKeyFunc.
232-
func objectKeyToStoreKey(k client.ObjectKey) string {
251+
func objectKeyToStoreKey(ctx context.Context, k client.ObjectKey) string {
252+
cluster, ok := kontext.ClusterFrom(ctx)
253+
if ok {
254+
return kcpcache.ToClusterAwareKey(cluster.String(), k.Namespace, k.Name)
255+
}
256+
233257
if k.Namespace == "" {
234258
return k.Name
235259
}
@@ -253,3 +277,9 @@ func KeyToNamespacedKey(ns string, baseKey string) string {
253277
}
254278
return allNamespacesNamespace + "/" + baseKey
255279
}
280+
281+
// KeyToClusteredKey prefixes the given index key with a cluster name
282+
// for use in field selector indexes.
283+
func KeyToClusteredKey(clusterName string, ns string, baseKey string) string {
284+
return clusterName + "|" + KeyToNamespacedKey(ns, baseKey)
285+
}

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"
@@ -46,7 +48,7 @@ type InformersOpts struct {
4648
Mapper meta.RESTMapper
4749
ResyncPeriod time.Duration
4850
Namespace string
49-
NewInformer *func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer
51+
NewInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) kcpcache.ScopeableSharedIndexInformer
5052
Selector Selector
5153
Transform cache.TransformFunc
5254
UnsafeDisableDeepCopy bool
@@ -55,9 +57,9 @@ type InformersOpts struct {
5557

5658
// NewInformers creates a new InformersMap that can create informers under the hood.
5759
func NewInformers(config *rest.Config, options *InformersOpts) *Informers {
58-
newInformer := cache.NewSharedIndexInformer
60+
newInformer := informers.NewSharedIndexInformer
5961
if options.NewInformer != nil {
60-
newInformer = *options.NewInformer
62+
newInformer = options.NewInformer
6163
}
6264
return &Informers{
6365
config: config,
@@ -175,7 +177,7 @@ type Informers struct {
175177
unsafeDisableDeepCopy bool
176178

177179
// NewInformer allows overriding of the shared index informer constructor for testing.
178-
newInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer
180+
newInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) kcpcache.ScopeableSharedIndexInformer
179181

180182
// WatchErrorHandler allows the shared index informer's
181183
// watchErrorHandler to be set by overriding the options

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
//
94102
// The client's read behavior is determined by Options.Cache.

0 commit comments

Comments
 (0)