Skip to content

Commit

Permalink
Use generated informer with cluster resource quota
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Jun 14, 2017
1 parent c7a38d7 commit 8fa91e2
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 180 deletions.
26 changes: 14 additions & 12 deletions pkg/cmd/server/admission/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ import (
imageapi "github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/project/cache"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion/quota/internalversion"
usercache "github.com/openshift/origin/pkg/user/cache"
)

type PluginInitializer struct {
OpenshiftClient client.Interface
ProjectCache *cache.ProjectCache
OriginQuotaRegistry quota.Registry
Authorizer kauthorizer.Authorizer
JenkinsPipelineConfig configapi.JenkinsPipelineConfig
RESTClientConfig restclient.Config
Informers shared.InformerFactory
ClusterQuotaMapper clusterquotamapping.ClusterQuotaMapper
DefaultRegistryFn imageapi.DefaultRegistryFunc
GroupCache *usercache.GroupCache
OpenshiftClient client.Interface
ProjectCache *cache.ProjectCache
OriginQuotaRegistry quota.Registry
Authorizer kauthorizer.Authorizer
JenkinsPipelineConfig configapi.JenkinsPipelineConfig
RESTClientConfig restclient.Config
Informers shared.InformerFactory
ClusterResourceQuotaInformer quotainformer.ClusterResourceQuotaInformer
ClusterQuotaMapper clusterquotamapping.ClusterQuotaMapper
DefaultRegistryFn imageapi.DefaultRegistryFunc
GroupCache *usercache.GroupCache
}

