-
Notifications
You must be signed in to change notification settings - Fork 494
/
image.go
85 lines (73 loc) · 2.25 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package podcfg
import (
"fmt"
"strings"
"github.com/juju/version"
"github.com/juju/juju/controller"
)
const (
jujudOCINamespace = "jujusolutions"
jujudOCIName = "jujud-operator"
jujudbOCIName = "juju-db"
)
// GetControllerImagePath returns oci image path of jujud for a controller.
func (cfg *ControllerPodConfig) GetControllerImagePath() string {
return GetJujuOCIImagePath(cfg.Controller.Config, cfg.JujuVersion, 0)
}
// GetJujuDbOCIImagePath returns the juju-db oci image path.
func (cfg *ControllerPodConfig) GetJujuDbOCIImagePath() string {
imageRepo := cfg.Controller.Config.CAASImageRepo()
if imageRepo == "" {
imageRepo = jujudOCINamespace
}
v := jujudbVersion
return fmt.Sprintf("%s/%s:%d.%d", imageRepo, jujudbOCIName, v.Major, v.Minor)
}
// IsJujuOCIImage returns true if the image path is for a Juju operator.
func IsJujuOCIImage(imagePath string) bool {
return strings.Contains(imagePath, jujudOCIName+":")
}
// GetJujuOCIImagePath returns the jujud oci image path.
func GetJujuOCIImagePath(controllerCfg controller.Config, ver version.Number, build int) string {
// First check the deprecated "caas-operator-image-path" config.
ver.Build = build
imagePath := RebuildOldOperatorImagePath(
controllerCfg.CAASOperatorImagePath(), ver,
)
if imagePath != "" {
return imagePath
}
return imageRepoToPath(controllerCfg.CAASImageRepo(), ver)
}
// RebuildOldOperatorImagePath returns a updated image path for the specified juju version.
func RebuildOldOperatorImagePath(imagePath string, ver version.Number) string {
if imagePath == "" {
return ""
}
return tagImagePath(imagePath, ver)
}
func tagImagePath(path string, ver version.Number) string {
var verString string
splittedPath := strings.Split(path, ":")
path = splittedPath[0]
if len(splittedPath) > 1 {
verString = splittedPath[1]
}
if ver != version.Zero {
verString = ver.String()
}
if verString != "" {
// tag with version.
path += ":" + verString
}
return path
}
func imageRepoToPath(imageRepo string, ver version.Number) string {
if imageRepo == "" {
imageRepo = jujudOCINamespace
}
path := fmt.Sprintf("%s/%s", imageRepo, jujudOCIName)
return tagImagePath(path, ver)
}