Skip to content

Commit 9c1c5b8

Browse files
committed
Make MapperProvider multi-cluster by default
Default options.MapperProvider to an implementation that defaults to /clusters/*, so API discovery (i.e. REST mapping) will work. Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
1 parent 9fc73db commit 9c1c5b8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/kcp/wrappers.go

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

1919
import (
2020
"net/http"
21+
"strings"
2122

23+
"k8s.io/apimachinery/pkg/api/meta"
2224
"k8s.io/client-go/rest"
2325
k8scache "k8s.io/client-go/tools/cache"
26+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
2427

2528
kcpcache "github.com/kcp-dev/apimachinery/pkg/cache"
2629
kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
@@ -38,10 +41,22 @@ func NewClusterAwareManager(cfg *rest.Config, options ctrl.Options) (manager.Man
3841
if options.NewCache == nil {
3942
options.NewCache = NewClusterAwareCache
4043
}
44+
4145
if options.NewClient == nil {
4246
options.NewClient = NewClusterAwareClient
4347
}
4448

49+
if options.MapperProvider == nil {
50+
options.MapperProvider = func(c *rest.Config) (meta.RESTMapper, error) {
51+
mapperCfg := rest.CopyConfig(c)
52+
if !strings.HasSuffix(mapperCfg.Host, "/clusters/*") {
53+
mapperCfg.Host += "/clusters/*"
54+
}
55+
56+
return apiutil.NewDynamicRESTMapper(mapperCfg)
57+
}
58+
}
59+
4560
return ctrl.NewManager(cfg, options)
4661
}
4762

0 commit comments

Comments
 (0)