Skip to content

Commit

Permalink
All: Juju now compiles
Browse files Browse the repository at this point in the history
Lots of tests are still failing here, but the idea is that
context.Context means something here and the fallout is quite large, but
worth while.
  • Loading branch information
SimonRichardson committed Jun 16, 2021
1 parent 836a526 commit 8899219
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 67 deletions.
5 changes: 3 additions & 2 deletions agent/agentbootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package agentbootstrap

import (
stdcontext "context"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -390,9 +391,9 @@ func getEnviron(
Config: modelConfig,
}
if cloudSpec.Type == cloud.CloudTypeCAAS {
return caas.Open(provider, openParams)
return caas.Open(stdcontext.TODO(), provider, openParams)
}
return environs.Open(provider, openParams)
return environs.Open(stdcontext.TODO(), provider, openParams)
}

func initRaft(agentConfig agent.Config) error {
Expand Down
4 changes: 3 additions & 1 deletion apiserver/common/credentialcommon/modelcredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package credentialcommon

import (
stdcontext "context"

"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/names/v4"
Expand Down Expand Up @@ -63,7 +65,7 @@ func ValidateNewModelCredential(backend PersistentBackend, callCtx context.Provi
}

func checkCAASModelCredential(brokerParams environs.OpenParams) (params.ErrorResults, error) {
broker, err := newCAASBroker(brokerParams)
broker, err := newCAASBroker(stdcontext.TODO(), brokerParams)
if err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
Expand Down
4 changes: 2 additions & 2 deletions apiserver/facades/client/modelmanager/modelmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type ModelManagerV2 interface {
ModelStatus(req params.Entities) (params.ModelStatusResults, error)
}

type newCaasBrokerFunc func(args environs.OpenParams) (caas.Broker, error)
type newCaasBrokerFunc func(_ stdcontext.Context, args environs.OpenParams) (caas.Broker, error)

// StatePool represents a point of use interface for getting the state from the
// pool.
Expand Down Expand Up @@ -622,7 +622,7 @@ func (m *ModelManagerAPI) newCAASModel(
if err != nil {
return nil, errors.Annotate(err, "getting controller config")
}
broker, err := m.getBroker(environs.OpenParams{
broker, err := m.getBroker(stdcontext.TODO(), environs.OpenParams{
ControllerUUID: controllerConfig.ControllerUUID(),
Cloud: cloudSpec,
Config: newConfig,
Expand Down
9 changes: 5 additions & 4 deletions caas/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package caas

import (
"context"
"fmt"

"github.com/juju/errors"
Expand Down Expand Up @@ -49,17 +50,17 @@ func RegisterContainerProvider(name string, p ContainerEnvironProvider, alias ..
}

// New returns a new broker based on the provided configuration.
func New(args environs.OpenParams) (Broker, error) {
func New(ctx context.Context, args environs.OpenParams) (Broker, error) {
p, err := environs.Provider(args.Cloud.Type)
if err != nil {
return nil, errors.Trace(err)
}
return Open(p, args)
return Open(ctx, p, args)
}

// Open creates a Broker instance and errors if the provider is not for
// a container substrate.
func Open(p environs.EnvironProvider, args environs.OpenParams) (Broker, error) {
func Open(ctx context.Context, p environs.EnvironProvider, args environs.OpenParams) (Broker, error) {
if envProvider, ok := p.(ContainerEnvironProvider); !ok {
return nil, errors.NotValidf("container environ provider %T", p)
} else {
Expand All @@ -68,7 +69,7 @@ func Open(p environs.EnvironProvider, args environs.OpenParams) (Broker, error)
}

// NewContainerBrokerFunc returns a Container Broker.
type NewContainerBrokerFunc func(args environs.OpenParams) (Broker, error)
type NewContainerBrokerFunc func(ctx context.Context, args environs.OpenParams) (Broker, error)

// StatusCallbackFunc represents a function that can be called to report a status.
type StatusCallbackFunc func(appName string, settableStatus status.Status, info string, data map[string]interface{}) error
Expand Down
3 changes: 2 additions & 1 deletion caas/kubernetes/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package provider

import (
stdcontext "context"
"net/url"

jujuclock "github.com/juju/clock"
Expand Down Expand Up @@ -44,7 +45,7 @@ var providerInstance = kubernetesEnvironProvider{
cmdRunner: defaultRunner{},
builtinCloudGetter: attemptMicroK8sCloud,
brokerGetter: func(args environs.OpenParams) (caas.ClusterMetadataChecker, error) {
return caas.New(args)
return caas.New(stdcontext.TODO(), args)
},
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/juju/caas/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package caas

import (
"bytes"
stdcontext "context"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -718,7 +719,7 @@ func (c *AddCAASCommand) newK8sClusterBroker(cloud jujucloud.Cloud, credential j
}
openParams.ControllerUUID = ctrlUUID
}
return caas.New(openParams)
return caas.New(stdcontext.TODO(), openParams)
}

func getCloudAndRegionFromOptions(cloudOption, regionOption string) (string, string, error) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/juju/caas/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package caas

import (
stdcontext "context"
"fmt"

"github.com/juju/cmd"
Expand Down Expand Up @@ -159,7 +160,7 @@ func (c *UpdateCAASCommand) newK8sClusterBroker(cloud jujucloud.Cloud, credentia
}
openParams.ControllerUUID = ctrlUUID
}
return caas.New(openParams)
return caas.New(stdcontext.TODO(), openParams)
}

// maybeBuiltInCloud returns a built in cloud (eg microk8s) and the relevant credential
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/commands/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) {
cfg, err := provider.PrepareConfig(*params)
c.Assert(err, jc.ErrorIsNil)

env, err := environs.New(environs.OpenParams{
env, err := environs.New(stdcontext.TODO(), environs.OpenParams{
Cloud: params.Cloud,
Config: cfg,
})
Expand Down
3 changes: 2 additions & 1 deletion cmd/juju/commands/upgrademodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package commands

import (
"bufio"
stdcontext "context"
stderrors "errors"
"fmt"
"io"
Expand Down Expand Up @@ -632,7 +633,7 @@ var getCAASBroker = func(getter environs.EnvironConfigGetter) (caas.Broker, erro
if err != nil {
return nil, errors.Trace(err)
}
env, err := caas.New(environs.OpenParams{
env, err := caas.New(stdcontext.TODO(), environs.OpenParams{
Cloud: cloudSpec,
Config: modelConfig,
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/juju/controller/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ func (c *destroyCommandBase) getControllerEnvironFromStore(
Config: cfg,
}
if bootstrapConfig.CloudType == cloud.CloudTypeCAAS {
return caas.New(openParams)
return caas.New(stdcontext.TODO(), openParams)
}
return environs.New(openParams)
return environs.New(stdcontext.TODO(), openParams)
}

func (c *destroyCommandBase) getControllerEnvironFromAPI(
Expand Down Expand Up @@ -611,7 +611,7 @@ func (c *destroyCommandBase) getControllerEnvironFromAPI(
if err != nil {
return nil, errors.Annotate(err, "getting controller config from API")
}
return environs.New(environs.OpenParams{
return environs.New(stdcontext.TODO(), environs.OpenParams{
ControllerUUID: ctrlCfg.ControllerUUID(),
Cloud: cloudSpec,
Config: cfg,
Expand Down
5 changes: 3 additions & 2 deletions cmd/juju/controller/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package controller

import (
stdcontext "context"
"fmt"
"time"

Expand Down Expand Up @@ -226,9 +227,9 @@ func (c *killCommand) DirectDestroyRemaining(ctx *cmd.Context, api destroyContro
}
var env environs.CloudDestroyer
if model.CloudSpec.Type == cloud.CloudTypeCAAS {
env, err = caas.Open(cloudProvider, openParams)
env, err = caas.Open(stdcontext.TODO(), cloudProvider, openParams)
} else {
env, err = environs.Open(cloudProvider, openParams)
env, err = environs.Open(stdcontext.TODO(), cloudProvider, openParams)
}
if err != nil {
logger.Errorf(err.Error())
Expand Down
7 changes: 5 additions & 2 deletions cmd/jujud/agent/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ func (c *BootstrapCommand) Run(_ *cmd.Context) error {
Cloud: cloudSpec,
Config: args.ControllerModelConfig,
}

ctx := stdcontext.TODO()

var env environs.BootstrapEnviron
if isCAAS {
env, err = environsNewCAAS(openParams)
env, err = environsNewCAAS(ctx, openParams)
} else {
env, err = environsNewIAAS(openParams)
env, err = environsNewIAAS(ctx, openParams)
}
if err != nil {
return errors.Trace(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jujud/agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func (s *BootstrapSuite) TestBootstrapWithInvalidCredentialLogs(c *gc.C) {
called := false
newEnviron := func(ps environs.OpenParams) (environs.Environ, error) {
called = true
env, _ := environs.New(ps)
env, _ := environs.New(context.TODO(), ps)
return &mockDummyEnviron{env}, nil
}
s.PatchValue(&environsNewIAAS, newEnviron)
Expand Down Expand Up @@ -792,7 +792,7 @@ func (s *BootstrapSuite) makeTestModel(c *gc.C) {
Config: cfg,
})
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Open(provider, environs.OpenParams{
env, err := environs.Open(context.TODO(), provider, environs.OpenParams{
Cloud: dummy.SampleCloudSpec(),
Config: cfg,
})
Expand Down
7 changes: 4 additions & 3 deletions cmd/plugins/juju-metadata/imagemetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"context"
"fmt"
"os"
"path/filepath"
Expand All @@ -26,12 +27,12 @@ import (
"github.com/juju/juju/version"
)

func prepare(context *cmd.Context, controllerName string, store jujuclient.ClientStore) (environs.Environ, error) {
func prepare(ctx *cmd.Context, controllerName string, store jujuclient.ClientStore) (environs.Environ, error) {
// NOTE(axw) this is a work-around for the TODO below. This
// means that the command will only work if you've bootstrapped
// the specified environment.
bootstrapConfig, params, err := modelcmd.NewGetBootstrapConfigParamsFunc(
context, store, environs.GlobalProviderRegistry(),
ctx, store, environs.GlobalProviderRegistry(),
)(controllerName)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -53,7 +54,7 @@ func prepare(context *cmd.Context, controllerName string, store jujuclient.Clien
// identify region and endpoint info that we need. Not sure what
// we'll do about simplestreams.MetadataValidator yet. Probably
// move it to the EnvironProvider interface.
return environs.New(environs.OpenParams{
return environs.New(context.TODO(), environs.OpenParams{
Cloud: params.Cloud,
Config: cfg,
})
Expand Down
2 changes: 1 addition & 1 deletion environs/bootstrap/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func PrepareController(
}
if isCAASController {
details.ModelType = model.CAAS
env, err = caas.Open(p, openParams)
env, err = caas.Open(ctx.Context(), p, openParams)
} else {
details.ModelType = model.IAAS
env, err = environs.Open(ctx.Context(), p, openParams)
Expand Down
6 changes: 4 additions & 2 deletions state/stateenvirons/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package stateenvirons

import (
"context"

"github.com/juju/errors"
"github.com/juju/names/v4"

Expand Down Expand Up @@ -54,7 +56,7 @@ func (g EnvironConfigGetter) CloudAPIVersion(spec environscloudspec.CloudSpec) (
if newBroker == nil {
newBroker = caas.New
}
broker, err := newBroker(environs.OpenParams{
broker, err := newBroker(context.TODO(), environs.OpenParams{
ControllerUUID: g.Model.ControllerUUID(),
Cloud: spec,
Config: cfg,
Expand Down Expand Up @@ -143,7 +145,7 @@ func GetNewCAASBrokerFunc(newBroker caas.NewContainerBrokerFunc) NewCAASBrokerFu
if err != nil {
return nil, errors.Trace(err)
}
return newBroker(environs.OpenParams{
return newBroker(context.TODO(), environs.OpenParams{
ControllerUUID: m.ControllerUUID(),
Cloud: cloudSpec,
Config: cfg,
Expand Down
8 changes: 5 additions & 3 deletions state/stateenvirons/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package stateenvirons_test

import (
"context"

"github.com/juju/juju/caas"
"github.com/juju/names/v4"
jc "github.com/juju/testing/checkers"
Expand All @@ -26,7 +28,7 @@ var _ = gc.Suite(&environSuite{})
func (s *environSuite) TestGetNewEnvironFunc(c *gc.C) {
var calls int
var callArgs environs.OpenParams
newEnviron := func(args environs.OpenParams) (environs.Environ, error) {
newEnviron := func(_ context.Context, args environs.OpenParams) (environs.Environ, error) {
calls++
callArgs = args
return nil, nil
Expand Down Expand Up @@ -110,7 +112,7 @@ func (s *environSuite) TestCloudSpecForModel(c *gc.C) {
func (s *environSuite) TestGetNewCAASBrokerFunc(c *gc.C) {
var calls int
var callArgs environs.OpenParams
newBroker := func(args environs.OpenParams) (caas.Broker, error) {
newBroker := func(_ context.Context, args environs.OpenParams) (caas.Broker, error) {
calls++
callArgs = args
return nil, nil
Expand Down Expand Up @@ -142,7 +144,7 @@ func (s *environSuite) TestCloudAPIVersion(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

cred := cloud.NewNamedCredential("dummy-credential", "userpass", nil, false)
newBrokerFunc := func(args environs.OpenParams) (caas.Broker, error) {
newBrokerFunc := func(_ context.Context, args environs.OpenParams) (caas.Broker, error) {
c.Assert(args.Cloud, jc.DeepEquals, environscloudspec.CloudSpec{
Name: "caascloud",
Type: "kubernetes",
Expand Down
3 changes: 2 additions & 1 deletion state/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package state

import (
"context"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -1928,7 +1929,7 @@ func updateKubernetesStorageConfig(st *State) error {
if err != nil {
return errors.Trace(err)
}
broker, err := NewBroker(environs.OpenParams{Cloud: cloudSpec, Config: cfg})
broker, err := NewBroker(context.TODO(), environs.OpenParams{Cloud: cloudSpec, Config: cfg})
if err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion worker/caasbroker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewTracker(config Config) (*Tracker, error) {
if err != nil {
return nil, errors.Trace(err)
}
broker, err := config.NewContainerBrokerFunc(environs.OpenParams{
broker, err := config.NewContainerBrokerFunc(context.TODO(), environs.OpenParams{
ControllerUUID: ctrlCfg.ControllerUUID(),
Cloud: cloudSpec,
Config: cfg,
Expand Down
Loading

0 comments on commit 8899219

Please sign in to comment.