-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathcollector.go
77 lines (64 loc) · 1.9 KB
/
collector.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
package framework
import (
"fmt"
"os/exec"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
CollectorNamespace = "collector"
collectorChartReleaseName = "otel-collector"
//nolint:lll
// renovate: datasource=helm depName=opentelemetry-collector registryUrl=https://open-telemetry.github.io/opentelemetry-helm-charts
collectorChartVersion = "0.111.0"
)
// InstallCollector installs the otel-collector.
func InstallCollector() ([]byte, error) {
repoAddArgs := []string{
"repo",
"add",
"open-telemetry",
"https://open-telemetry.github.io/opentelemetry-helm-charts",
}
if output, err := exec.Command("helm", repoAddArgs...).CombinedOutput(); err != nil {
return output, err
}
args := []string{
"install",
collectorChartReleaseName,
"open-telemetry/opentelemetry-collector",
"--create-namespace",
"--namespace", CollectorNamespace,
"--version", collectorChartVersion,
"-f", "manifests/telemetry/collector-values.yaml",
"--wait",
}
return exec.Command("helm", args...).CombinedOutput()
}
// UninstallCollector uninstalls the otel-collector.
func UninstallCollector(resourceManager ResourceManager) ([]byte, error) {
args := []string{
"uninstall", collectorChartReleaseName,
"--namespace", CollectorNamespace,
}
output, err := exec.Command("helm", args...).CombinedOutput()
if err != nil {
return output, err
}
return nil, resourceManager.DeleteNamespace(CollectorNamespace)
}
// GetCollectorPodName returns the name of the collector Pod.
func GetCollectorPodName(resourceManager ResourceManager) (string, error) {
collectorPodNames, err := resourceManager.GetPodNames(
CollectorNamespace,
client.MatchingLabels{
"app.kubernetes.io/name": "opentelemetry-collector",
},
)
if err != nil {
return "", err
}
if len(collectorPodNames) != 1 {
return "", fmt.Errorf("expected 1 collector pod, got %d", len(collectorPodNames))
}
return collectorPodNames[0], nil
}