-
Notifications
You must be signed in to change notification settings - Fork 90
/
install.go
64 lines (55 loc) · 1.65 KB
/
install.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
package prometheus
import (
"fmt"
"time"
//lint:ignore ST1001 since Ginkgo and Gomega are DSLs this makes the tests more natural to read
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/replicatedhq/kots/e2e/helm"
)
const (
DefaultNamespace = "monitoring"
DefaultReleaseName = "k8s"
)
type Prometheus struct {
options Options
}
type Options struct {
Namespace string
ReleaseName string
}
func New(opts Options) Prometheus {
p := Prometheus{
Options{
Namespace: opts.Namespace,
ReleaseName: opts.ReleaseName,
},
}
if p.options.Namespace == "" {
p.options.Namespace = DefaultNamespace
}
if p.options.ReleaseName == "" {
p.options.ReleaseName = DefaultReleaseName
}
return p
}
func (m *Prometheus) Install(helmCLI *helm.CLI, kubeconfig string) {
session, err := helmCLI.RepoAdd("prometheus-community", "https://prometheus-community.github.io/helm-charts")
Expect(err).WithOffset(1).Should(Succeed(), "helm repo add")
Eventually(session).WithOffset(1).WithTimeout(time.Minute).Should(gexec.Exit(0), "helm repo add")
session, err = helmCLI.Install(
kubeconfig,
"--create-namespace",
fmt.Sprintf("--namespace=%s", m.options.Namespace),
"--wait",
"--set=server.fullnameOverride=prometheus-k8s",
"--set=server.service.servicePort=9090",
m.options.ReleaseName,
"prometheus-community/prometheus",
)
Expect(err).WithOffset(1).Should(Succeed(), "helm install")
Eventually(session).WithOffset(1).WithTimeout(2*time.Minute).Should(gexec.Exit(0), "helm install")
}
func (m *Prometheus) GetURL() string {
return fmt.Sprintf("http://%s.%s.svc.cluster.local:9000", m.options.ReleaseName, m.options.Namespace)
}