Skip to content

Commit

Permalink
Hardcode ControllerBases + WorkloadBases
Browse files Browse the repository at this point in the history
It was decided in Madrid that, going forward, we want to provide a hard
coded list of ubuntu bases which we wish to support for
1) controllers
2) other workloads

So hardcode the output to ControllerBases & WorkloadBases

This means we can simplify the signature of these functions. This
resulted in many small changes across Juju

Also, importantly, this means we can remove all the code which searches
distro info. This simplifies core/base dramatically!

I also took the decision to remove
1) AllWorkloadVersions. This can simply be calculated using
   WorkloadBases.
2) AllWorkloadOSypes. This is only ubuntu now, so I just use the const instead
  • Loading branch information
jack-w-shaw committed Jun 6, 2024
1 parent 7de540a commit b257bf1
Show file tree
Hide file tree
Showing 38 changed files with 102 additions and 1,442 deletions.
7 changes: 1 addition & 6 deletions apiserver/facades/client/application/deployrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"sync"

jujuclock "github.com/juju/clock"
"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/names/v5"
Expand Down Expand Up @@ -842,17 +841,13 @@ func (v *deployFromRepositoryValidator) resolveCharm(ctx context.Context, curl *
if err != nil {
return corecharm.ResolvedDataForDeploy{}, errors.Trace(err)
}
workloadBases, err := corebase.WorkloadBases(jujuclock.WallClock.Now(), requestedBase, modelCfg.ImageStream())
if err != nil {
return corecharm.ResolvedDataForDeploy{}, errors.Trace(err)
}
bsCfg := corecharm.SelectorConfig{
Config: modelCfg,
Force: force,
Logger: v.logger,
RequestedBase: requestedBase,
SupportedCharmBases: supportedBases,
WorkloadBases: workloadBases,
WorkloadBases: corebase.WorkloadBases(),
UsingImageID: cons.HasImageID() || modelCons.HasImageID(),
}
selector, err := corecharm.ConfigureBaseSelector(bsCfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1648,9 +1648,7 @@ type IsBaseLessThanMachineManagerSuite struct{}
// but complex enough to warrant being exported from an export test package for
// testing.
func (s *IsBaseLessThanMachineManagerSuite) TestIsBaseLessThan(c *gc.C) {
workloadVersions, err := corebase.AllWorkloadVersions()
c.Assert(err, jc.ErrorIsNil)
vers := workloadVersions.Values()
vers := transform.Slice(corebase.WorkloadBases(), func(b corebase.Base) string { return b.Channel.Track })
s.assertSeriesLessThan(c, "ubuntu", vers)
}

Expand Down
31 changes: 19 additions & 12 deletions apiserver/facades/client/modelupgrader/upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package modelupgrader_test

import (
stdcontext "context"
"time"

"github.com/juju/collections/transform"
"github.com/juju/errors"
Expand Down Expand Up @@ -189,8 +188,8 @@ func (s *modelUpgradeSuite) assertUpgradeModelForControllerModelJuju3(c *gc.C, d
},
)

s.PatchValue(&upgradevalidation.SupportedJujuBases, func(time.Time, base.Base, string) ([]base.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.ParseBaseFromString)
s.PatchValue(&upgradevalidation.SupportedJujuBases, func() []base.Base {
return transform.Slice([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.MustParseBaseFromString)
})

ctrlModelTag := coretesting.ModelTag
Expand Down Expand Up @@ -318,8 +317,8 @@ func (s *modelUpgradeSuite) TestUpgradeModelForControllerDyingHostedModelJuju3(c
},
)

s.PatchValue(&upgradevalidation.SupportedJujuBases, func(time.Time, base.Base, string) ([]base.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.ParseBaseFromString)
s.PatchValue(&upgradevalidation.SupportedJujuBases, func() []base.Base {
return transform.Slice([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.MustParseBaseFromString)
})

ctrlModelTag := coretesting.ModelTag
Expand Down Expand Up @@ -427,8 +426,8 @@ func (s *modelUpgradeSuite) TestUpgradeModelForControllerModelJuju3Failed(c *gc.
},
)

s.PatchValue(&upgradevalidation.SupportedJujuBases, func(time.Time, base.Base, string) ([]base.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.ParseBaseFromString)
s.PatchValue(&upgradevalidation.SupportedJujuBases, func() []base.Base {
return transform.Slice([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.MustParseBaseFromString)
})

ctrlModelTag := coretesting.ModelTag
Expand Down Expand Up @@ -553,6 +552,14 @@ func (s *modelUpgradeSuite) assertUpgradeModelJuju3(c *gc.C, ctrlModelVers strin
},
)

s.PatchValue(&upgradevalidation.SupportedJujuBases, func() []base.Base {
return []base.Base{
base.MustParseBaseFromString("ubuntu@24.04"),
base.MustParseBaseFromString("ubuntu@22.04"),
base.MustParseBaseFromString("ubuntu@20.04"),
}
})

modelUUID := coretesting.ModelTag.Id()
model := mocks.NewMockModel(ctrl)
st := mocks.NewMockState(ctrl)
Expand Down Expand Up @@ -588,7 +595,7 @@ func (s *modelUpgradeSuite) assertUpgradeModelJuju3(c *gc.C, ctrlModelVers strin
// - check no upgrade series in process.
st.EXPECT().HasUpgradeSeriesLocks().Return(false, nil)
// - check if the model has deprecated ubuntu machines;
st.EXPECT().MachineCountForBase(makeBases("ubuntu", []string{"20.04/stable", "22.04/stable", "24.04/stable"})).Return(nil, nil)
st.EXPECT().MachineCountForBase(makeBases("ubuntu", []string{"24.04/stable", "22.04/stable", "20.04/stable"})).Return(nil, nil)
st.EXPECT().AllMachinesCount().Return(0, nil)
// - check LXD version.
serverFactory.EXPECT().RemoteServer(s.cloudSpec).Return(server, nil)
Expand Down Expand Up @@ -639,8 +646,8 @@ func (s *modelUpgradeSuite) TestUpgradeModelJuju3Failed(c *gc.C) {
},
)

s.PatchValue(&upgradevalidation.SupportedJujuBases, func(time.Time, base.Base, string) ([]base.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@20.04", "ubuntu@22.04", "ubuntu@24.04"}, base.ParseBaseFromString)
s.PatchValue(&upgradevalidation.SupportedJujuBases, func() []base.Base {
return transform.Slice([]string{"ubuntu@24.04", "ubuntu@22.04", "ubuntu@20.04"}, base.MustParseBaseFromString)
})

modelUUID := coretesting.ModelTag.Id()
Expand Down Expand Up @@ -676,7 +683,7 @@ func (s *modelUpgradeSuite) TestUpgradeModelJuju3Failed(c *gc.C) {
st.EXPECT().HasUpgradeSeriesLocks().Return(true, nil)

// - check if the model has deprecated ubuntu machines;
st.EXPECT().MachineCountForBase(makeBases("ubuntu", []string{"20.04/stable", "22.04/stable", "24.04/stable"})).Return(map[string]int{
st.EXPECT().MachineCountForBase(makeBases("ubuntu", []string{"24.04/stable", "22.04/stable", "20.04/stable"})).Return(map[string]int{
"ubuntu@20.04": 1, "ubuntu@22.04": 2, "ubuntu@24.04": 3,
}, nil)
st.EXPECT().AllMachinesCount().Return(7, nil)
Expand All @@ -700,7 +707,7 @@ func (s *modelUpgradeSuite) TestUpgradeModelJuju3Failed(c *gc.C) {
cannot upgrade to "3.9.99" due to issues with these models:
"admin/model-1":
- unexpected upgrade series lock found
- the model hosts 1 ubuntu machine(s) with an unsupported base. The supported bases are: ubuntu@20.04, ubuntu@22.04, ubuntu@24.04
- the model hosts 1 ubuntu machine(s) with an unsupported base. The supported bases are: ubuntu@24.04, ubuntu@22.04, ubuntu@20.04
- LXD version has to be at least "5.0.0", but current version is only "4.0.0"`[1:])
}

Expand Down
17 changes: 8 additions & 9 deletions cmd/juju/application/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"regexp"
"sort"
"strings"
"time"

"github.com/juju/cmd/v4"
"github.com/juju/cmd/v4/cmdtesting"
Expand Down Expand Up @@ -235,8 +234,8 @@ func (s *DeploySuite) TestDeployFromPathDefaultBase(c *gc.C) {

func (s *DeploySuite) TestDeployFromPathUnsupportedSeriesForce(c *gc.C) {
// Do not remove this because we want to test: bases supported by the charm and bases supported by Juju have overlap.
s.PatchValue(&deployer.SupportedJujuBases, func(time.Time, corebase.Base, string) ([]corebase.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@22.04", "ubuntu@20.04", "ubuntu@12.10"}, corebase.ParseBaseFromString)
s.PatchValue(&deployer.SupportedJujuBases, func() []corebase.Base {
return transform.Slice([]string{"ubuntu@22.04", "ubuntu@20.04", "ubuntu@12.10"}, corebase.MustParseBaseFromString)
})
charmDir := testcharms.RepoWithSeries("bionic").ClonedDir(c.MkDir(), "multi-series")
curl := charm.MustParseURL("local:multi-series-1")
Expand All @@ -249,8 +248,8 @@ func (s *DeploySuite) TestDeployFromPathUnsupportedSeriesForce(c *gc.C) {

func (s *DeploySuite) TestDeployFromPathUnsupportedSeriesHaveOverlap(c *gc.C) {
// Do not remove this because we want to test: bases supported by the charm and bases supported by Juju have overlap.
s.PatchValue(&deployer.SupportedJujuBases, func(time.Time, corebase.Base, string) ([]corebase.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@22.04", "ubuntu@20.04", "ubuntu@12.10"}, corebase.ParseBaseFromString)
s.PatchValue(&deployer.SupportedJujuBases, func() []corebase.Base {
return transform.Slice([]string{"ubuntu@22.04", "ubuntu@20.04", "ubuntu@12.10"}, corebase.MustParseBaseFromString)
})

path := testcharms.RepoWithSeries("bionic").ClonedDirPath(c.MkDir(), "multi-series")
Expand All @@ -261,8 +260,8 @@ func (s *DeploySuite) TestDeployFromPathUnsupportedSeriesHaveOverlap(c *gc.C) {
func (s *DeploySuite) TestDeployFromPathUnsupportedBaseHaveNoOverlap(c *gc.C) {
// Do not remove this because we want to test: bases supported by the charm and bases supported by Juju have NO overlap.
s.PatchValue(&deployer.SupportedJujuBases,
func(time.Time, corebase.Base, string) ([]corebase.Base, error) {
return []corebase.Base{corebase.MustParseBaseFromString("ubuntu@22.10")}, nil
func() []corebase.Base {
return []corebase.Base{corebase.MustParseBaseFromString("ubuntu@22.10")}
},
)

Expand All @@ -273,8 +272,8 @@ func (s *DeploySuite) TestDeployFromPathUnsupportedBaseHaveNoOverlap(c *gc.C) {

func (s *DeploySuite) TestDeployFromPathUnsupportedLXDProfileForce(c *gc.C) {
// TODO remove this patch once we removed all the old bases from tests in current package.
s.PatchValue(&deployer.SupportedJujuBases, func(time.Time, corebase.Base, string) ([]corebase.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@22.04", "ubuntu@20.04", "ubuntu@18.04", "ubuntu@12.10"}, corebase.ParseBaseFromString)
s.PatchValue(&deployer.SupportedJujuBases, func() []corebase.Base {
return transform.Slice([]string{"ubuntu@22.04", "ubuntu@20.04", "ubuntu@18.04", "ubuntu@12.10"}, corebase.MustParseBaseFromString)
})

charmDir := testcharms.RepoWithSeries("quantal").ClonedDir(c.MkDir(), "lxd-profile-fail")
Expand Down
12 changes: 2 additions & 10 deletions cmd/juju/application/deployer/bundlehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,13 @@ func (h *bundleHandler) addCharm(change *bundlechanges.AddCharmChange) error {
if resolvedOrigin.Type == "bundle" {
return errors.Errorf("expected charm, got bundle %q %v", ch.Name, resolvedOrigin)
}
workloadBases, err := SupportedJujuBases(jujuclock.WallClock.Now(), base, h.modelConfig.ImageStream())
if err != nil {
return errors.Trace(err)
}
selector, err := corecharm.ConfigureBaseSelector(corecharm.SelectorConfig{
Config: h.modelConfig,
Force: h.force,
Logger: logger,
RequestedBase: base,
SupportedCharmBases: supportedBases,
WorkloadBases: workloadBases,
WorkloadBases: SupportedJujuBases(),
})
if err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -980,17 +976,13 @@ func (h *bundleHandler) selectedBase(ch charm.CharmMeta, chBase corebase.Base) (
if err != nil {
return corebase.Base{}, errors.Trace(err)
}
workloadBases, err := SupportedJujuBases(jujuclock.WallClock.Now(), chBase, h.modelConfig.ImageStream())
if err != nil {
return corebase.Base{}, errors.Trace(err)
}
selector, err := corecharm.ConfigureBaseSelector(corecharm.SelectorConfig{
Config: h.modelConfig,
Force: h.force,
Logger: logger,
RequestedBase: chBase,
SupportedCharmBases: supportedBases,
WorkloadBases: workloadBases,
WorkloadBases: SupportedJujuBases(),
})
if err != nil {
return corebase.Base{}, errors.Trace(err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/juju/application/deployer/bundlehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/juju/cmd/v4"
"github.com/juju/collections/set"
Expand Down Expand Up @@ -64,8 +63,8 @@ func (s *BundleDeployRepositorySuite) SetUpTest(_ *gc.C) {
s.deployArgs = make(map[string]application.DeployArgs)
s.output = bytes.NewBuffer([]byte{})

s.PatchValue(&SupportedJujuBases, func(time.Time, corebase.Base, string) ([]corebase.Base, error) {
return transform.SliceOrErr([]string{"ubuntu@20.04", "ubuntu@22.04", "ubuntu@24.04"}, corebase.ParseBaseFromString)
s.PatchValue(&SupportedJujuBases, func() []corebase.Base {
return transform.Slice([]string{"ubuntu@20.04", "ubuntu@22.04", "ubuntu@24.04"}, corebase.MustParseBaseFromString)
})
}

Expand Down
18 changes: 3 additions & 15 deletions cmd/juju/application/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,13 @@ func (d *factory) localPreDeployedCharmDeployer(getter ModelConfigGetter) (Deplo

func (d *factory) determineBaseForLocalCharm(ch charm.Charm, getter ModelConfigGetter) (corebase.Base, string, error) {
var (
imageStream string
selectedBase corebase.Base
)
modelCfg, err := getModelConfig(getter)
if err != nil {
return corebase.Base{}, "", errors.Trace(err)
}

imageStream = modelCfg.ImageStream()
workloadBases, err := SupportedJujuBases(d.clock.Now(), d.base, imageStream)
if err != nil {
return corebase.Base{}, "", errors.Trace(err)
}

supportedBases, err := corecharm.ComputedBases(ch)
if err != nil {
return corebase.Base{}, "", errors.Trace(err)
Expand All @@ -304,7 +297,7 @@ func (d *factory) determineBaseForLocalCharm(ch charm.Charm, getter ModelConfigG
Logger: logger,
RequestedBase: d.base,
SupportedCharmBases: supportedBases,
WorkloadBases: workloadBases,
WorkloadBases: SupportedJujuBases(),
UsingImageID: d.constraints.HasImageID() || d.modelConstraints.HasImageID(),
})
if err != nil {
Expand All @@ -315,7 +308,7 @@ func (d *factory) determineBaseForLocalCharm(ch charm.Charm, getter ModelConfigG
if err = charmValidationError(ch.Meta().Name, errors.Trace(err)); err != nil {
return corebase.Base{}, "", errors.Trace(err)
}
return selectedBase, imageStream, nil
return selectedBase, modelCfg.ImageStream(), nil
}

func (d *factory) checkHandleRevision(userCharmURL *charm.URL, charmHubSchemaCheck bool) (int, error) {
Expand Down Expand Up @@ -666,12 +659,7 @@ func (d *factory) validateCharmBase(base corebase.Base, imageStream string) erro
}
// attempt to locate the charm base from the list of known juju bases
// that we currently support.
workloadBases, err := SupportedJujuBases(d.clock.Now(), base, imageStream)
if err != nil {
return errors.Trace(err)
}

for _, workloadBase := range workloadBases {
for _, workloadBase := range SupportedJujuBases() {
if workloadBase == base {
return nil
}
Expand Down
17 changes: 3 additions & 14 deletions cmd/juju/commands/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,6 @@ var getBootstrapFuncs = func() BootstrapInterface {
return &bootstrapFuncs{}
}

var supportedJujuBases = corebase.ControllerBases

var (
bootstrapPrepareController = bootstrap.PrepareController
environsDestroy = environs.Destroy
Expand Down Expand Up @@ -771,18 +769,6 @@ func (c *bootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
}
}

// Get the supported bootstrap series.
var imageStream string
if cfg, ok := bootstrapCfg.bootstrapModel["image-stream"]; ok {
imageStream = cfg.(string)
}
now := c.clock.Now()
supportedBootstrapBases, err := supportedJujuBases(now, bootstrapBase, imageStream)
if err != nil {
return errors.Annotate(err, "error reading supported bootstrap series")
}
logger.Tracef("supported bootstrap bases %v", supportedBootstrapBases)

bootstrapCfg.controller[controller.ControllerName] = c.controllerName

// Handle Ctrl-C during bootstrap by asking the bootstrap process to stop
Expand Down Expand Up @@ -889,6 +875,9 @@ to create a new model to deploy %sworkloads.
}
}

supportedBootstrapBases := corebase.ControllerBases()
logger.Tracef("supported bootstrap bases %v", supportedBootstrapBases)

bootstrapParams := bootstrap.BootstrapParams{
ControllerName: c.controllerName,
BootstrapBase: bootstrapBase,
Expand Down
9 changes: 0 additions & 9 deletions cmd/juju/commands/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/juju/cmd/v4/cmdtesting"
"github.com/juju/errors"
"github.com/juju/loggo/v2"
jujuos "github.com/juju/os/v2"
osseries "github.com/juju/os/v2/series"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v4"
Expand Down Expand Up @@ -118,12 +116,6 @@ func init() {
func (s *BootstrapSuite) SetUpSuite(c *gc.C) {
s.FakeJujuXDGDataHomeSuite.SetUpSuite(c)
s.PatchValue(&keys.JujuPublicKey, sstesting.SignedMetadataPublicKey)
s.PatchValue(
&corebase.LocalSeriesVersionInfo,
func() (jujuos.OSType, map[string]osseries.SeriesVersionInfo, error) {
return jujuos.Ubuntu, nil, nil
},
)
}

func (s *BootstrapSuite) SetUpTest(c *gc.C) {
Expand All @@ -136,7 +128,6 @@ func (s *BootstrapSuite) SetUpTest(c *gc.C) {
s.PatchValue(&jujuversion.Current, v100u64.Number)
s.PatchValue(&arch.HostArch, func() string { return v100u64.Arch })
s.PatchValue(&coreos.HostOS, func() ostype.OSType { return ostype.Ubuntu })
s.PatchValue(&corebase.UbuntuDistroInfo, "/path/notexists")

// Ensure KUBECONFIG doesn't interfere with tests.
s.PatchEnvironment(k8scmd.RecommendedConfigPathEnvVar, filepath.Join(c.MkDir(), "config"))
Expand Down
2 changes: 0 additions & 2 deletions cmd/jujud-controller/agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/juju/juju/cloud"
"github.com/juju/juju/cmd/jujud-controller/agent/agenttest"
"github.com/juju/juju/controller"
corebase "github.com/juju/juju/core/base"
"github.com/juju/juju/core/constraints"
"github.com/juju/juju/core/instance"
corelogger "github.com/juju/juju/core/logger"
Expand Down Expand Up @@ -108,7 +107,6 @@ func (s *BootstrapSuite) SetUpTest(c *gc.C) {
s.PatchValue(&sshGenerateKey, func(name string) (string, string, error) {
return "private-key", "public-key", nil
})
s.PatchValue(&corebase.UbuntuDistroInfo, "/path/notexists")

s.MgoSuite.SetUpTest(c)
s.dataDir = c.MkDir()
Expand Down
Loading

0 comments on commit b257bf1

Please sign in to comment.