This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 875
/
chartmuseum.go
83 lines (70 loc) · 2.58 KB
/
chartmuseum.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
package tools
import (
"encoding/json"
"fmt"
"github.com/KubeOperator/KubeOperator/pkg/constant"
"github.com/KubeOperator/KubeOperator/pkg/model"
)
type Chartmuseum struct {
Cluster *Cluster
Tool *model.ClusterTool
LocalHostName string
LocalRepositoryPort int
}
func NewChartmuseum(cluster *Cluster, tool *model.ClusterTool) (*Chartmuseum, error) {
p := &Chartmuseum{
Tool: tool,
Cluster: cluster,
LocalHostName: constant.LocalRepositoryDomainName,
LocalRepositoryPort: cluster.helmRepoPort,
}
return p, nil
}
func (c Chartmuseum) setDefaultValue(toolDetail model.ClusterToolDetail, isInstall bool) {
versionMap := map[string]interface{}{}
_ = json.Unmarshal([]byte(toolDetail.Vars), &versionMap)
values := map[string]interface{}{}
_ = json.Unmarshal([]byte(c.Tool.Vars), &values)
values["env.open.DISABLE_API"] = false
values["image.repository"] = fmt.Sprintf("%s:%d/%s", c.LocalHostName, c.LocalRepositoryPort, versionMap["chartmuseum_image_name"])
values["image.tag"] = versionMap["chartmuseum_image_tag"]
if isInstall {
if va, ok := values["persistence.enabled"]; ok {
if hasPers, _ := va.(bool); !hasPers {
delete(values, "nodeSelector.kubernetes\\.io/hostname")
}
}
if _, ok := values["persistence.size"]; ok {
values["persistence.size"] = fmt.Sprintf("%vGi", values["persistence.size"])
}
}
str, _ := json.Marshal(&values)
c.Tool.Vars = string(str)
}
func (c Chartmuseum) Install(toolDetail model.ClusterToolDetail) error {
c.setDefaultValue(toolDetail, true)
if err := installChart(c.Cluster.HelmClient, c.Tool, constant.ChartmuseumChartName, toolDetail.ChartVersion); err != nil {
return err
}
ingressItem := &Ingress{
name: constant.DefaultChartmuseumIngressName,
url: constant.DefaultChartmuseumIngress,
service: constant.DefaultChartmuseumServiceName,
port: 8080,
version: c.Cluster.Version,
}
if err := createRoute(c.Cluster.Namespace, ingressItem, c.Cluster.KubeClient); err != nil {
return err
}
if err := waitForRunning(c.Cluster.Namespace, constant.DefaultChartmuseumDeploymentName, 1, c.Cluster.KubeClient); err != nil {
return err
}
return nil
}
func (c Chartmuseum) Upgrade(toolDetail model.ClusterToolDetail) error {
c.setDefaultValue(toolDetail, false)
return upgradeChart(c.Cluster.HelmClient, c.Tool, constant.ChartmuseumChartName, toolDetail.ChartVersion)
}
func (c Chartmuseum) Uninstall() error {
return uninstall(c.Cluster.Namespace, c.Tool, constant.DefaultChartmuseumIngressName, c.Cluster.Version, c.Cluster.HelmClient, c.Cluster.KubeClient)
}