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
/
efk.go
83 lines (71 loc) · 2.97 KB
/
efk.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 EFK struct {
Cluster *Cluster
Tool *model.ClusterTool
LocalHostName string
LocalRepositoryPort int
}
func NewEFK(cluster *Cluster, tool *model.ClusterTool) (*EFK, error) {
p := &EFK{
Tool: tool,
Cluster: cluster,
LocalHostName: constant.LocalRepositoryDomainName,
LocalRepositoryPort: cluster.helmRepoPort,
}
return p, nil
}
func (e EFK) setDefaultValue(toolDetail model.ClusterToolDetail, isInstall bool) {
imageMap := map[string]interface{}{}
_ = json.Unmarshal([]byte(toolDetail.Vars), &imageMap)
values := map[string]interface{}{}
_ = json.Unmarshal([]byte(e.Tool.Vars), &values)
values["fluentd-elasticsearch.image.repository"] = fmt.Sprintf("%s:%d/%s", e.LocalHostName, e.LocalRepositoryPort, imageMap["fluentd_image_name"])
values["fluentd-elasticsearch.imageTag"] = imageMap["fluentd_image_tag"]
values["elasticsearch.image"] = fmt.Sprintf("%s:%d/%s", e.LocalHostName, e.LocalRepositoryPort, imageMap["elasticsearch_image_name"])
values["elasticsearch.imageTag"] = imageMap["elasticsearch_image_tag"]
if isInstall {
if _, ok := values["elasticsearch.esJavaOpts.item"]; !ok {
values["elasticsearch.esJavaOpts.item"] = 1
}
values["elasticsearch.esJavaOpts"] = fmt.Sprintf("-Xmx%vg -Xms%vg", values["elasticsearch.esJavaOpts.item"], values["elasticsearch.esJavaOpts.item"])
delete(values, "elasticsearch.esJavaOpts.item")
if _, ok := values["elasticsearch.volumeClaimTemplate.resources.requests.storage"]; ok {
values["elasticsearch.volumeClaimTemplate.resources.requests.storage"] = fmt.Sprintf("%vGi", values["elasticsearch.volumeClaimTemplate.resources.requests.storage"])
}
}
str, _ := json.Marshal(&values)
e.Tool.Vars = string(str)
}
func (e EFK) Install(toolDetail model.ClusterToolDetail) error {
e.setDefaultValue(toolDetail, true)
if err := installChart(e.Cluster.HelmClient, e.Tool, constant.LoggingChartName, toolDetail.ChartVersion); err != nil {
return err
}
ingressItem := &Ingress{
name: constant.DefaultLoggingIngressName,
url: constant.DefaultLoggingIngress,
service: constant.DefaultLoggingServiceName,
port: 9200,
version: e.Cluster.Version,
}
if err := createRoute(e.Cluster.Namespace, ingressItem, e.Cluster.KubeClient); err != nil {
return err
}
if err := waitForStatefulSetsRunning(e.Cluster.Namespace, constant.DefaultLoggingStateSetsfulName, 1, e.Cluster.KubeClient); err != nil {
return err
}
return nil
}
func (e EFK) Upgrade(toolDetail model.ClusterToolDetail) error {
e.setDefaultValue(toolDetail, false)
return upgradeChart(e.Cluster.HelmClient, e.Tool, constant.LoggingChartName, toolDetail.ChartVersion)
}
func (e EFK) Uninstall() error {
return uninstall(e.Cluster.Namespace, e.Tool, constant.DefaultLoggingIngressName, e.Cluster.Version, e.Cluster.HelmClient, e.Cluster.KubeClient)
}