-
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#17660 from barrettj12/ctrl-modelid-ctx
juju#17660 <!-- Why this change is needed and what it does. --> This PR fixes a chicken-and-egg problem in setting up the apiserver. Previously we were given just a service factory getter. We needed to pass in the controller model UUID to obtain the service factory (for the controller model). However, we needed the service factory to get the controller model UUID. To get around this, we were using a nasty hack where we passed in the controller namespace (not UUID). This worked because the controller service factory methods don't depend on the UUID passed in. (In fact, any string would have worked). Then we could obtain the controller UUID from this "false" service factory, and pass it back in to the service factory getter to get the "real" service factory. Something like this: ```go // the arg here should be a model UUID, but we don't have this yet fakeServiceFactory := serviceFactoryGetter.FactoryForModel(database.ControllerNS) controllerModel, err := fakeServiceFactory.Model().ControllerModel(ctx) if err != nil { ... } realServiceFactory := serviceFactoryGetter.FactoryForModel(controllerModel.UUID.String()) ... ``` To fix this, we add the `controllerModelID` as a field to `apiserver.ServerConfig` and `api.sharedServerContext`. Then, we will always have the controller model UUID when we need it to pass in to the service factory getter. To nudge developers in the right direction, I've changed the arg type of `ServiceFactoryGetter.FactoryForModel` to `core/model.UUID`: ```go type ServiceFactoryGetter interface { // FactoryForModel returns a ServiceFactory for the given model. FactoryForModel(modelID model.UUID) ServiceFactory } ``` This should reduce the temptation to pass in a namespace or fake value that is not a valid model UUID. Drive-bys: - move apiserver worker services to `service.go` - change some instances of `modelUUID string` to `modelID model.UUID` ## Checklist <!-- If an item is not applicable, use `~strikethrough~`. --> - [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 <!-- Describe steps to verify that the change works. --> Bootstrap Juju and run `smoke` tests. Check that the GitHub actions pass below. ## Links <!-- Link to all relevant specification, documentation, bug, issue or JIRA card. --> **Jira card:** JUJU-6323
- Loading branch information
Showing
44 changed files
with
256 additions
and
97 deletions.
There are no files selected for viewing
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
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
7 changes: 4 additions & 3 deletions
7
apiserver/facades/controller/migrationtarget/servicefactory_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
Oops, something went wrong.