Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/operator/resources_logs.go
4094 views
1
package operator
2
3
import (
4
gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1"
5
apps_v1 "k8s.io/api/apps/v1"
6
v1 "k8s.io/api/core/v1"
7
)
8
9
func generateLogsDaemonSet(
10
cfg *Config,
11
name string,
12
d gragent.Deployment,
13
) (*apps_v1.DaemonSet, error) {
14
15
d = *(&d).DeepCopy()
16
17
opts := logsPodTemplateOptions()
18
tmpl, selector, err := generatePodTemplate(cfg, name, d, opts)
19
if err != nil {
20
return nil, err
21
}
22
23
spec := apps_v1.DaemonSetSpec{
24
UpdateStrategy: apps_v1.DaemonSetUpdateStrategy{
25
Type: apps_v1.RollingUpdateDaemonSetStrategyType,
26
},
27
Selector: selector,
28
Template: tmpl,
29
}
30
31
return &apps_v1.DaemonSet{
32
ObjectMeta: metadataFromPodTemplate(name, d, tmpl),
33
Spec: spec,
34
}, nil
35
}
36
37
func logsPodTemplateOptions() podTemplateOptions {
38
return podTemplateOptions{
39
Privileged: true,
40
ExtraSelectorLabels: map[string]string{
41
agentTypeLabel: "logs",
42
},
43
ExtraVolumes: []v1.Volume{
44
{
45
Name: "varlog",
46
VolumeSource: v1.VolumeSource{
47
HostPath: &v1.HostPathVolumeSource{Path: "/var/log"},
48
},
49
},
50
{
51
// Needed for docker. Kubernetes will symlink to this directory. For CRI
52
// platforms, this doesn't change anything.
53
Name: "dockerlogs",
54
VolumeSource: v1.VolumeSource{
55
HostPath: &v1.HostPathVolumeSource{Path: "/var/lib/docker/containers"},
56
},
57
},
58
{
59
// Needed for storing positions for recovery.
60
Name: "data",
61
VolumeSource: v1.VolumeSource{
62
HostPath: &v1.HostPathVolumeSource{Path: "/var/lib/grafana-agent/data"},
63
},
64
},
65
},
66
ExtraVolumeMounts: []v1.VolumeMount{
67
{
68
Name: "varlog",
69
ReadOnly: true,
70
MountPath: "/var/log",
71
}, {
72
Name: "dockerlogs",
73
ReadOnly: true,
74
MountPath: "/var/lib/docker/containers",
75
}, {
76
Name: "data",
77
MountPath: "/var/lib/grafana-agent/data",
78
},
79
},
80
ExtraEnvVars: []v1.EnvVar{
81
{
82
Name: "HOSTNAME",
83
ValueFrom: &v1.EnvVarSource{
84
FieldRef: &v1.ObjectFieldSelector{FieldPath: "spec.nodeName"},
85
},
86
},
87
{
88
// Not used anywhere for logs but passed to the config-reloader since it
89
// expects everything is coming from a StatefulSet.
90
Name: "SHARD",
91
Value: "0",
92
},
93
},
94
}
95
}
96
97