Skip to content

Commit

Permalink
refactor(internal/jimm/jimm.go): introduces a jimm constructor
Browse files Browse the repository at this point in the history
- adds jimmtest.NewJIMM
  • Loading branch information
alesstimec committed Dec 4, 2024
1 parent ba1f73a commit b1e3f3c
Show file tree
Hide file tree
Showing 41 changed files with 1,014 additions and 1,760 deletions.
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func initializeEnvironment(c *gc.C, ctx context.Context, db *db.Database, u dbmo
}

func (s *relationSuite) TestListRelations(c *gc.C) {
env := initializeEnvironment(c, context.Background(), &s.JIMM.Database, *s.AdminUser)
env := initializeEnvironment(c, context.Background(), s.JIMM.Database, *s.AdminUser)
bClient := s.SetupCLIAccess(c, "alice") // alice is superuser

relations := []apiparams.RelationshipTuple{{
Expand Down Expand Up @@ -420,7 +420,7 @@ func (s *relationSuite) TestListRelations(c *gc.C) {
}

func (s *relationSuite) TestListRelationsWithError(c *gc.C) {
env := initializeEnvironment(c, context.Background(), &s.JIMM.Database, *s.AdminUser)
env := initializeEnvironment(c, context.Background(), s.JIMM.Database, *s.AdminUser)
// alice is superuser
bClient := s.SetupCLIAccess(c, "alice")

Expand Down
28 changes: 3 additions & 25 deletions cmd/jimmsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func start(ctx context.Context, s *service.Service) error {

logSQL, _ := strconv.ParseBool(os.Getenv("JIMM_LOG_SQL"))

jimmsvc, err := jimmsvc.NewService(ctx, jimmsvc.Params{
jimmsvc, startServices, err := jimmsvc.NewService(ctx, jimmsvc.Params{
ControllerUUID: os.Getenv("JIMM_UUID"),
DSN: os.Getenv("JIMM_DSN"),
ControllerAdmins: strings.Fields(os.Getenv("JIMM_ADMINS")),
Expand Down Expand Up @@ -183,35 +183,13 @@ func start(ctx context.Context, s *service.Service) error {
CorsAllowedOrigins: corsAllowedOrigins,
LogSQL: logSQL,
LogLevel: logLevel,
IsLeader: os.Getenv("JIMM_IS_LEADER") != "",
})
if err != nil {
return err
}

isLeader := os.Getenv("JIMM_IS_LEADER") != ""
if isLeader {
s.Go(func() error { return jimmsvc.WatchControllers(ctx) }) // Deletes dead/dying models, updates model config.
}
s.Go(func() error { return jimmsvc.WatchModelSummaries(ctx) })

if isLeader {
zapctx.Info(ctx, "attempting to start JWKS rotator and generate OAuth secret key")
s.Go(func() error {
if err := jimmsvc.StartJWKSRotator(ctx, time.NewTicker(time.Hour).C, time.Now().UTC().AddDate(0, 3, 0)); err != nil {
zapctx.Error(ctx, "failed to start JWKS rotator", zap.Error(err))
return err
}
return nil
})
s.Go(func() error {
return jimmsvc.OpenFGACleanup(ctx, time.NewTicker(6*time.Hour).C)
})
}

if isLeader {
// No need for s.Go() since this routine doesn't return an error.
go jimmsvc.MonitorResources(ctx)
}
startServices(s)

httpsrv := &http.Server{
Addr: addr,
Expand Down
Loading

0 comments on commit b1e3f3c

Please sign in to comment.