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
  • Loading branch information
alesstimec committed Dec 3, 2024
1 parent 6031feb commit 30ce643
Show file tree
Hide file tree
Showing 38 changed files with 797 additions and 718 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: 2 additions & 26 deletions cmd/jimmsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,12 @@ func start(ctx context.Context, s *service.Service) error {
CorsAllowedOrigins: corsAllowedOrigins,
LogSQL: logSQL,
LogLevel: logLevel,
})
IsLeader: os.Getenv("JIMM_IS_LEADER") != "",
}, s)
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)
}

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

0 comments on commit 30ce643

Please sign in to comment.