-
Notifications
You must be signed in to change notification settings - Fork 870
/
registry.go
81 lines (70 loc) · 2.59 KB
/
registry.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
package tools
import (
"encoding/json"
"fmt"
"github.com/KubeOperator/KubeOperator/pkg/constant"
"github.com/KubeOperator/KubeOperator/pkg/model"
)
type Registry struct {
Cluster *Cluster
Tool *model.ClusterTool
LocalHostName string
LocalRepositoryPort int
}
func NewRegistry(cluster *Cluster, tool *model.ClusterTool) (*Registry, error) {
p := &Registry{
Tool: tool,
Cluster: cluster,
LocalHostName: constant.LocalRepositoryDomainName,
LocalRepositoryPort: cluster.helmRepoPort,
}
return p, nil
}
func (r Registry) setDefaultValue(toolDetail model.ClusterToolDetail, isInstall bool) {
imageMap := map[string]interface{}{}
_ = json.Unmarshal([]byte(toolDetail.Vars), &imageMap)
values := map[string]interface{}{}
_ = json.Unmarshal([]byte(r.Tool.Vars), &values)
values["image.repository"] = fmt.Sprintf("%s:%d/%s", r.LocalHostName, r.LocalRepositoryPort, imageMap["registry_image_name"])
values["image.tag"] = imageMap["registry_image_tag"]
values["secrets.htpasswd"] = "admin:$2y$05$xOL4vcb.1gGpKBHzW0Vv0O4KV0kOAHLXkXBPHtZFAswoW.hYVGzOy"
if isInstall {
if _, ok := values["persistence.size"]; ok {
values["persistence.size"] = fmt.Sprintf("%vGi", values["persistence.size"])
}
if va, ok := values["persistence.enabled"]; ok {
if hasPers, _ := va.(bool); !hasPers {
delete(values, "nodeSelector.kubernetes\\.io/hostname")
}
}
}
str, _ := json.Marshal(&values)
r.Tool.Vars = string(str)
}
func (r Registry) Install(toolDetail model.ClusterToolDetail) error {
r.setDefaultValue(toolDetail, true)
if err := installChart(r.Cluster.HelmClient, r.Tool, constant.DockerRegistryChartName, toolDetail.ChartVersion); err != nil {
return err
}
ingressItem := &Ingress{
name: constant.DefaultRegistryIngressName,
url: constant.DefaultRegistryIngress,
service: constant.DefaultRegistryServiceName,
port: 5000,
version: r.Cluster.Version,
}
if err := createRoute(r.Cluster.Namespace, ingressItem, r.Cluster.KubeClient); err != nil {
return err
}
if err := waitForRunning(r.Cluster.Namespace, constant.DefaultRegistryDeploymentName, 1, r.Cluster.KubeClient); err != nil {
return err
}
return nil
}
func (r Registry) Upgrade(toolDetail model.ClusterToolDetail) error {
r.setDefaultValue(toolDetail, false)
return upgradeChart(r.Cluster.HelmClient, r.Tool, constant.DockerRegistryChartName, toolDetail.ChartVersion)
}
func (r Registry) Uninstall() error {
return uninstall(r.Cluster.Namespace, r.Tool, constant.DefaultRegistryIngressName, r.Cluster.Version, r.Cluster.HelmClient, r.Cluster.KubeClient)
}