Skip to content

Commit

Permalink
Merge pull request #16215 from deads2k/gc-01-restmapper
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

add dynamic rest mapper to the admission plugin initializer

fixes #16141

picks the dynamic memcache discovery for the RESTMapper and wires it for admission.  There's a post-start hook that starts it refreshing.
  • Loading branch information
openshift-merge-robot authored Sep 12, 2017
2 parents 0b29c3f + 2ffa593 commit 15f7720
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 3 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 @@ -12,6 +12,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 @@ -35,6 +36,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 @@ -95,6 +98,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 @@ -225,6 +230,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 @@ -251,8 +260,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 @@ -298,6 +306,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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15f7720

Please sign in to comment.