Skip to content

Commit

Permalink
fix rebase conflicts
Browse files Browse the repository at this point in the history
fix migration

fix
  • Loading branch information
SimoneDutto committed Dec 10, 2024
1 parent 2de7fe8 commit a5d440f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 40 deletions.
10 changes: 5 additions & 5 deletions cmd/jimmsrv/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,6 @@ func NewService(ctx context.Context, p Params) (*Service, error) {
func (s *Service) StartServices(ctx context.Context, svc *service.Service) {
// on the leader unit we start additional routines
if s.isLeader {
// the leader unit connects to all controllers' AllWatcher
svc.Go(func() error {
return s.WatchControllers(ctx)
})

// audit log cleanup routine
if s.auditLogCleanupPeriod != 0 {
svc.Go(func() error {
Expand All @@ -529,6 +524,11 @@ func (s *Service) StartServices(ctx context.Context, svc *service.Service) {
svc.Go(func() error {
return s.OpenFGACleanup(ctx, time.NewTicker(6*time.Hour).C)
})

// CleanupDyingModels cleanup - cleans up all dying models
svc.Go(func() error {
return s.CleanupDyingModels(ctx, time.NewTicker(time.Minute).C)
})
}

// all units periodically update their controller/model metrics
Expand Down
2 changes: 2 additions & 0 deletions internal/dbmodel/sql/postgres/1_17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
ALTER TABLE models DROP COLUMN default_series, DROP COLUMN migration_controller_id, DROP COLUMN is_controller, DROP COLUMN cores,
DROP COLUMN machines, DROP COLUMN units, DROP COLUMN type, DROP COLUMN status_status, DROP COLUMN status_info, DROP COLUMN status_data,
DROP COLUMN status_since, DROP COLUMN status_version, DROP COLUMN sla_level, DROP COLUMN sla_owner;

UPDATE versions SET major=1, minor=17 WHERE component='jimmdb';
11 changes: 1 addition & 10 deletions internal/jimm/model_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (

qt "github.com/frankban/quicktest"
"github.com/frankban/quicktest/qtsuite"
"github.com/google/uuid"
jujuparams "github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
"github.com/juju/names/v5"

"github.com/canonical/jimm/v3/internal/db"
"github.com/canonical/jimm/v3/internal/dbmodel"
"github.com/canonical/jimm/v3/internal/errors"
"github.com/canonical/jimm/v3/internal/jimm"
Expand Down Expand Up @@ -91,17 +89,10 @@ type modelCleanupSuite struct {

func (s *modelCleanupSuite) Init(c *qt.C) {
ctx := context.Background()
// Setup DB
var err error
s.ofgaClient, _, _, err = jimmtest.SetupTestOFGAClient(c.Name())
c.Assert(err, qt.IsNil)
s.jimm = &jimm.JIMM{
UUID: uuid.NewString(),
OpenFGAClient: s.ofgaClient,
Database: db.Database{
DB: jimmtest.PostgresDB(c, time.Now),
},
}
s.jimm = jimmtest.NewJIMM(c, nil)
err = s.jimm.Database.Migrate(ctx, false)
c.Assert(err, qt.IsNil)
s.jimmAdmin, err = s.jimm.GetUser(ctx, "[email protected]")
Expand Down
19 changes: 5 additions & 14 deletions internal/jimm/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/juju/juju/core/life"
"github.com/juju/juju/rpc/params"
jujuparams "github.com/juju/juju/rpc/params"
Expand All @@ -22,7 +21,6 @@ import (
"github.com/juju/version/v2"
"sigs.k8s.io/yaml"

"github.com/canonical/jimm/v3/internal/db"
"github.com/canonical/jimm/v3/internal/dbmodel"
"github.com/canonical/jimm/v3/internal/errors"
"github.com/canonical/jimm/v3/internal/jimm"
Expand Down Expand Up @@ -1760,23 +1758,16 @@ func TestModelSummaries(t *testing.T) {
c := qt.New(t)
ctx := context.Background()

client, _, _, err := jimmtest.SetupTestOFGAClient(c.Name())
c.Assert(err, qt.IsNil)
j := &jimm.JIMM{
UUID: uuid.NewString(),
OpenFGAClient: client,
Database: db.Database{
DB: jimmtest.PostgresDB(c, nil),
},
}
err = j.Database.Migrate(ctx, false)
j := jimmtest.NewJIMM(c, nil)

err := j.Database.Migrate(ctx, false)
c.Assert(err, qt.IsNil)

env := jimmtest.ParseEnvironment(c, modelSummariesTestEnv)
env.PopulateDBAndPermissions(c, j.ResourceTag(), j.Database, client)
env.PopulateDBAndPermissions(c, j.ResourceTag(), j.Database, j.OpenFGAClient)

dbUser := env.User("[email protected]").DBObject(c, j.Database)
alice := openfga.NewUser(&dbUser, client)
alice := openfga.NewUser(&dbUser, j.OpenFGAClient)

tests := []struct {
description string
Expand Down
6 changes: 3 additions & 3 deletions internal/jimm/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestModelSummaryWatcher(t *testing.T) {

w := &jimm.Watcher{
Pubsub: publisher,
Database: db.Database{
Database: &db.Database{
DB: jimmtest.PostgresDB(c, nil),
},
Dialer: &jimmtest.Dialer{
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestWatcherSetsControllerUnavailable(t *testing.T) {

controllerUnavailableChannel := make(chan error, 1)
w := jimm.NewWatcherWithControllerUnavailableChan(
db.Database{
&db.Database{
DB: jimmtest.PostgresDB(c, nil),
},
&jimmtest.Dialer{
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestWatcherClearsControllerUnavailable(t *testing.T) {
defer cancel()

w := jimm.Watcher{
Database: db.Database{
Database: &db.Database{
DB: jimmtest.PostgresDB(c, nil),
},
Dialer: &jimmtest.Dialer{
Expand Down
8 changes: 0 additions & 8 deletions internal/testutils/jimmtest/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package jimmtest
import (
"context"
"database/sql"
"time"

petname "github.com/dustinkirkland/golang-petname"
qt "github.com/frankban/quicktest"
Expand Down Expand Up @@ -94,13 +93,6 @@ func CreateTestControllerEnvironment(ctx context.Context, c *qt.C, db *db.Databa
CloudRegionID: cloud.Regions[0].ID,
CloudCredentialID: cred.ID,
Life: state.Alive.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Time: time.Now().UTC().Truncate(time.Millisecond),
Valid: true,
},
},
}

err = db.AddModel(ctx, &model)
Expand Down

0 comments on commit a5d440f

Please sign in to comment.