Skip to content

Commit

Permalink
drop InformerService
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek committed Oct 9, 2024
1 parent 4797d02 commit 4d9b4d5
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 415 deletions.
8 changes: 5 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/codeready-toolchain/registration-service/pkg/auth"
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/pkg/log"
"github.com/codeready-toolchain/registration-service/pkg/namespaced"
"github.com/codeready-toolchain/registration-service/pkg/proxy"
"github.com/codeready-toolchain/registration-service/pkg/proxy/metrics"
"github.com/codeready-toolchain/registration-service/pkg/server"
Expand Down Expand Up @@ -83,8 +84,9 @@ func main() {
panic(fmt.Sprintf("cannot set captcha credentials: %s", err.Error()))
}
}
nsClient := namespaced.NewClient(cl, configuration.Namespace())

app := server.NewInClusterApplication(cl, configuration.Namespace())
app := server.NewInClusterApplication(nsClient)
// Initialize toolchain cluster cache service
// let's cache the member clusters before we start the services,
// this will speed up the first request
Expand All @@ -106,7 +108,7 @@ func main() {
proxyMetrics := metrics.NewProxyMetrics(proxyRegistry)
proxyMetricsSrv := proxy.StartMetricsServer(proxyRegistry, proxy.ProxyMetricsPort)
// Proxy API server
p, err := proxy.NewProxy(app, proxyMetrics, cluster.GetMemberClusters)
p, err := proxy.NewProxy(nsClient, app, proxyMetrics, cluster.GetMemberClusters)
if err != nil {
panic(errs.Wrap(err, "failed to create proxy"))
}
Expand All @@ -118,7 +120,7 @@ func main() {
regsvcRegistry := prometheus.NewRegistry()
regsvcMetricsSrv, _ := server.StartMetricsServer(regsvcRegistry, server.RegSvcMetricsPort)
regsvcSrv := server.New(app)
err = regsvcSrv.SetupRoutes(proxy.DefaultPort, regsvcRegistry)
err = regsvcSrv.SetupRoutes(proxy.DefaultPort, regsvcRegistry, nsClient)
if err != nil {
panic(err.Error())
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/application/service/factory/service_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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"
informerservice "github.com/codeready-toolchain/registration-service/pkg/informers/service"
"github.com/codeready-toolchain/registration-service/pkg/log"
"github.com/codeready-toolchain/registration-service/pkg/namespaced"
clusterservice "github.com/codeready-toolchain/registration-service/pkg/proxy/service"
Expand Down Expand Up @@ -52,10 +51,6 @@ func (s *ServiceFactory) defaultServiceContextProducer() servicecontext.ServiceC
}
}

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

func (s *ServiceFactory) MemberClusterService() service.MemberClusterService {
return clusterservice.NewMemberClusterService(s.getContext().Client(), s.getContext().Services().SignupService())
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/application/service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ import (
"github.com/codeready-toolchain/registration-service/pkg/proxy/access"
"github.com/codeready-toolchain/registration-service/pkg/signup"
"github.com/gin-gonic/gin"
"k8s.io/apimachinery/pkg/labels"
)

type InformerService interface {
GetMasterUserRecord(name string) (*toolchainv1alpha1.MasterUserRecord, error)
GetSpace(name string) (*toolchainv1alpha1.Space, error)
ListSpaceBindings(reqs ...labels.Requirement) ([]toolchainv1alpha1.SpaceBinding, error)
GetNSTemplateTier(name string) (*toolchainv1alpha1.NSTemplateTier, error)
ListBannedUsersByEmail(email string) ([]toolchainv1alpha1.BannedUser, error)
}

type SignupService interface {
Signup(ctx *gin.Context) (*toolchainv1alpha1.UserSignup, error)
GetSignup(ctx *gin.Context, userID, username string) (*signup.Signup, error)
Expand All @@ -25,10 +16,6 @@ type SignupService interface {
PhoneNumberAlreadyInUse(userID, username, phoneNumberOrHash string) error
}

type SocialEventService interface {
GetEvent(code string) (*toolchainv1alpha1.SocialEvent, error)
}

type VerificationService interface {
InitVerification(ctx *gin.Context, userID, username, e164PhoneNumber, countryCode string) error
VerifyPhoneCode(ctx *gin.Context, userID, username, code string) error
Expand All @@ -40,7 +27,6 @@ type MemberClusterService interface {
}

type Services interface {
InformerService() InformerService
SignupService() SignupService
VerificationService() VerificationService
MemberClusterService() MemberClusterService
Expand Down
12 changes: 7 additions & 5 deletions pkg/controller/usernames.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ package controller
import (
"net/http"

"github.com/codeready-toolchain/registration-service/pkg/application"
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
crterrors "github.com/codeready-toolchain/registration-service/pkg/errors"
"github.com/codeready-toolchain/registration-service/pkg/log"
"github.com/codeready-toolchain/registration-service/pkg/namespaced"
"github.com/codeready-toolchain/registration-service/pkg/username"
"github.com/gin-gonic/gin"
"k8s.io/apimachinery/pkg/api/errors"
)

// Usernames implements the usernames endpoint, which is invoked for checking if a given username/email exists.
type Usernames struct {
app application.Application
namespaced.Client
}

// NewUsernames returns a new Usernames instance.
func NewUsernames(app application.Application) *Usernames {
func NewUsernames(nsClient namespaced.Client) *Usernames {
return &Usernames{
app: app,
Client: nsClient,
}
}

Expand All @@ -34,7 +35,8 @@ func (s *Usernames) GetHandler(ctx *gin.Context) {
// TODO check if the queryString is an email
// in that case we have to fetch the UserSignup resources with the provided email and the MasterUserRecords associated with those.

murResource, err := s.app.InformerService().GetMasterUserRecord(queryString)
murResource := &toolchainv1alpha1.MasterUserRecord{}
err := s.Get(ctx.Request.Context(), s.NamespacedName(queryString), murResource)
// handle not found error
if errors.IsNotFound(err) {
log.Infof(ctx, "MasterUserRecord resource for: %s not found", queryString)
Expand Down
12 changes: 5 additions & 7 deletions pkg/controller/usernames_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/codeready-toolchain/registration-service/pkg/controller"
"github.com/codeready-toolchain/registration-service/pkg/informers/service"
"github.com/codeready-toolchain/registration-service/pkg/namespaced"
"github.com/codeready-toolchain/registration-service/pkg/username"
"github.com/codeready-toolchain/registration-service/test"
"github.com/codeready-toolchain/registration-service/test/fake"
Expand Down Expand Up @@ -40,11 +40,10 @@ func (s *TestUsernamesSuite) TestUsernamesGetHandler() {

s.Run("success", func() {

fakeInformer := service.NewInformerService(fakeClient, commontest.HostOperatorNs)
s.Application.MockInformerService(fakeInformer)
nsClient := namespaced.NewClient(fakeClient, commontest.HostOperatorNs)

// Create Usernames controller instance.
ctrl := controller.NewUsernames(s.Application)
ctrl := controller.NewUsernames(nsClient)
handler := gin.HandlerFunc(ctrl.GetHandler)

s.Run("usernames found", func() {
Expand Down Expand Up @@ -104,11 +103,10 @@ func (s *TestUsernamesSuite) TestUsernamesGetHandler() {
fakeClient.MockGet = func(_ context.Context, _ client.ObjectKey, _ client.Object, _ ...client.GetOption) error {
return fmt.Errorf("mock error")
}
fakeInformer := service.NewInformerService(fakeClient, commontest.HostOperatorNs)
s.Application.MockInformerService(fakeInformer)
nsClient := namespaced.NewClient(fakeClient, commontest.HostOperatorNs)

// Create Usernames controller instance.
ctrl := controller.NewUsernames(s.Application)
ctrl := controller.NewUsernames(nsClient)
handler := gin.HandlerFunc(ctrl.GetHandler)
s.Run("unable to get mur", func() {
// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
Expand Down
76 changes: 0 additions & 76 deletions pkg/informers/service/informer_service.go

This file was deleted.

Loading

0 comments on commit 4d9b4d5

Please sign in to comment.