Skip to content

Commit 709c44a

Browse files
committed
Wire DynamicRESTMapper into pkg/server
On-behalf-of: @SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
1 parent 8de2a35 commit 709c44a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pkg/server/controllers.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import (
7979
coresreplicateclusterrole "github.com/kcp-dev/kcp/pkg/reconciler/core/replicateclusterrole"
8080
corereplicateclusterrolebinding "github.com/kcp-dev/kcp/pkg/reconciler/core/replicateclusterrolebinding"
8181
"github.com/kcp-dev/kcp/pkg/reconciler/core/shard"
82+
"github.com/kcp-dev/kcp/pkg/reconciler/dynamicrestmapper"
8283
"github.com/kcp-dev/kcp/pkg/reconciler/garbagecollector"
8384
"github.com/kcp-dev/kcp/pkg/reconciler/kubequota"
8485
"github.com/kcp-dev/kcp/pkg/reconciler/tenancy/bootstrap"
@@ -1595,6 +1596,39 @@ func (s *Server) installGarbageCollectorController(ctx context.Context, config *
15951596
})
15961597
}
15971598

1599+
func (s *Server) installDynamicRESTMapper(ctx context.Context, config *rest.Config) error {
1600+
c, err := dynamicrestmapper.NewController(ctx, s.DynRESTMapper,
1601+
s.ApiExtensionsSharedInformerFactory.Apiextensions().V1().CustomResourceDefinitions(),
1602+
s.KcpSharedInformerFactory.Apis().V1alpha1().APIBindings(),
1603+
s.KcpSharedInformerFactory.Apis().V1alpha2().APIExports(),
1604+
s.KcpSharedInformerFactory.Apis().V1alpha1().APIResourceSchemas(),
1605+
s.CacheKcpSharedInformerFactory.Apis().V1alpha2().APIExports(),
1606+
s.CacheKcpSharedInformerFactory.Apis().V1alpha1().APIResourceSchemas(),
1607+
s.KcpSharedInformerFactory.Core().V1alpha1().LogicalClusters(),
1608+
)
1609+
if err != nil {
1610+
return err
1611+
}
1612+
1613+
return s.registerController(&controllerWrapper{
1614+
Name: dynamicrestmapper.ControllerName,
1615+
Wait: func(ctx context.Context, s *Server) error {
1616+
return wait.PollUntilContextCancel(ctx, waitPollInterval, true, func(ctx context.Context) (bool, error) {
1617+
return s.KcpSharedInformerFactory.Core().V1alpha1().LogicalClusters().Informer().HasSynced() &&
1618+
s.ApiExtensionsSharedInformerFactory.Apiextensions().V1().CustomResourceDefinitions().Informer().HasSynced() &&
1619+
s.KcpSharedInformerFactory.Apis().V1alpha2().APIExports().Informer().HasSynced() &&
1620+
s.CacheKcpSharedInformerFactory.Apis().V1alpha2().APIExports().Informer().HasSynced() &&
1621+
s.KcpSharedInformerFactory.Apis().V1alpha1().APIResourceSchemas().Informer().HasSynced() &&
1622+
s.CacheKcpSharedInformerFactory.Apis().V1alpha1().APIResourceSchemas().Informer().HasSynced() &&
1623+
s.KcpSharedInformerFactory.Apis().V1alpha1().APIBindings().Informer().HasSynced(), nil
1624+
})
1625+
},
1626+
Runner: func(ctx context.Context) {
1627+
c.Start(ctx, 2)
1628+
},
1629+
})
1630+
}
1631+
15981632
func (s *Server) WaitForSync(stop <-chan struct{}) error {
15991633
// Wait for shared informer factories to by synced.
16001634
// factory. Otherwise, informer list calls may go into backoff (before the CRDs are ready) and

pkg/server/server.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
"github.com/kcp-dev/kcp/pkg/informer"
5757
metadataclient "github.com/kcp-dev/kcp/pkg/metadata"
5858
"github.com/kcp-dev/kcp/pkg/reconciler/cache/replication"
59+
"github.com/kcp-dev/kcp/pkg/reconciler/dynamicrestmapper"
5960
"github.com/kcp-dev/kcp/pkg/reconciler/kubequota"
6061
"github.com/kcp-dev/kcp/pkg/server/options/batteries"
6162
virtualrootapiserver "github.com/kcp-dev/kcp/pkg/virtual/framework/rootapiserver"
@@ -74,6 +75,7 @@ type Server struct {
7475
Apis *controlplaneapiserver.Server
7576
MiniAggregator *miniaggregator.MiniAggregatorServer
7677
virtual *virtualrootapiserver.Server
78+
DynRESTMapper *dynamicrestmapper.DynamicRESTMapper
7779

7880
syncedCh chan struct{}
7981
rootPhase1FinishedCh chan struct{}
@@ -181,6 +183,9 @@ func NewServer(c CompletedConfig) (*Server, error) {
181183
}
182184
}
183185

186+
// Controllers are free to pull in DynRESTMapper and query for types.
187+
s.DynRESTMapper = dynamicrestmapper.NewDynamicRESTMapper(nil)
188+
184189
return s, nil
185190
}
186191

@@ -349,6 +354,12 @@ func (s *Server) installControllers(ctx context.Context, controllerConfig *rest.
349354
}
350355
}
351356

357+
if s.Options.Controllers.EnableAll || enabled.Has("dynamicrestmapper") {
358+
if err := s.installDynamicRESTMapper(ctx, controllerConfig); err != nil {
359+
return err
360+
}
361+
}
362+
352363
return nil
353364
}
354365
func (s *Server) Run(ctx context.Context) error {

0 commit comments

Comments
 (0)