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

replace shared-informers' methods with cached client #461

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/registration-service/pkg/auth"
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/pkg/informers"
"github.com/codeready-toolchain/registration-service/pkg/log"
"github.com/codeready-toolchain/registration-service/pkg/proxy"
"github.com/codeready-toolchain/registration-service/pkg/proxy/metrics"
Expand Down Expand Up @@ -85,12 +84,7 @@ func main() {
}
}

informer, informerShutdown, err := informers.StartInformer(cfg)
if err != nil {
panic(err.Error())
}

app, err := server.NewInClusterApplication(*informer)
app, err := server.NewInClusterApplication(cl)
if err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -121,11 +115,6 @@ func main() {
}
proxySrv := p.StartProxy(proxy.DefaultPort)

// stop the informer when proxy server shuts down
proxySrv.RegisterOnShutdown(func() {
informerShutdown <- struct{}{}
})

// ---------------------------------------------
// Registration Service
// ---------------------------------------------
Expand Down Expand Up @@ -202,7 +191,17 @@ func newCachedClient(ctx context.Context, cfg *rest.Config) (client.Client, erro

// populate the cache backed by shared informers that are initialized lazily on the first call
// for the given GVK with all resources we are interested in from the host-operator namespace
objectsToList := []client.ObjectList{&toolchainv1alpha1.ToolchainConfigList{}, &corev1.SecretList{}}
objectsToList := []client.ObjectList{
&toolchainv1alpha1.MasterUserRecordList{},
&toolchainv1alpha1.SpaceList{},
&toolchainv1alpha1.SpaceBindingList{},
&toolchainv1alpha1.ToolchainStatusList{},
&toolchainv1alpha1.UserSignupList{},
&toolchainv1alpha1.ProxyPluginList{},
&toolchainv1alpha1.NSTemplateTierList{},
&toolchainv1alpha1.ToolchainConfigList{},
&toolchainv1alpha1.BannedUserList{},
&corev1.SecretList{}}
for i := range objectsToList {
if err := hostCluster.GetClient().List(ctx, objectsToList[i], client.InNamespace(configuration.Namespace())); err != nil {
return nil, err
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ require (
cloud.google.com/go/auth v0.3.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.11.2 // indirect
Expand All @@ -67,6 +71,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
Expand All @@ -77,7 +82,12 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/migueleliasweb/go-github-mock v0.0.18 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/redhat-cop/operator-utils v1.3.3-0.20220121120056-862ef22b8cdf // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
Expand All @@ -94,6 +104,7 @@ require (
google.golang.org/grpc v1.63.2 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/kubectl v0.24.0 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
)

Expand Down
776 changes: 776 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/application/service/context/service_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package context

import (
"github.com/codeready-toolchain/registration-service/pkg/application/service"
"github.com/codeready-toolchain/registration-service/pkg/informers"
"github.com/codeready-toolchain/registration-service/pkg/kubeclient"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type ServiceContextProducer func() ServiceContext

type ServiceContext interface {
CRTClient() kubeclient.CRTClient
Informer() informers.Informer
Client() client.Client
Services() service.Services
}
14 changes: 7 additions & 7 deletions pkg/application/service/factory/service_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"github.com/codeready-toolchain/registration-service/pkg/application/service"
servicecontext "github.com/codeready-toolchain/registration-service/pkg/application/service/context"
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/pkg/informers"
informerservice "github.com/codeready-toolchain/registration-service/pkg/informers/service"
"github.com/codeready-toolchain/registration-service/pkg/kubeclient"
"github.com/codeready-toolchain/registration-service/pkg/log"
clusterservice "github.com/codeready-toolchain/registration-service/pkg/proxy/service"
signupservice "github.com/codeready-toolchain/registration-service/pkg/signup/service"
verificationservice "github.com/codeready-toolchain/registration-service/pkg/verification/service"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type serviceContextImpl struct {
kubeClient kubeclient.CRTClient
informer informers.Informer
client client.Client
services service.Services
}

Expand All @@ -29,14 +29,14 @@ func CRTClientOption(kubeClient kubeclient.CRTClient) ServiceContextOption {
}
}

func InformerOption(informer informers.Informer) ServiceContextOption {
func InformerOption(client client.Client) ServiceContextOption {
return func(ctx *serviceContextImpl) {
ctx.informer = informer
ctx.client = client
}
}

func (s *serviceContextImpl) Informer() informers.Informer {
return s.informer
func (s *serviceContextImpl) Client() client.Client {
return s.client
}

func (s *serviceContextImpl) CRTClient() kubeclient.CRTClient {
Expand Down Expand Up @@ -65,7 +65,7 @@ func (s *ServiceFactory) defaultServiceContextProducer() servicecontext.ServiceC
}

func (s *ServiceFactory) InformerService() service.InformerService {
return informerservice.NewInformerService(s.getContext())
return informerservice.NewInformerService(s.getContext().Client(), configuration.Namespace())
}

func (s *ServiceFactory) MemberClusterService() service.MemberClusterService {
Expand Down
104 changes: 0 additions & 104 deletions pkg/informers/informers.go

This file was deleted.

Loading
Loading