From a5d440fc098c4226218fa0583bcaf822dbc842c1 Mon Sep 17 00:00:00 2001 From: SimoneDutto Date: Tue, 10 Dec 2024 12:36:46 +0100 Subject: [PATCH] fix rebase conflicts fix migration fix --- cmd/jimmsrv/service/service.go | 10 +++++----- internal/dbmodel/sql/postgres/1_17.sql | 2 ++ internal/jimm/model_cleanup_test.go | 11 +---------- internal/jimm/model_test.go | 19 +++++-------------- internal/jimm/watcher_test.go | 6 +++--- internal/testutils/jimmtest/fixture.go | 8 -------- 6 files changed, 16 insertions(+), 40 deletions(-) diff --git a/cmd/jimmsrv/service/service.go b/cmd/jimmsrv/service/service.go index 23b1c537f..29008dae5 100644 --- a/cmd/jimmsrv/service/service.go +++ b/cmd/jimmsrv/service/service.go @@ -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 { @@ -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 diff --git a/internal/dbmodel/sql/postgres/1_17.sql b/internal/dbmodel/sql/postgres/1_17.sql index 16b4393ec..e0adc1eeb 100644 --- a/internal/dbmodel/sql/postgres/1_17.sql +++ b/internal/dbmodel/sql/postgres/1_17.sql @@ -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'; diff --git a/internal/jimm/model_cleanup_test.go b/internal/jimm/model_cleanup_test.go index 2d647e3f6..3241a9dbd 100644 --- a/internal/jimm/model_cleanup_test.go +++ b/internal/jimm/model_cleanup_test.go @@ -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" @@ -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, "alice@canonical.com") diff --git a/internal/jimm/model_test.go b/internal/jimm/model_test.go index 88bd4a2e0..cd33831bd 100644 --- a/internal/jimm/model_test.go +++ b/internal/jimm/model_test.go @@ -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" @@ -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" @@ -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("alice@canonical.com").DBObject(c, j.Database) - alice := openfga.NewUser(&dbUser, client) + alice := openfga.NewUser(&dbUser, j.OpenFGAClient) tests := []struct { description string diff --git a/internal/jimm/watcher_test.go b/internal/jimm/watcher_test.go index 7a7798f98..80e24af81 100644 --- a/internal/jimm/watcher_test.go +++ b/internal/jimm/watcher_test.go @@ -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{ @@ -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{ @@ -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{ diff --git a/internal/testutils/jimmtest/fixture.go b/internal/testutils/jimmtest/fixture.go index b9458b534..3aa9b674c 100644 --- a/internal/testutils/jimmtest/fixture.go +++ b/internal/testutils/jimmtest/fixture.go @@ -5,7 +5,6 @@ package jimmtest import ( "context" "database/sql" - "time" petname "github.com/dustinkirkland/golang-petname" qt "github.com/frankban/quicktest" @@ -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)