@@ -11,6 +11,7 @@ import (
1111 "github.com/golang/glog"
1212
1313 kapierrors "k8s.io/apimachinery/pkg/api/errors"
14+ "k8s.io/apimachinery/pkg/api/meta"
1415 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516 "k8s.io/apimachinery/pkg/labels"
1617 "k8s.io/apimachinery/pkg/runtime/schema"
@@ -32,6 +33,8 @@ import (
3233 "k8s.io/apiserver/pkg/authorization/authorizerfactory"
3334 authorizerunion "k8s.io/apiserver/pkg/authorization/union"
3435 apirequest "k8s.io/apiserver/pkg/endpoints/request"
36+ "k8s.io/client-go/discovery"
37+ cacheddiscovery "k8s.io/client-go/discovery/cached"
3538 kubeclientgoinformers "k8s.io/client-go/informers"
3639 kubeclientgoclient "k8s.io/client-go/kubernetes"
3740 restclient "k8s.io/client-go/rest"
@@ -92,6 +95,8 @@ import (
9295type MasterConfig struct {
9396 Options configapi.MasterConfig
9497
98+ RESTMapper * discovery.DeferredDiscoveryRESTMapper
99+
95100 // RESTOptionsGetter provides access to storage and RESTOptions for a particular resource
96101 RESTOptionsGetter restoptions.Getter
97102
@@ -222,6 +227,10 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
222227 options .ProjectConfig .ProjectRequestMessage ,
223228 )
224229
230+ // Use a discovery client capable of being refreshed.
231+ discoveryClient := cacheddiscovery .NewMemCacheClient (privilegedLoopbackKubeClientsetInternal .Discovery ())
232+ restMapper := discovery .NewDeferredDiscoveryRESTMapper (discoveryClient , meta .InterfacesForUnstructured )
233+
225234 // punch through layers to build this in order to get a string for a cloud provider file
226235 // TODO refactor us into a forward building flow with a side channel like this
227236 kubeOptions , err := kubernetes .BuildKubeAPIserverOptions (options )
@@ -248,8 +257,7 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
248257 informers .GetInternalKubeInformers (),
249258 authorizer ,
250259 cloudConfig ,
251- // TODO: use a dynamic restmapper. See https://github.com/kubernetes/kubernetes/pull/42615.
252- kapi .Registry .RESTMapper (),
260+ restMapper ,
253261 quotaRegistry )
254262 openshiftPluginInitializer := & oadmission.PluginInitializer {
255263 OpenshiftClient : privilegedLoopbackOpenShiftClient ,
@@ -295,6 +303,8 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
295303 config := & MasterConfig {
296304 Options : options ,
297305
306+ RESTMapper : restMapper ,
307+
298308 RESTOptionsGetter : restOptsGetter ,
299309
300310 RuleResolver : ruleResolver ,
0 commit comments