-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#17006 from tlm/dqlite-model-migration
juju#17006 As part of moving the model manager facade over to DQlite we need to remove all usages of the model manager/model list structures in DQlite. These items were being used to get models registered in DQlite previously but have served their purpose. To remove the model manager service we have to get rid of all usages. One of these usages was in model migration where we would register the model with DQlite so we could make service factories on the newly minted model database. This was needed to so applications and machines could also be migrated. What this PR does is add model migration steps for models themselves and puts a very rough pass in for applications and machines to get them registered in DQlite during a migration. This allows for the service factories to be pulled out of the mongo state layer. With all of the above done we can now have the DQlite import steps run before that of Mongo as we have no dependency problems. ## Checklist - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing - ~[] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~ - ~[] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~ ## QA steps 1. Bootstrap two controllers that can reach each other. 2. On the first controller make a new model `test` 3. On the first controller deploy `postgresql` 4. Migrate the `test` model from the first controller to the second controller We are skipping these tests as part of the PR because migration is currently broken because of an sql failure in the object store. This will get tested soon when we have fixed that problem. ## Documentation changes N/A ## Links **Jira card:** JUJU-5600
- Loading branch information
Showing
26 changed files
with
814 additions
and
188 deletions.
There are no files selected for viewing
42 changes: 2 additions & 40 deletions
42
apiserver/facades/controller/migrationtarget/domain_mock_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package modelmigration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/juju/description/v5" | ||
"github.com/juju/loggo" | ||
|
||
"github.com/juju/juju/core/modelmigration" | ||
"github.com/juju/juju/domain/application/service" | ||
"github.com/juju/juju/domain/application/state" | ||
) | ||
|
||
var logger = loggo.GetLogger("juju.migration.applications") | ||
|
||
// Coordinator is the interface that is used to add operations to a migration. | ||
type Coordinator interface { | ||
Add(modelmigration.Operation) | ||
} | ||
|
||
// RegisterImport register's a new model migration importer into the supplied | ||
// coordinator. | ||
func RegisterImport(coordinator Coordinator) { | ||
coordinator.Add(&importOperation{}) | ||
} | ||
|
||
type importOperation struct { | ||
modelmigration.BaseOperation | ||
|
||
service ImportService | ||
} | ||
|
||
// ImportService defines the application service used to import applications | ||
// from another controller model to this controller. | ||
type ImportService interface { | ||
// CreateApplication registers the existence of an application in the model. | ||
CreateApplication(context.Context, string, service.AddApplicationParams, ...service.AddUnitParams) error | ||
} | ||
|
||
func (i *importOperation) Setup(scope modelmigration.Scope) error { | ||
i.service = service.NewService( | ||
state.NewState(scope.ModelDB(), logger), | ||
) | ||
return nil | ||
} | ||
|
||
func (i *importOperation) Execute(ctx context.Context, model description.Model) error { | ||
for _, app := range model.Applications() { | ||
unitArgs := make([]service.AddUnitParams, 0, len(app.Units())) | ||
for _, unit := range app.Units() { | ||
name := unit.Name() | ||
unitArgs = append(unitArgs, service.AddUnitParams{UnitName: &name}) | ||
} | ||
|
||
err := i.service.CreateApplication( | ||
ctx, app.Name(), service.AddApplicationParams{}, unitArgs..., | ||
) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"import model application %q with %d units: %w", | ||
app.Name(), len(app.Units()), err, | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package modelmigration | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/juju/description/v5" | ||
"github.com/juju/names/v5" | ||
jc "github.com/juju/testing/checkers" | ||
gomock "go.uber.org/mock/gomock" | ||
gc "gopkg.in/check.v1" | ||
|
||
"github.com/juju/juju/domain/application/service" | ||
) | ||
|
||
type importSuite struct { | ||
importService *MockImportService | ||
} | ||
|
||
var _ = gc.Suite(&importSuite{}) | ||
|
||
func (s *importSuite) setupMocks(c *gc.C) *gomock.Controller { | ||
ctrl := gomock.NewController(c) | ||
s.importService = NewMockImportService(ctrl) | ||
return ctrl | ||
} | ||
|
||
func (i *importSuite) TestApplicationSave(c *gc.C) { | ||
model := description.NewModel(description.ModelArgs{}) | ||
|
||
appArgs := description.ApplicationArgs{ | ||
Tag: names.NewApplicationTag("prometheus"), | ||
} | ||
model.AddApplication(appArgs).AddUnit(description.UnitArgs{ | ||
Tag: names.NewUnitTag("prometheus/0"), | ||
}) | ||
|
||
defer i.setupMocks(c).Finish() | ||
|
||
i.importService.EXPECT().CreateApplication( | ||
gomock.Any(), | ||
"prometheus", | ||
gomock.Any(), | ||
[]service.AddUnitParams{ | ||
{ | ||
ptrString("prometheus/0"), | ||
}, | ||
}, | ||
).Return(nil) | ||
|
||
importOp := importOperation{ | ||
service: i.importService, | ||
} | ||
|
||
err := importOp.Execute(context.Background(), model) | ||
c.Assert(err, jc.ErrorIsNil) | ||
} | ||
|
||
func ptrString(s string) *string { | ||
return &s | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.