Skip to content

Commit

Permalink
Merge pull request #117 from atiratree/bug-13649-cluster-resource-quo…
Browse files Browse the repository at this point in the history
…tas-fix-count-4.12

OCPBUGS-14092: [4.12] fix ClusterResourceQuotas to work for all api resources including custom resources
  • Loading branch information
openshift-merge-robot committed Jun 6, 2023
2 parents 9aaf6fe + f062afb commit a83965e
Show file tree
Hide file tree
Showing 214 changed files with 11 additions and 19,493 deletions.
197 changes: 11 additions & 186 deletions pkg/cmd/controller/interfaces.go
Expand Up @@ -11,30 +11,20 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/metadata"
"k8s.io/client-go/metadata/metadatainformer"
"k8s.io/client-go/rest"
"k8s.io/controller-manager/app"
"k8s.io/controller-manager/pkg/clientbuilder"

openshiftcontrolplanev1 "github.com/openshift/api/openshiftcontrolplane/v1"
appsclient "github.com/openshift/client-go/apps/clientset/versioned"
appsinformer "github.com/openshift/client-go/apps/informers/externalversions"
buildclient "github.com/openshift/client-go/build/clientset/versioned"
buildinformer "github.com/openshift/client-go/build/informers/externalversions"
configclient "github.com/openshift/client-go/config/clientset/versioned"
configinformer "github.com/openshift/client-go/config/informers/externalversions"
imageclient "github.com/openshift/client-go/image/clientset/versioned"
imageinformer "github.com/openshift/client-go/image/informers/externalversions"
operatorclient "github.com/openshift/client-go/operator/clientset/versioned"
operatorinformer "github.com/openshift/client-go/operator/informers/externalversions"
quotaclient "github.com/openshift/client-go/quota/clientset/versioned"
quotainformer "github.com/openshift/client-go/quota/informers/externalversions"
routeclient "github.com/openshift/client-go/route/clientset/versioned"
routeinformer "github.com/openshift/client-go/route/informers/externalversions"
securityclient "github.com/openshift/client-go/security/clientset/versioned"
securityinformer "github.com/openshift/client-go/security/informers/externalversions"
securityinternalclient "github.com/openshift/client-go/securityinternal/clientset/versioned"
templateclient "github.com/openshift/client-go/template/clientset/versioned"
templateinformer "github.com/openshift/client-go/template/informers/externalversions"
"github.com/openshift/library-go/pkg/controller/controllercmd"

"github.com/openshift/cluster-policy-controller/pkg/client/genericinformers"
Expand Down Expand Up @@ -64,18 +54,11 @@ func NewControllerContext(
clientConfig.Burst = clientConfig.Burst/10 + 1
}

appsClient, err := appsclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
}
buildClient, err := buildclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
}
configClient, err := configclient.NewForConfig(nonProtobufConfig(clientConfig))
metadataClient, err := metadata.NewForConfig(clientConfig)
if err != nil {
return nil, err
}

