Skip to content

Commit

Permalink
Merge pull request juju#17165 from SimonRichardson/service-factory-wi…
Browse files Browse the repository at this point in the history
…th-provider

juju#17165

The following exposes the provider tracker to the service
factory. The service factory now takes a IAAS and CAAS provider
tracker. Initially it was hoped that you could use the generic
provider tracker directly, but for controllers with both IAAS
and CAAS mode types this isn't possible. We do need to expose both
at the service factory level.

The service that requires a provider can then create a local interface
that implements some functionality of an environ. For instance the
network domain service could expose that it would like a provider
that supports networking:

 type Provider interface {
 environs.Networking
 }

The service then takes a `providertracker.ProviderGetter[Provider]`,
which will hand out providers. If the service requires to work on
both IAAS and CAAS, then two provider getters will needed as dependencies.

To provide the provider getter to the service, the service factory
needs to supply the right provider.

 providertracker.ProviderRunner[networkservice.Provider](s.providerFactory, s.modelUUID.String())

Using a provider runner we can late bind the provider for the model
UUID, so the error surfaces on use of the service method. This is
akin to the DB pattern we currently have.

This ProviderRunner replaces the SupportsNetworking and other
environs casting functions. Ideally the casting functions in the
environs package can be removed.

The only concern with this change, is that the core/providertracker
package is bringing in the environs package. It's clear that it
_should_ live there, it just breaks one of the rules of the core
package.

<!-- Why this change is needed and what it does. -->

## 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

## QA steps

```sh
$ juju bootstrap lxd test
$ juju add-model test
$ juju deploy ubuntu
```

## Links

**Jira card:** JUJU-5644
  • Loading branch information
jujubot authored Apr 10, 2024
2 parents d61ecc2 + 48f44b2 commit fb2ff5a
Show file tree
Hide file tree
Showing 28 changed files with 1,423 additions and 154 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/jujud-controller/agent/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ func (a *MachineAgent) makeEngineCreator(
CharmhubHTTPClient: charmhubHTTPClient,
S3HTTPClient: s3HTTPClient,
NewEnvironFunc: newEnvirons,
NewCAASBrokerFunc: newCAASBroker,
}
manifolds := iaasMachineManifolds(manifoldsCfg)
if a.isCaasAgent {
Expand Down
36 changes: 35 additions & 1 deletion cmd/jujud-controller/agent/machine/manifolds.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/juju/juju/api"
"github.com/juju/juju/api/base"
"github.com/juju/juju/api/controller/crosscontroller"
"github.com/juju/juju/caas"
"github.com/juju/juju/cmd/jujud-controller/util"
"github.com/juju/juju/core/instance"
corelogger "github.com/juju/juju/core/logger"
Expand Down Expand Up @@ -93,6 +94,7 @@ import (
"github.com/juju/juju/internal/worker/peergrouper"
prworker "github.com/juju/juju/internal/worker/presence"
"github.com/juju/juju/internal/worker/providerservicefactory"
"github.com/juju/juju/internal/worker/providertracker"
"github.com/juju/juju/internal/worker/provisioner"
"github.com/juju/juju/internal/worker/proxyupdater"
psworker "github.com/juju/juju/internal/worker/pubsub"
Expand Down Expand Up @@ -280,9 +282,13 @@ type ManifoldsConfig struct {

// S3HTTPClient is the HTTP client used for S3 API requests.
S3HTTPClient HTTPClient

// NewEnvironFunc is a function opens a provider "environment"
// (typically environs.New).
NewEnvironFunc func(context.Context, environs.OpenParams) (environs.Environ, error)

// NewCAASBrokerFunc is a function opens a CAAS broker.
NewCAASBrokerFunc func(context.Context, environs.OpenParams) (caas.Broker, error)
}

type HTTPClient interface {
Expand Down Expand Up @@ -722,11 +728,13 @@ func commonManifolds(config ManifoldsConfig) dependency.Manifolds {
serviceFactoryName: workerservicefactory.Manifold(workerservicefactory.ManifoldConfig{
DBAccessorName: dbAccessorName,
ChangeStreamName: changeStreamName,
ProviderFactoryName: iaasProviderTrackerName,
BrokerFactoryName: caasProviderTrackerName,
Logger: workerservicefactory.NewLogger("juju.worker.servicefactory"),
NewWorker: workerservicefactory.NewWorker,
NewServiceFactoryGetter: workerservicefactory.NewServiceFactoryGetter,
NewControllerServiceFactory: workerservicefactory.NewControllerServiceFactory,
NewModelServiceFactory: workerservicefactory.NewModelServiceFactory,
NewModelServiceFactory: workerservicefactory.NewProviderTrackerModelServiceFactory,
}),

providerServiceFactoryName: providerservicefactory.Manifold(providerservicefactory.ManifoldConfig{
Expand Down Expand Up @@ -865,6 +873,30 @@ func commonManifolds(config ManifoldsConfig) dependency.Manifolds {
GetControllerConfigService: objectstores3caller.GetControllerConfigService,
NewWorker: objectstores3caller.NewWorker,
})),

caasProviderTrackerName: ifDatabaseUpgradeComplete(providertracker.MultiTrackerManifold[caas.Broker](providertracker.ManifoldConfig[caas.Broker]{
ProviderServiceFactoriesName: providerServiceFactoryName,
NewWorker: providertracker.NewWorker[caas.Broker],
NewTrackerWorker: providertracker.NewTrackerWorker[caas.Broker],
GetProviderServiceFactoryGetter: providertracker.GetProviderServiceFactoryGetter,
GetProvider: providertracker.CAASGetProvider(func(ctx context.Context, args environs.OpenParams) (caas.Broker, error) {
return config.NewCAASBrokerFunc(ctx, args)
}),
Logger: loggo.GetLogger("juju.worker.caasprovidertracker"),
Clock: config.Clock,
})),

iaasProviderTrackerName: ifDatabaseUpgradeComplete(providertracker.MultiTrackerManifold[environs.Environ](providertracker.ManifoldConfig[environs.Environ]{
ProviderServiceFactoriesName: providerServiceFactoryName,
NewWorker: providertracker.NewWorker[environs.Environ],
NewTrackerWorker: providertracker.NewTrackerWorker[environs.Environ],
GetProviderServiceFactoryGetter: providertracker.GetProviderServiceFactoryGetter,
GetProvider: providertracker.IAASGetProvider(func(ctx context.Context, args environs.OpenParams) (environs.Environ, error) {
return config.NewEnvironFunc(ctx, args)
}),
Logger: loggo.GetLogger("juju.worker.iaasprovidertracker"),
Clock: config.Clock,
})),
}

return manifolds
Expand Down Expand Up @@ -1327,6 +1359,8 @@ const (
leaseManagerName = "lease-manager"
stateConverterName = "state-converter"
serviceFactoryName = "service-factory"
caasProviderTrackerName = "caas-provider-tracker"
iaasProviderTrackerName = "iaas-provider-tracker"
providerServiceFactoryName = "provider-service-factory"
lxdContainerProvisioner = "lxd-container-provisioner"
controllerAgentConfigName = "controller-agent-config"
Expand Down
Loading

0 comments on commit fb2ff5a

Please sign in to comment.