Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide plugins access to openshift informers #231

Merged
merged 2 commits into from Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,21 @@
package openshiftadmission

import "k8s.io/apiserver/pkg/admission"

type openshiftInformersInitializer struct {
informerAccess InformerAccess
}

func NewOpenShiftInformersInitializer(access InformerAccess) *openshiftInformersInitializer {
return &openshiftInformersInitializer{informerAccess: access}
}

type WantsOpenShiftInformerAccess interface {
SetOpenShiftInformerAccess(access InformerAccess)
}

func (i *openshiftInformersInitializer) Initialize(plugin admission.Interface) {
if wants, ok := plugin.(WantsOpenShiftInformerAccess); ok {
wants.SetOpenShiftInformerAccess(i.informerAccess)
}
}
Expand Up @@ -91,6 +91,8 @@ func NewPluginInitializer(
restMapper,
generic.NewConfiguration(quotaRegistry.List(), map[schema.GroupResource]struct{}{}))

openshiftPluginInitializer := NewOpenShiftInformersInitializer(informers)

webhookAuthResolverWrapper := func(delegate webhook.AuthenticationInfoResolver) webhook.AuthenticationInfoResolver {
return &webhook.AuthenticationInfoResolverDelegator{
ClientConfigForFunc: func(server string) (*rest.Config, error) {
Expand All @@ -117,6 +119,7 @@ func NewPluginInitializer(
genericInitializer,
webhookInitializer,
kubePluginInitializer,
openshiftPluginInitializer,
imagepolicy.NewInitializer(originimagereferencemutators.OriginImageMutators{}, internalImageRegistryHostname),
clusterresourcequota.NewInitializer(
informers.GetOpenshiftQuotaInformers().Quota().V1().ClusterResourceQuotas(),
Expand Down
12 changes: 12 additions & 0 deletions pkg/cmd/openshift-apiserver/openshiftapiserver/informers.go
Expand Up @@ -5,6 +5,8 @@ import (

authorizationv1client "github.com/openshift/client-go/authorization/clientset/versioned"
authorizationv1informer "github.com/openshift/client-go/authorization/informers/externalversions"
configv1client "github.com/openshift/client-go/config/clientset/versioned"
configv1informer "github.com/openshift/client-go/config/informers/externalversions"
imagev1client "github.com/openshift/client-go/image/clientset/versioned"
imagev1informer "github.com/openshift/client-go/image/informers/externalversions"
oauthv1client "github.com/openshift/client-go/oauth/clientset/versioned"
Expand All @@ -31,6 +33,7 @@ type InformerHolder struct {

// Internal OpenShift informers
authorizationInformers authorizationv1informer.SharedInformerFactory
configInformers configv1informer.SharedInformerFactory
imageInformers imagev1informer.SharedInformerFactory
oauthInformers oauthv1informer.SharedInformerFactory
quotaInformers quotainformer.SharedInformerFactory
Expand All @@ -46,6 +49,10 @@ func NewInformers(kubeInformers kexternalinformers.SharedInformerFactory, kubeCl
if err != nil {
return nil, err
}
configClient, err := configv1client.NewForConfig(loopbackClientConfig)
if err != nil {
return nil, err
}
imageClient, err := imagev1client.NewForConfig(loopbackClientConfig)
if err != nil {
return nil, err
Expand Down Expand Up @@ -82,6 +89,7 @@ func NewInformers(kubeInformers kexternalinformers.SharedInformerFactory, kubeCl
return &InformerHolder{
kubernetesInformers: kubeInformers,
authorizationInformers: authorizationv1informer.NewSharedInformerFactory(authorizationClient, defaultInformerResyncPeriod),
configInformers: configv1informer.NewSharedInformerFactory(configClient, defaultInformerResyncPeriod),
imageInformers: imagev1informer.NewSharedInformerFactory(imageClient, defaultInformerResyncPeriod),
oauthInformers: oauthv1informer.NewSharedInformerFactory(oauthClient, defaultInformerResyncPeriod),
quotaInformers: quotainformer.NewSharedInformerFactory(quotaClient, defaultInformerResyncPeriod),
Expand All @@ -107,6 +115,9 @@ func (i *InformerHolder) GetKubernetesInformers() kexternalinformers.SharedInfor
func (i *InformerHolder) GetOpenshiftAuthorizationInformers() authorizationv1informer.SharedInformerFactory {
return i.authorizationInformers
}
func (i *InformerHolder) GetOpenshiftConfigInformers() configv1informer.SharedInformerFactory {
return i.configInformers
}
func (i *InformerHolder) GetOpenshiftImageInformers() imagev1informer.SharedInformerFactory {
return i.imageInformers
}
Expand All @@ -130,6 +141,7 @@ func (i *InformerHolder) GetOpenshiftUserInformers() userv1informer.SharedInform
func (i *InformerHolder) Start(stopCh <-chan struct{}) {
i.kubernetesInformers.Start(stopCh)
i.authorizationInformers.Start(stopCh)
i.configInformers.Start(stopCh)
i.imageInformers.Start(stopCh)
i.oauthInformers.Start(stopCh)
i.quotaInformers.Start(stopCh)
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.

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.