Skip to content

Commit

Permalink
Make juju-db repo configurable like juju operator image;
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed Jul 26, 2021
1 parent 33e0259 commit 762b78c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 5 additions & 1 deletion caas/kubernetes/provider/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,14 @@ func (c *controllerStack) buildContainerSpecForController(statefulset *apps.Stat
mongoArgs := fmt.Sprintf("%[1]s && chmod a+x %[2]s && %[2]s", makeMongoCmd, mongoSh)
logger.Debugf("mongodb container args:\n%s", mongoArgs)

dbImage, err := c.pcfg.GetJujuDbOCIImagePath()
if err != nil {
return nil, errors.Trace(err)
}
containerSpec = append(containerSpec, core.Container{
Name: mongoDBContainerName,
ImagePullPolicy: core.PullIfNotPresent,
Image: c.pcfg.GetJujuDbOCIImagePath(),
Image: dbImage,
Command: []string{
"/bin/sh",
},
Expand Down
31 changes: 20 additions & 11 deletions cloudconfig/podcfg/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ func (cfg *ControllerPodConfig) GetControllerImagePath() (string, error) {
}

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

// IsJujuOCIImage returns true if the image path is for a Juju operator.
Expand All @@ -51,18 +52,27 @@ func GetJujuOCIImagePath(controllerCfg controller.Config, ver version.Number, bu
if imagePath != "" || err != nil {
return imagePath, err
}
return imageRepoToPath(controllerCfg.CAASImageRepo(), ver)
tag := ""
if ver != version.Zero {
tag = ver.String()
}
return imageRepoToPath(controllerCfg.CAASImageRepo(), tag)
}

// RebuildOldOperatorImagePath returns a updated image path for the specified juju version.
func RebuildOldOperatorImagePath(imagePath string, ver version.Number) (string, error) {
if imagePath == "" {
return "", nil
}
return tagImagePath(imagePath, ver)
tag := ""
if ver != version.Zero {
// ver is always a valid tag.
tag = ver.String()
}
return tagImagePath(imagePath, tag)
}

func tagImagePath(fullPath string, ver version.Number) (string, error) {
func tagImagePath(fullPath, tag string) (string, error) {
ref, err := reference.Parse(fullPath)
if err != nil {
return "", errors.Trace(err)
Expand All @@ -72,19 +82,18 @@ func tagImagePath(fullPath string, ver version.Number) (string, error) {
if !ok {
return "", errors.Errorf("unexpected docker image path type, got %T, expected reference.Named", ref)
}
if ver != version.Zero {
// ver is always a valid tag.
imageNamed, _ = reference.WithTag(imageNamed, ver.String())
if tag != "" {
imageNamed, _ = reference.WithTag(imageNamed, tag)
}
return imageNamed.String(), nil
}

func imageRepoToPath(imageRepo string, ver version.Number) (string, error) {
func imageRepoToPath(imageRepo, tag string) (string, error) {
if imageRepo == "" {
imageRepo = JujudOCINamespace
}
path := fmt.Sprintf("%s/%s", imageRepo, JujudOCIName)
return tagImagePath(path, ver)
return tagImagePath(path, tag)
}

// ImageForBase returns the OCI image path for a generic base.
Expand Down

0 comments on commit 762b78c

Please sign in to comment.