// Initialize will check the initialization interfaces implemented by each plugin
Expand Down Expand Up @@ -59,8 +61,8 @@ func (i *PluginInitializer) Initialize(plugin admission.Interface) {
if wantsInformerFactory, ok := plugin.(kubeapiserveradmission.WantsInternalKubeInformerFactory); ok {
wantsInformerFactory.SetInternalKubeInformerFactory(i.Informers.InternalKubernetesInformers())
}
if wantsClusterQuotaMapper, ok := plugin.(WantsClusterQuotaMapper); ok {
wantsClusterQuotaMapper.SetClusterQuotaMapper(i.ClusterQuotaMapper)
if wantsClusterQuota, ok := plugin.(WantsClusterQuota); ok {
wantsClusterQuota.SetClusterQuota(i.ClusterQuotaMapper, i.ClusterResourceQuotaInformer)
}
if wantsDefaultRegistryFunc, ok := plugin.(WantsDefaultRegistryFunc); ok {
wantsDefaultRegistryFunc.SetDefaultRegistryFunc(i.DefaultRegistryFn)
Expand Down
9 changes: 5 additions & 4 deletions pkg/cmd/server/admission/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
imageapi "github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/project/cache"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion/quota/internalversion"
usercache "github.com/openshift/origin/pkg/user/cache"
)

Expand Down Expand Up @@ -61,10 +62,10 @@ type WantsInformers interface {
admission.Validator
}

// WantsClusterQuotaMapper should be implemented by admission plugins that need to know how to map between
// cluster quota and namespaces
type WantsClusterQuotaMapper interface {
SetClusterQuotaMapper(clusterquotamapping.ClusterQuotaMapper)
// WantsClusterQuota should be implemented by admission plugins that need to know how to map between
// cluster quota and namespaces and get access to the informer.
type WantsClusterQuota interface {
SetClusterQuota(clusterquotamapping.ClusterQuotaMapper, quotainformer.ClusterResourceQuotaInformer)
admission.Validator
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/origin/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *MasterConfig) newOpenshiftAPIConfig(kubeAPIServerConfig apiserver.Confi
KubeletClientConfig: c.KubeletClientConfig,
KubeInternalInformers: c.Informers.InternalKubernetesInformers(),
AuthorizationInformers: c.AuthorizationInformers,
DeprecatedInformers: c.Informers,
QuotaInformers: c.QuotaInformers,
DeprecatedOpenshiftClient: c.PrivilegedLoopbackOpenShiftClient,
RuleResolver: c.RuleResolver,
SubjectLocator: c.SubjectLocator,
Expand Down
32 changes: 21 additions & 11 deletions pkg/cmd/server/origin/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import (
"github.com/openshift/origin/pkg/quota"
overrideapi "github.com/openshift/origin/pkg/quota/admission/clusterresourceoverride/api"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion"
quotaclient "github.com/openshift/origin/pkg/quota/generated/internalclientset"
"github.com/openshift/origin/pkg/service"
serviceadmit "github.com/openshift/origin/pkg/service/admission"
"github.com/openshift/origin/pkg/serviceaccounts"
Expand Down Expand Up @@ -191,6 +193,7 @@ type MasterConfig struct {
AppInformers appinformer.SharedInformerFactory
AuthorizationInformers authorizationinformer.SharedInformerFactory
ImageInformers imageinformer.SharedInformerFactory
QuotaInformers quotainformer.SharedInformerFactory
TemplateInformers templateinformer.SharedInformerFactory
}

Expand Down Expand Up @@ -235,6 +238,10 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
if err != nil {
return nil, err
}
quotaClient, err := quotaclient.NewForConfig(privilegedLoopbackClientConfig)
if err != nil {
return nil, err
}
templateClient, err := templateclient.NewForConfig(privilegedLoopbackClientConfig)
if err != nil {
return nil, err
Expand All @@ -251,6 +258,7 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
externalkubeInformerFactory := kinformers.NewSharedInformerFactory(privilegedLoopbackKubeClientsetExternal, defaultInformerResyncPeriod)
appInformers := appinformer.NewSharedInformerFactory(appClient, defaultInformerResyncPeriod)
authorizationInformers := authorizationinformer.NewSharedInformerFactory(authorizationClient, defaultInformerResyncPeriod)
quotaInformers := quotainformer.NewSharedInformerFactory(quotaClient, defaultInformerResyncPeriod)
imageInformers := imageinformer.NewSharedInformerFactory(imageClient, defaultInformerResyncPeriod)
templateInformers := templateinformer.NewSharedInformerFactory(templateClient, defaultInformerResyncPeriod)
informerFactory := shared.NewInformerFactory(internalkubeInformerFactory, externalkubeInformerFactory, privilegedLoopbackKubeClientsetInternal, privilegedLoopbackOpenShiftClient, customListerWatchers, defaultInformerResyncPeriod)
Expand Down Expand Up @@ -283,7 +291,7 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
}
groupCache := usercache.NewGroupCache(groupregistry.NewRegistry(groupStorage))
projectCache := projectcache.NewProjectCache(informerFactory.InternalKubernetesInformers().Core().InternalVersion().Namespaces().Informer(), privilegedLoopbackKubeClientsetInternal.Core().Namespaces(), options.ProjectConfig.DefaultNodeSelector)
clusterQuotaMappingController := clusterquotamapping.NewClusterQuotaMappingController(internalkubeInformerFactory.Core().InternalVersion().Namespaces(), informerFactory.ClusterResourceQuotas())
clusterQuotaMappingController := clusterquotamapping.NewClusterQuotaMappingController(internalkubeInformerFactory.Core().InternalVersion().Namespaces(), quotaInformers.Quota().InternalVersion().ClusterResourceQuotas())

kubeletClientConfig := configapi.GetKubeletClientConfig(options)

Expand All @@ -297,16 +305,17 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
authorizer, subjectLocator := newAuthorizer(ruleResolver, informerFactory, authorizationInformers.Authorization().InternalVersion(), options.ProjectConfig.ProjectRequestMessage)

pluginInitializer := oadmission.PluginInitializer{
OpenshiftClient: privilegedLoopbackOpenShiftClient,
ProjectCache: projectCache,
OriginQuotaRegistry: quotaRegistry,
Authorizer: authorizer,
JenkinsPipelineConfig: options.JenkinsPipelineConfig,
RESTClientConfig: *privilegedLoopbackClientConfig,
Informers: informerFactory,
ClusterQuotaMapper: clusterQuotaMappingController.GetClusterQuotaMapper(),
DefaultRegistryFn: imageapi.DefaultRegistryFunc(defaultRegistryFunc),
GroupCache: groupCache,
OpenshiftClient: privilegedLoopbackOpenShiftClient,
ProjectCache: projectCache,
OriginQuotaRegistry: quotaRegistry,
Authorizer: authorizer,
JenkinsPipelineConfig: options.JenkinsPipelineConfig,
RESTClientConfig: *privilegedLoopbackClientConfig,
Informers: informerFactory,
ClusterResourceQuotaInformer: quotaInformers.Quota().InternalVersion().ClusterResourceQuotas(),
ClusterQuotaMapper: clusterQuotaMappingController.GetClusterQuotaMapper(),
DefaultRegistryFn: imageapi.DefaultRegistryFunc(defaultRegistryFunc),
GroupCache: groupCache,
}

// punch through layers to build this in order to get a string for a cloud provider file
Expand Down Expand Up @@ -384,6 +393,7 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
AppInformers: appInformers,
AuthorizationInformers: authorizationInformers,
ImageInformers: imageInformers,
QuotaInformers: quotaInformers,
TemplateInformers: templateInformers,
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/cmd/server/origin/openshift-apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"github.com/openshift/origin/pkg/authorization/rulevalidation"
osclient "github.com/openshift/origin/pkg/client"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
deprecatedinformers "github.com/openshift/origin/pkg/controller/shared"
imageadmission "github.com/openshift/origin/pkg/image/admission"
imageapi "github.com/openshift/origin/pkg/image/api"
projectauth "github.com/openshift/origin/pkg/project/auth"
projectcache "github.com/openshift/origin/pkg/project/cache"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion"
routeallocationcontroller "github.com/openshift/origin/pkg/route/controller/allocation"
"github.com/openshift/origin/pkg/version"

Expand All @@ -60,9 +60,9 @@ type OpenshiftAPIConfig struct {
KubeInternalInformers kinternalinformers.SharedInformerFactory

AuthorizationInformers authorizationinformer.SharedInformerFactory
QuotaInformers quotainformer.SharedInformerFactory

// DeprecatedInformers is a shared factory for getting old style openshift informers
DeprecatedInformers deprecatedinformers.InformerFactory
DeprecatedOpenshiftClient *osclient.Client

// these are all required to build our storage
Expand Down Expand Up @@ -104,12 +104,15 @@ func (c *OpenshiftAPIConfig) Validate() error {
if c.KubeletClientConfig == nil {
ret = append(ret, fmt.Errorf("KubeletClientConfig is required"))
}
if c.DeprecatedInformers == nil {
ret = append(ret, fmt.Errorf("DeprecatedInformers is required"))
}
if c.KubeInternalInformers == nil {
ret = append(ret, fmt.Errorf("KubeInternalInformers is required"))
}
if c.AuthorizationInformers == nil {
ret = append(ret, fmt.Errorf("AuthorizationInformers is required"))
}
if c.QuotaInformers == nil {
ret = append(ret, fmt.Errorf("QuotaInformers is required"))
}
if c.RuleResolver == nil {
ret = append(ret, fmt.Errorf("RuleResolver is required"))
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/cmd/server/origin/reststorage_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
deployapi "github.com/openshift/origin/pkg/deploy/api"
quotaapi "github.com/openshift/origin/pkg/quota/api"
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion"
quotaclientfake "github.com/openshift/origin/pkg/quota/generated/internalclientset/fake"
"github.com/openshift/origin/pkg/util/restoptions"
)

Expand Down Expand Up @@ -92,23 +94,24 @@ func fakeMasterConfig() *MasterConfig {
externalKubeInformerFactory := kinformers.NewSharedInformerFactory(fakeexternal.NewSimpleClientset(), 1*time.Second)
informerFactory := shared.NewInformerFactory(internalkubeInformerFactory, externalKubeInformerFactory, fakeinternal.NewSimpleClientset(), testclient.NewSimpleFake(), shared.DefaultListerWatcherOverrides{}, 1*time.Second)
authorizationInformerFactory := authorizationinformer.NewSharedInformerFactory(authorizationclientfake.NewSimpleClientset(), 0)
quotaInformerFactory := quotainformer.NewSharedInformerFactory(quotaclientfake.NewSimpleClientset(), 0)

return &MasterConfig{
KubeletClientConfig: &kubeletclient.KubeletClientConfig{},
RESTOptionsGetter: restoptions.NewSimpleGetter(&storagebackend.Config{ServerList: []string{"localhost"}}),
Informers: informerFactory,
AuthorizationInformers: authorizationInformerFactory,
ClusterQuotaMappingController: clusterquotamapping.NewClusterQuotaMappingController(internalkubeInformerFactory.Core().InternalVersion().Namespaces(), informerFactory.ClusterResourceQuotas()),
QuotaInformers: quotaInformerFactory,
ClusterQuotaMappingController: clusterquotamapping.NewClusterQuotaMappingController(internalkubeInformerFactory.Core().InternalVersion().Namespaces(), quotaInformerFactory.Quota().InternalVersion().ClusterResourceQuotas()),
PrivilegedLoopbackKubernetesClientsetInternal: &kclientsetinternal.Clientset{},
PrivilegedLoopbackKubernetesClientsetExternal: &kclientsetexternal.Clientset{},
}
}

func fakeOpenshiftAPIServerConfig() *OpenshiftAPIConfig {
internalkubeInformerFactory := kinternalinformers.NewSharedInformerFactory(fakeinternal.NewSimpleClientset(), 1*time.Second)
externalKubeInformerFactory := kinformers.NewSharedInformerFactory(fakeexternal.NewSimpleClientset(), 1*time.Second)
informerFactory := shared.NewInformerFactory(internalkubeInformerFactory, externalKubeInformerFactory, fakeinternal.NewSimpleClientset(), testclient.NewSimpleFake(), shared.DefaultListerWatcherOverrides{}, 1*time.Second)
authorizationInformerFactory := authorizationinformer.NewSharedInformerFactory(authorizationclientfake.NewSimpleClientset(), 0)
quotaInformerFactory := quotainformer.NewSharedInformerFactory(quotaclientfake.NewSimpleClientset(), 0)

ret := &OpenshiftAPIConfig{
GenericConfig: &apiserver.Config{
Expand All @@ -120,10 +123,10 @@ func fakeOpenshiftAPIServerConfig() *OpenshiftAPIConfig {
KubeletClientConfig: &kubeletclient.KubeletClientConfig{},
KubeInternalInformers: internalkubeInformerFactory,
AuthorizationInformers: authorizationInformerFactory,
DeprecatedInformers: informerFactory,
QuotaInformers: quotaInformerFactory,
EnableBuilds: true,
EnableTemplateServiceBroker: false,
ClusterQuotaMappingController: clusterquotamapping.NewClusterQuotaMappingController(internalkubeInformerFactory.Core().InternalVersion().Namespaces(), informerFactory.ClusterResourceQuotas()),
ClusterQuotaMappingController: clusterquotamapping.NewClusterQuotaMappingController(internalkubeInformerFactory.Core().InternalVersion().Namespaces(), quotaInformerFactory.Quota().InternalVersion().ClusterResourceQuotas()),
}
return ret
}
2 changes: 1 addition & 1 deletion pkg/cmd/server/origin/run_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (c *MasterConfig) RunClusterQuotaReconciliationController() {
groupKindsToReplenish := quota.AllEvaluatedGroupKinds

options := clusterquotareconciliation.ClusterQuotaReconcilationControllerOptions{
ClusterQuotaInformer: c.Informers.ClusterResourceQuotas(),
ClusterQuotaInformer: c.QuotaInformers.Quota().InternalVersion().ClusterResourceQuotas(),
ClusterQuotaMapper: c.ClusterQuotaMappingController.GetClusterQuotaMapper(),
ClusterQuotaClient: osClient,

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/origin/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (c OpenshiftAPIConfig) GetRestStorage() (map[schema.GroupVersion]map[string
"clusterResourceQuotas/status": clusterResourceQuotaStatusStorage,
"appliedClusterResourceQuotas": appliedclusterresourcequotaregistry.NewREST(
c.ClusterQuotaMappingController.GetClusterQuotaMapper(),
c.DeprecatedInformers.ClusterResourceQuotas().Lister(),
c.QuotaInformers.Quota().InternalVersion().ClusterResourceQuotas().Lister(),
c.KubeInternalInformers.Core().InternalVersion().Namespaces().Lister(),
),
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ func (m *Master) Start() error {
openshiftConfig.Informers.InternalKubernetesInformers().Start(utilwait.NeverStop)
openshiftConfig.Informers.KubernetesInformers().Start(utilwait.NeverStop)
openshiftConfig.Informers.Start(utilwait.NeverStop)
openshiftConfig.Informers.StartCore(utilwait.NeverStop)
openshiftConfig.AppInformers.Start(utilwait.NeverStop)
openshiftConfig.AuthorizationInformers.Start(utilwait.NeverStop)
openshiftConfig.ImageInformers.Start(utilwait.NeverStop)
openshiftConfig.QuotaInformers.Start(utilwait.NeverStop)
openshiftConfig.TemplateInformers.Start(utilwait.NeverStop)
}()
} else {
Expand All @@ -473,6 +473,7 @@ func (m *Master) Start() error {
openshiftConfig.AppInformers.Start(utilwait.NeverStop)
openshiftConfig.AuthorizationInformers.Start(utilwait.NeverStop)
openshiftConfig.ImageInformers.Start(utilwait.NeverStop)
openshiftConfig.QuotaInformers.Start(utilwait.NeverStop)
openshiftConfig.TemplateInformers.Start(utilwait.NeverStop)
}

Expand Down Expand Up @@ -504,8 +505,8 @@ func StartAPI(oc *origin.MasterConfig, kc *kubernetes.MasterConfig) error {
}
}

// Must start policy caching immediately
oc.Informers.StartCore(utilwait.NeverStop)
// Must start policy and quota caching immediately
oc.QuotaInformers.Start(utilwait.NeverStop)
oc.AuthorizationInformers.Start(utilwait.NeverStop)
oc.RunClusterQuotaMappingController()
oc.RunGroupCache()
Expand Down Expand Up @@ -718,6 +719,9 @@ func startControllers(oc *origin.MasterConfig, kc *kubernetes.MasterConfig) erro
genericInternalResourceInformerFunc(func(resource schema.GroupVersionResource) (kinformers.GenericInformer, error) {
return oc.ImageInformers.ForResource(resource)
}),
genericInternalResourceInformerFunc(func(resource schema.GroupVersionResource) (kinformers.GenericInformer, error) {
return oc.QuotaInformers.ForResource(resource)
}),
genericInternalResourceInformerFunc(func(resource schema.GroupVersionResource) (kinformers.GenericInformer, error) {
return oc.TemplateInformers.ForResource(resource)
}),
Expand Down
70 changes: 0 additions & 70 deletions pkg/controller/shared/quota_informers.go

This file was deleted.

Loading

0 comments on commit 8fa91e2

Please sign in to comment.