Skip to content

Commit

Permalink
Removes usage of systems package from CAAS application provisioner
Browse files Browse the repository at this point in the history
worker.

Instead we use the series package to determine an OS and version,
construct a base from these, then use that to get a charm-base image.
  • Loading branch information
manadart authored and hmlanigan committed Apr 19, 2021
1 parent 7ae24ca commit b763122
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
9 changes: 4 additions & 5 deletions cloudconfig/podcfg/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"fmt"
"strings"

"github.com/juju/charm/v8"
"github.com/juju/errors"
"github.com/juju/systems"
"github.com/juju/systems/channel"
"github.com/juju/version/v2"

"github.com/juju/juju/controller"
Expand Down Expand Up @@ -90,9 +89,9 @@ func imageRepoToPath(imageRepo string, ver version.Number) string {

// ImageForBase returns the OCI image path for a generic base.
// NOTE: resource referenced bases are not resolved via ImageForBase.
func ImageForBase(imageRepo string, base systems.Base) (string, error) {
func ImageForBase(imageRepo string, base charm.Base) (string, error) {
if base.Name == "" {
return "", errors.NotValidf("base name")
return "", errors.NotValidf("empty base name")
}
if imageRepo == "" {
imageRepo = JujudOCINamespace
Expand All @@ -101,7 +100,7 @@ func ImageForBase(imageRepo string, base systems.Base) (string, error) {
return "", errors.NotValidf("channel %q", base.Channel)
}
tag := fmt.Sprintf("%s-%s", base.Name, base.Channel.Track)
if base.Channel.Risk != channel.Stable {
if base.Channel.Risk != charm.Stable {
tag = fmt.Sprintf("%s-%s", tag, base.Channel.Risk)
}
image := fmt.Sprintf("%s/charm-base:%s", imageRepo, tag)
Expand Down
21 changes: 10 additions & 11 deletions cloudconfig/podcfg/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
package podcfg_test

import (
"github.com/juju/charm/v8"
jc "github.com/juju/testing/checkers"
"github.com/juju/version/v2"
gc "gopkg.in/check.v1"

"github.com/juju/juju/cloudconfig/podcfg"
"github.com/juju/juju/controller"
"github.com/juju/juju/testing"
"github.com/juju/systems"
"github.com/juju/systems/channel"
)

type imageSuite struct {
Expand All @@ -35,25 +34,25 @@ func (*imageSuite) TestGetJujuOCIImagePath(c *gc.C) {
}

func (*imageSuite) TestImageForBase(c *gc.C) {
_, err := podcfg.ImageForBase("", systems.Base{})
c.Assert(err, gc.ErrorMatches, `base name not valid`)
_, err := podcfg.ImageForBase("", charm.Base{})
c.Assert(err, gc.ErrorMatches, `empty base name not valid`)

_, err = podcfg.ImageForBase("", systems.Base{Name: "ubuntu"})
_, err = podcfg.ImageForBase("", charm.Base{Name: "ubuntu"})
c.Assert(err, gc.ErrorMatches, `channel "" not valid`)

_, err = podcfg.ImageForBase("", systems.Base{Name: "ubuntu", Channel: channel.Channel{
_, err = podcfg.ImageForBase("", charm.Base{Name: "ubuntu", Channel: charm.Channel{
Track: "20.04",
}})
c.Assert(err, gc.ErrorMatches, `channel "" not valid`)
c.Assert(err, gc.ErrorMatches, `channel "20.04/" not valid`)

path, err := podcfg.ImageForBase("", systems.Base{Name: "ubuntu", Channel: channel.Channel{
Track: "20.04", Risk: channel.Stable,
path, err := podcfg.ImageForBase("", charm.Base{Name: "ubuntu", Channel: charm.Channel{
Track: "20.04", Risk: charm.Stable,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(path, gc.DeepEquals, `jujusolutions/charm-base:ubuntu-20.04`)

path, err = podcfg.ImageForBase("", systems.Base{Name: "ubuntu", Channel: channel.Channel{
Track: "20.04", Risk: channel.Edge,
path, err = podcfg.ImageForBase("", charm.Base{Name: "ubuntu", Channel: charm.Channel{
Track: "20.04", Risk: charm.Edge,
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(path, gc.DeepEquals, `jujusolutions/charm-base:ubuntu-20.04-edge`)
Expand Down
30 changes: 21 additions & 9 deletions worker/caasapplicationprovisioner/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"strings"
"time"

"github.com/juju/charm/v8"
"github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/retry"
"github.com/juju/systems"
"github.com/juju/utils/v2"
"github.com/juju/worker/v2"
"github.com/juju/worker/v2/catacomb"
Expand All @@ -23,6 +23,7 @@ import (
"github.com/juju/juju/cloudconfig/podcfg"
"github.com/juju/juju/core/life"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/core/series"
"github.com/juju/juju/core/status"
"github.com/juju/juju/core/watcher"
)
Expand Down Expand Up @@ -417,20 +418,20 @@ func (a *appWorker) alive(app caas.Application) error {

provisionInfo, err := a.facade.ProvisioningInfo(a.name)
if err != nil {
return errors.Annotate(err, "failed to get provisioning info")
return errors.Annotate(err, "retrieving provisioning info")
}
if provisionInfo.CharmURL == nil {
return errors.Errorf("missing charm url in provision info")
}

charmInfo, err := a.facade.CharmInfo(provisionInfo.CharmURL.String())
if err != nil {
return errors.Annotatef(err, "failed to get application charm deployment metadata for %q", a.name)
return errors.Annotatef(err, "retrieving charm deployment info for %q", a.name)
}

appState, err := app.Exists()
if err != nil {
return errors.Annotatef(err, "failed get application state for %q", a.name)
return errors.Annotatef(err, "retrieving application state for %q", a.name)
}

if appState.Exists && appState.Terminating {
Expand All @@ -441,19 +442,30 @@ func (a *appWorker) alive(app caas.Application) error {

images, err := a.facade.ApplicationOCIResources(a.name)
if err != nil {
return errors.Annotate(err, "failed to get oci image resources")
return errors.Annotate(err, "getting OCI image resources")
}

base, err := systems.ParseBaseFromSeries(provisionInfo.Series)
os, err := series.GetOSFromSeries(provisionInfo.Series)
if err != nil {
return errors.Annotate(err, "failed to parse series as a system")
return errors.Trace(err)
}

ver, err := series.SeriesVersion(provisionInfo.Series)
if err != nil {
return errors.Trace(err)
}

ch := charmInfo.Charm()
charmBaseImage := resources.DockerImageDetails{}
charmBaseImage.RegistryPath, err = podcfg.ImageForBase(provisionInfo.ImageRepo, base)
charmBaseImage.RegistryPath, err = podcfg.ImageForBase(provisionInfo.ImageRepo, charm.Base{
Name: strings.ToLower(os.String()),
Channel: charm.Channel{
Track: ver,
Risk: charm.Stable,
},
})
if err != nil {
return errors.Annotate(err, "failed to get image for system")
return errors.Annotate(err, "getting image for base")
}

containers := make(map[string]caas.ContainerConfig)
Expand Down

0 comments on commit b763122

Please sign in to comment.