Skip to content

Commit

Permalink
k8s controller juju-db image tag comes from the controller config juj…
Browse files Browse the repository at this point in the history
…u-db-snap-channel that can be set at bootstrap
  • Loading branch information
wallyworld committed Oct 19, 2021
1 parent 29858b5 commit 3722f2d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions caas/kubernetes/provider/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (s *bootstrapSuite) SetUpTest(c *gc.C) {
s.cfg = cfg

s.controllerCfg = coretesting.FakeControllerConfig()
s.controllerCfg["juju-db-snap-channel"] = "4.0/stable"
s.controllerCfg[controller.CAASImageRepo] = `
{
"serveraddress": "quay.io",
Expand Down
20 changes: 19 additions & 1 deletion cloudconfig/podcfg/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/juju/version/v2"

"github.com/juju/juju/controller"
"github.com/juju/juju/mongo"
)

const (
Expand All @@ -26,14 +27,31 @@ func (cfg *ControllerPodConfig) GetControllerImagePath() (string, error) {
return GetJujuOCIImagePath(cfg.Controller.Config, cfg.JujuVersion, cfg.OfficialBuild)
}

func (cfg *ControllerPodConfig) mongoVersion() (*mongo.Version, error) {
snapChannel := cfg.Controller.Config.JujuDBSnapChannel()
vers := strings.Split(snapChannel, "/")[0] + ".0"
versionNum, err := version.Parse(vers)
if err != nil {
return nil, errors.Annotatef(err, "invalid mongo version %q in %q controller config", versionNum, controller.JujuDBSnapChannel)
}
mongoVersion := mongo.Mongo4xwt
mongoVersion.Major = versionNum.Major
mongoVersion.Minor = versionNum.Minor
return &mongoVersion, nil
}

// GetJujuDbOCIImagePath returns the juju-db oci image path.
func (cfg *ControllerPodConfig) GetJujuDbOCIImagePath() (string, error) {
imageRepo := cfg.Controller.Config.CAASImageRepo().Repository
if imageRepo == "" {
imageRepo = JujudOCINamespace
}
path := fmt.Sprintf("%s/%s", imageRepo, JujudbOCIName)
tag := fmt.Sprintf("%d.%d", jujudbVersion.Major, jujudbVersion.Minor)
mongoVers, err := cfg.mongoVersion()
if err != nil {
return "", errors.Trace(err)
}
tag := fmt.Sprintf("%d.%d", mongoVers.Major, mongoVers.Minor)
return tagImagePath(path, tag)
}

Expand Down
9 changes: 5 additions & 4 deletions cloudconfig/podcfg/podcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import (

var logger = loggo.GetLogger("juju.cloudconfig.podcfg")

// jujudbVersion is the version of juju-db to use.
var jujudbVersion = mongo.Mongo40wt

// ControllerPodConfig represents initialization information for a new juju caas controller pod.
type ControllerPodConfig struct {
// Tags is a set of tags/labels to set on the Pod, if supported. This
Expand Down Expand Up @@ -105,6 +102,10 @@ type ControllerConfig struct {

// AgentConfig returns an agent config.
func (cfg *ControllerPodConfig) AgentConfig(tag names.Tag) (agent.ConfigSetterWriter, error) {
mongoVers, err := cfg.mongoVersion()
if err != nil {
return nil, errors.Trace(err)
}
configParams := agent.AgentConfigParams{
Paths: agent.Paths{
DataDir: cfg.DataDir,
Expand All @@ -119,7 +120,7 @@ func (cfg *ControllerPodConfig) AgentConfig(tag names.Tag) (agent.ConfigSetterWr
Values: cfg.AgentEnvironment,
Controller: cfg.ControllerTag,
Model: cfg.APIInfo.ModelTag,
MongoVersion: jujudbVersion,
MongoVersion: *mongoVers,
MongoMemoryProfile: mongo.MemoryProfile(cfg.Controller.Config.MongoMemoryProfile()),
}
return agent.NewStateMachineConfig(configParams, cfg.Bootstrap.StateServingInfo)
Expand Down
4 changes: 3 additions & 1 deletion cloudconfig/podcfg/podcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func testPodLabels(c *gc.C, cfg *config.Config, jobs []model.MachineJob, expectT

func (*podcfgSuite) TestOperatorImagesDefaultRepo(c *gc.C) {
cfg := testing.FakeControllerConfig()
cfg["juju-db-snap-channel"] = "4.0/stable"
podConfig, err := podcfg.NewBootstrapControllerPodConfig(
cfg,
"controller-1",
Expand All @@ -77,6 +78,7 @@ func (*podcfgSuite) TestOperatorImagesDefaultRepo(c *gc.C) {
func (*podcfgSuite) TestOperatorImagesCustomRepo(c *gc.C) {
cfg := testing.FakeControllerConfig()
cfg["caas-image-repo"] = "path/to/my/repo"
cfg["juju-db-snap-channel"] = "4.4"
podConfig, err := podcfg.NewBootstrapControllerPodConfig(
cfg,
"controller-1",
Expand All @@ -92,7 +94,7 @@ func (*podcfgSuite) TestOperatorImagesCustomRepo(c *gc.C) {
c.Assert(path, gc.Equals, "path/to/my/repo/jujud-operator:6.6.6.666")
path, err = podConfig.GetJujuDbOCIImagePath()
c.Assert(err, jc.ErrorIsNil)
c.Assert(path, gc.Equals, "path/to/my/repo/juju-db:4.0")
c.Assert(path, gc.Equals, "path/to/my/repo/juju-db:4.4")
}

func (*podcfgSuite) TestBootstrapConstraints(c *gc.C) {
Expand Down
4 changes: 2 additions & 2 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ var (
Patch: "",
StorageEngine: WiredTiger,
}
// Mongo40wt represents 'mongodb' at version 4.0.x with WiredTiger
Mongo40wt = Version{Major: 4,
// Mongo4xwt represents 'mongodb' at version 4.x with WiredTiger
Mongo4xwt = Version{Major: 4,
Minor: 0,
Patch: "",
StorageEngine: WiredTiger,
Expand Down

0 comments on commit 3722f2d

Please sign in to comment.