Skip to content

Commit

Permalink
add dynamic rest mapper to the admission plugin initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Sep 11, 2017
1 parent c7ca499 commit 2ffa593
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/cmd/server/origin/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/glog"

apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion"
"k8s.io/apimachinery/pkg/util/wait"
apiserver "k8s.io/apiserver/pkg/server"
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
kubeapiserver "k8s.io/kubernetes/pkg/master"
Expand Down Expand Up @@ -249,6 +250,15 @@ func (c *MasterConfig) Run(kubeAPIServerConfig *kubeapiserver.Config, controller
// add post-start hooks
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("template.openshift.io-sharednamespace", c.ensureOpenShiftSharedResourcesNamespace)
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("authorization.openshift.io-bootstrapclusterroles", bootstrappolicy.Policy().EnsureRBACPolicy())
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("admission.openshift.io-RefreshRESTMapper", func(context apiserver.PostStartHookContext) error {
c.RESTMapper.Reset()
go func() {
wait.Until(func() {
c.RESTMapper.Reset()
}, 10*time.Second, context.StopCh)
}()
return nil
})
for name, fn := range extraPostStartHooks {
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn)
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/cmd/server/origin/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/glog"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -32,6 +33,8 @@ import (
"k8s.io/apiserver/pkg/authorization/authorizerfactory"
authorizerunion "k8s.io/apiserver/pkg/authorization/union"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/client-go/discovery"
cacheddiscovery "k8s.io/client-go/discovery/cached"
kubeclientgoinformers "k8s.io/client-go/informers"
kubeclientgoclient "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
Expand Down Expand Up @@ -92,6 +95,8 @@ import (
type MasterConfig struct {
Options configapi.MasterConfig

RESTMapper *discovery.DeferredDiscoveryRESTMapper

// RESTOptionsGetter provides access to storage and RESTOptions for a particular resource
RESTOptionsGetter restoptions.Getter

Expand Down Expand Up @@ -222,6 +227,10 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
options.ProjectConfig.ProjectRequestMessage,
)

// Use a discovery client capable of being refreshed.
discoveryClient := cacheddiscovery.NewMemCacheClient(privilegedLoopbackKubeClientsetInternal.Discovery())
restMapper := discovery.NewDeferredDiscoveryRESTMapper(discoveryClient, meta.InterfacesForUnstructured)

// punch through layers to build this in order to get a string for a cloud provider file
// TODO refactor us into a forward building flow with a side channel like this
kubeOptions, err := kubernetes.BuildKubeAPIserverOptions(options)
Expand All @@ -248,8 +257,7 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
informers.GetInternalKubeInformers(),
authorizer,
cloudConfig,
// TODO: use a dynamic restmapper. See https://github.com/kubernetes/kubernetes/pull/42615.
kapi.Registry.RESTMapper(),
restMapper,
quotaRegistry)
openshiftPluginInitializer := &oadmission.PluginInitializer{
OpenshiftClient: privilegedLoopbackOpenShiftClient,
Expand Down Expand Up @@ -295,6 +303,8 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
config := &MasterConfig{
Options: options,

RESTMapper: restMapper,

RESTOptionsGetter: restOptsGetter,

RuleResolver: ruleResolver,
Expand Down
1 change: 1 addition & 0 deletions test/integration/master_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var expectedIndex = []string{
"/healthz",
"/healthz/autoregister-completion",
"/healthz/ping",
"/healthz/poststarthook/admission.openshift.io-RefreshRESTMapper",
"/healthz/poststarthook/apiservice-registration-controller",
"/healthz/poststarthook/apiservice-status-available-controller",
"/healthz/poststarthook/authorization.openshift.io-bootstrapclusterroles",
Expand Down

0 comments on commit 2ffa593

Please sign in to comment.