Skip to content

Commit

Permalink
Introduction of Force
Browse files Browse the repository at this point in the history
The following commit introduces a Force flag into the bootstrap
code to allow the overriding of the default series.
  • Loading branch information
SimonRichardson committed Aug 28, 2019
1 parent 2da0257 commit 4b3039d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/juju/commands/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ to create a new model to deploy k8s workloads.
RetryDelay: config.bootstrap.BootstrapRetryDelay,
AddressesDelay: config.bootstrap.BootstrapAddressesDelay,
},
Force: c.Force,
}

environ, err := bootstrapPrepareController(
Expand Down
3 changes: 3 additions & 0 deletions environs/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type BootstrapParams struct {
// that rely on it for selecting images. This will be empty for
// providers that do not implements simplestreams.HasRegion.
ImageMetadata []*imagemetadata.ImageMetadata

// Force is used to allow a bootstrap to be run on unsupported series.
Force bool
}

// CloudBootstrapFinalizer is a function returned from Environ.Bootstrap.
Expand Down
6 changes: 5 additions & 1 deletion environs/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ type BootstrapParams struct {
// JujuDbSnapAssertionsPath is the path to a local .assertfile that
// will be used to test the contents of the .snap at JujuDbSnap.
JujuDbSnapAssertionsPath string

// Force is used to allow a bootstrap to be run on unsupported series.
Force bool
}

// Validate validates the bootstrap parameters.
Expand Down Expand Up @@ -313,7 +316,7 @@ func bootstrapIAAS(
args.BootstrapSeries,
config.PreferredSeries(cfg),
)
if err != nil {
if !args.Force && err != nil {
return errors.Annotatef(err, "use --force to override")
}
bootstrapSeries := &requestedBootstrapSeries
Expand Down Expand Up @@ -583,6 +586,7 @@ func Bootstrap(
BootstrapSeries: args.BootstrapSeries,
SupportedBootstrapSeries: args.SupportedBootstrapSeries,
Placement: args.Placement,
Force: args.Force,
}
doBootstrap := bootstrapIAAS
if jujucloud.CloudIsCAAS(args.Cloud) {
Expand Down
45 changes: 45 additions & 0 deletions environs/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,51 @@ func (s *bootstrapSuite) TestBootstrapSpecifiedBootstrapSeries(c *gc.C) {
c.Check(env.args.AvailableTools.AllSeries(), jc.SameContents, []string{"trusty"})
}

func (s *bootstrapSuite) TestBootstrapFallbackBootstrapSeries(c *gc.C) {
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
cfg, err := env.Config().Apply(map[string]interface{}{
"default-series": series.DefaultSupportedLTS(),
})
c.Assert(err, jc.ErrorIsNil)
env.cfg = cfg

err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env,
s.callContext, bootstrap.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
SupportedBootstrapSeries: supportedJujuSeries,
})
c.Assert(err, jc.ErrorIsNil)
c.Check(env.bootstrapCount, gc.Equals, 1)
c.Check(env.args.AvailableTools.AllSeries(), jc.SameContents, []string{series.DefaultSupportedLTS()})
}

func (s *bootstrapSuite) TestBootstrapForcedBootstrapSeries(c *gc.C) {
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
cfg, err := env.Config().Apply(map[string]interface{}{
"default-series": "wily",
})
c.Assert(err, jc.ErrorIsNil)
env.cfg = cfg

err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env,
s.callContext, bootstrap.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
BootstrapSeries: "xenial",
SupportedBootstrapSeries: supportedJujuSeries,
Force: true,
})
c.Assert(err, jc.ErrorIsNil)
c.Check(env.bootstrapCount, gc.Equals, 1)
c.Check(env.args.BootstrapSeries, gc.Equals, "xenial")
c.Check(env.args.AvailableTools.AllSeries(), jc.SameContents, []string{"bionic", "trusty", "xenial"})
}

func (s *bootstrapSuite) TestBootstrapSpecifiedPlacement(c *gc.C) {
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
Expand Down
2 changes: 1 addition & 1 deletion provider/common/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func BootstrapInstance(
args.BootstrapSeries,
config.PreferredSeries(env.Config()),
)
if err != nil {
if !args.Force && err != nil {
return nil, "", nil, errors.Annotatef(err, "use --force to override")
}
availableTools, err := args.AvailableTools.Match(coretools.Filter{
Expand Down

0 comments on commit 4b3039d

Please sign in to comment.