imageClient, err := imageclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
Expand All @@ -84,18 +67,6 @@ func NewControllerContext(
if err != nil {
return nil, err
}
routerClient, err := routeclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
}
templateClient, err := templateclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
}
operatorClient, err := operatorclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
}
securityClient, err := securityclient.NewForConfig(clientConfig)
if err != nil {
return nil, err
Expand All @@ -109,15 +80,10 @@ func NewControllerContext(
ControllerClientBuilder: clientbuilder.NewDynamicClientBuilder(rest.AnonymousClientConfig(clientConfig), kubeClient.CoreV1(), defaultOpenShiftInfraNamespace),
},
KubernetesInformers: informers.NewSharedInformerFactory(kubeClient, defaultInformerResyncPeriod),
AppsInformers: appsinformer.NewSharedInformerFactory(appsClient, defaultInformerResyncPeriod),
BuildInformers: buildinformer.NewSharedInformerFactory(buildClient, defaultInformerResyncPeriod),
ConfigInformers: configinformer.NewSharedInformerFactory(configClient, defaultInformerResyncPeriod),
MetadataInformers: metadatainformer.NewSharedInformerFactory(metadataClient, defaultInformerResyncPeriod),
ImageInformers: imageinformer.NewSharedInformerFactory(imageClient, defaultInformerResyncPeriod),
OperatorInformers: operatorinformer.NewSharedInformerFactory(operatorClient, defaultInformerResyncPeriod),
QuotaInformers: quotainformer.NewSharedInformerFactory(quotaClient, defaultInformerResyncPeriod),
RouteInformers: routeinformer.NewSharedInformerFactory(routerClient, defaultInformerResyncPeriod),
SecurityInformers: securityinformer.NewSharedInformerFactory(securityClient, defaultInformerResyncPeriod),
TemplateInformers: templateinformer.NewSharedInformerFactory(templateClient, defaultInformerResyncPeriod),
InformersStarted: make(chan struct{}),
}
openshiftControllerContext.GenericResourceInformer = openshiftControllerContext.ToGenericInformer()
Expand All @@ -128,27 +94,17 @@ func NewControllerContext(
func (c *EnhancedControllerContext) ToGenericInformer() genericinformers.GenericResourceInformer {
return genericinformers.NewGenericInformers(
c.StartInformers,
// first shared informers used by the controllers
c.KubernetesInformers,
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.AppsInformers.ForResource(resource)
}),
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.BuildInformers.ForResource(resource)
}),
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.ConfigInformers.ForResource(resource)
}),
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.ImageInformers.ForResource(resource)
}),
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.QuotaInformers.ForResource(resource)
}),
// fallback to metadata shared informers
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.RouteInformers.ForResource(resource)
}),
genericinformers.GenericResourceInformerFunc(func(resource schema.GroupVersionResource) (informers.GenericInformer, error) {
return c.TemplateInformers.ForResource(resource)
return c.MetadataInformers.ForResource(resource), nil
}),
)
}
Expand All @@ -161,16 +117,10 @@ type EnhancedControllerContext struct {
ClientBuilder ControllerClientBuilder

KubernetesInformers informers.SharedInformerFactory
MetadataInformers metadatainformer.SharedInformerFactory

TemplateInformers templateinformer.SharedInformerFactory
QuotaInformers quotainformer.SharedInformerFactory
RouteInformers routeinformer.SharedInformerFactory

AppsInformers appsinformer.SharedInformerFactory
BuildInformers buildinformer.SharedInformerFactory
ConfigInformers configinformer.SharedInformerFactory
ImageInformers imageinformer.SharedInformerFactory
OperatorInformers operatorinformer.SharedInformerFactory
SecurityInformers securityinformer.SharedInformerFactory

GenericResourceInformer genericinformers.GenericResourceInformer
Expand All @@ -185,16 +135,11 @@ type EnhancedControllerContext struct {
func (c *EnhancedControllerContext) StartInformers(stopCh <-chan struct{}) {
c.KubernetesInformers.Start(stopCh)

c.AppsInformers.Start(stopCh)
c.BuildInformers.Start(stopCh)
c.ConfigInformers.Start(stopCh)
c.ImageInformers.Start(stopCh)
c.SecurityInformers.Start(stopCh)

c.TemplateInformers.Start(stopCh)
c.QuotaInformers.Start(stopCh)
c.RouteInformers.Start(stopCh)
c.OperatorInformers.Start(stopCh)

c.MetadataInformers.Start(stopCh)

c.informersStartedLock.Lock()
defer c.informersStartedLock.Unlock()
Expand All @@ -211,30 +156,14 @@ func (c *EnhancedControllerContext) IsControllerEnabled(name string) bool {
type ControllerClientBuilder interface {
clientbuilder.ControllerClientBuilder

OpenshiftAppsClient(name string) (appsclient.Interface, error)
OpenshiftAppsClientOrDie(name string) appsclient.Interface

OpenshiftBuildClient(name string) (buildclient.Interface, error)
OpenshiftBuildClientOrDie(name string) buildclient.Interface

OpenshiftConfigClient(name string) (configclient.Interface, error)
OpenshiftConfigClientOrDie(name string) configclient.Interface

OpenshiftSecurityClient(name string) (securityinternalclient.Interface, error)
OpenshiftSecurityClientOrDie(name string) securityinternalclient.Interface

// OpenShift clients based on generated internal clientsets
OpenshiftTemplateClient(name string) (templateclient.Interface, error)
OpenshiftTemplateClientOrDie(name string) templateclient.Interface

OpenshiftImageClient(name string) (imageclient.Interface, error)
OpenshiftImageClientOrDie(name string) imageclient.Interface

OpenshiftQuotaClient(name string) (quotaclient.Interface, error)
OpenshiftQuotaClientOrDie(name string) quotaclient.Interface

OpenshiftOperatorClient(name string) (operatorclient.Interface, error)
OpenshiftOperatorClientOrDie(name string) operatorclient.Interface
}

// InitFunc is used to launch a particular controller. It may run additional "should I activate checks".
Expand All @@ -246,44 +175,6 @@ type OpenshiftControllerClientBuilder struct {
clientbuilder.ControllerClientBuilder
}

func (b OpenshiftControllerClientBuilder) OpenshiftOperatorClient(name string) (operatorclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return operatorclient.NewForConfig(clientConfig)
}

func (b OpenshiftControllerClientBuilder) OpenshiftOperatorClientOrDie(name string) operatorclient.Interface {
client, err := b.OpenshiftOperatorClient(name)
if err != nil {
klog.Fatal(err)
}
return client
}

// OpenshiftInternalTemplateClient provides a REST client for the template API.
// If the client cannot be created because of configuration error, this function
// will return an error.
func (b OpenshiftControllerClientBuilder) OpenshiftTemplateClient(name string) (templateclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return templateclient.NewForConfig(clientConfig)
}

// OpenshiftInternalTemplateClientOrDie provides a REST client for the template API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftTemplateClientOrDie(name string) templateclient.Interface {
client, err := b.OpenshiftTemplateClient(name)
if err != nil {
klog.Fatal(err)
}
return client
}

// OpenshiftImageClient provides a REST client for the image API.
// If the client cannot be created because of configuration error, this function
// will error.
Expand All @@ -306,72 +197,6 @@ func (b OpenshiftControllerClientBuilder) OpenshiftImageClientOrDie(name string)
return client
}

// OpenshiftAppsClient provides a REST client for the apps API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftAppsClient(name string) (appsclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return appsclient.NewForConfig(clientConfig)
}

// OpenshiftAppsClientOrDie provides a REST client for the apps API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftAppsClientOrDie(name string) appsclient.Interface {
client, err := b.OpenshiftAppsClient(name)
if err != nil {
klog.Fatal(err)
}
return client
}

// OpenshiftBuildClient provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftBuildClient(name string) (buildclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return buildclient.NewForConfig(clientConfig)
}

// OpenshiftBuildClientOrDie provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftBuildClientOrDie(name string) buildclient.Interface {
client, err := b.OpenshiftBuildClient(name)
if err != nil {
klog.Fatal(err)
}
return client
}

// OpenshiftConfigClient provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftConfigClient(name string) (configclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return configclient.NewForConfig(nonProtobufConfig(clientConfig))
}

// OpenshiftConfigClientOrDie provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftConfigClientOrDie(name string) configclient.Interface {
client, err := b.OpenshiftConfigClient(name)
if err != nil {
klog.Fatal(err)
}
return client
}

func (b OpenshiftControllerClientBuilder) OpenshiftQuotaClient(name string) (quotaclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
Expand Down
8 changes: 0 additions & 8 deletions vendor/github.com/openshift/api/route/v1/doc.go

This file was deleted.

0 comments on commit a83965e

Please sign in to comment.