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 7, 2017
1 parent 83fc66a commit 87ea4ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/cmd/server/origin/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"gopkg.in/natefinch/lumberjack.v2"

apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion"
"k8s.io/apimachinery/pkg/util/wait"
auditinternal "k8s.io/apiserver/pkg/apis/audit"
auditpolicy "k8s.io/apiserver/pkg/audit/policy"
apifilters "k8s.io/apiserver/pkg/endpoints/filters"
Expand Down Expand Up @@ -257,6 +258,16 @@ 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.PollUntil(10*time.Second, func() (bool, error) {
c.RESTMapper.Reset()
return false, nil
}, 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

0 comments on commit 87ea4ec

Please sign in to comment.