-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathcollector.go
More file actions
88 lines (74 loc) · 2.2 KB
/
Copy pathcollector.go
File metadata and controls
88 lines (74 loc) · 2.2 KB
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
84
85
86
87
88
package framework
import (
"context"
"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.134.0"
)
// InstallCollector installs the otel-collector.
func InstallCollector() ([]byte, error) {
ctx := context.Background()
repoAddArgs := []string{
"repo",
"add",
"open-telemetry",
"https://open-telemetry.github.io/opentelemetry-helm-charts",
}
if output, err := exec.CommandContext(ctx, "helm", repoAddArgs...).CombinedOutput(); err != nil {
return output, err
}
if output, err := exec.CommandContext(
ctx,
"helm",
"repo",
"update",
).CombinedOutput(); err != nil {
return output, fmt.Errorf("failed to update helm repos: %w; output: %s", err, string(output))
}
args := []string{
"install",
collectorChartReleaseName,
"open-telemetry/opentelemetry-collector",
"--create-namespace",
"--namespace", CollectorNamespace,
"--version", collectorChartVersion,
"-f", "manifests/telemetry/collector-values.yaml",
"--wait",
}
return exec.CommandContext(ctx, "helm", args...).CombinedOutput()
}
// UninstallCollector uninstalls the otel-collector.
func UninstallCollector(resourceManager ResourceManager) ([]byte, error) {
args := []string{
"uninstall", collectorChartReleaseName,
"--namespace", CollectorNamespace,
}
output, err := exec.CommandContext(context.Background(), "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
}