-
Notifications
You must be signed in to change notification settings - Fork 98
/
feature.go
126 lines (103 loc) · 4.94 KB
/
feature.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package livecontainer
import (
corev1 "k8s.io/api/core/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object/volume"
)
func init() {
err := feature.Register(feature.LiveContainerIDType, buildLiveContainerFeature)
if err != nil {
panic(err)
}
}
func buildLiveContainerFeature(options *feature.Options) feature.Feature {
liveContainerFeat := &liveContainerFeature{}
return liveContainerFeat
}
type liveContainerFeature struct{}
// ID returns the ID of the Feature
func (f *liveContainerFeature) ID() feature.IDType {
return feature.LiveContainerIDType
}
// Configure is used to configure the feature from a v2alpha1.DatadogAgent instance.
func (f *liveContainerFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.RequiredComponents) {
if dda.Spec.Features.LiveContainerCollection != nil && apiutils.BoolValue(dda.Spec.Features.LiveContainerCollection.Enabled) {
reqComp = feature.RequiredComponents{
Agent: feature.RequiredComponent{
IsRequired: apiutils.NewBoolPointer(true),
Containers: []apicommonv1.AgentContainerName{
apicommonv1.CoreAgentContainerName,
apicommonv1.ProcessAgentContainerName,
},
},
}
}
return reqComp
}
// ConfigureV1 use to configure the feature from a v1alpha1.DatadogAgent instance.
func (f *liveContainerFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) (reqComp feature.RequiredComponents) {
if dda.Spec.Agent.Process != nil && *dda.Spec.Agent.Process.Enabled {
reqComp = feature.RequiredComponents{
Agent: feature.RequiredComponent{
IsRequired: apiutils.NewBoolPointer(true),
Containers: []apicommonv1.AgentContainerName{
apicommonv1.CoreAgentContainerName,
apicommonv1.ProcessAgentContainerName,
},
},
}
}
return reqComp
}
// ManageDependencies allows a feature to manage its dependencies.
// Feature's dependencies should be added in the store.
func (f *liveContainerFeature) ManageDependencies(managers feature.ResourceManagers, components feature.RequiredComponents) error {
return nil
}
// ManageClusterAgent allows a feature to configure the ClusterAgent's corev1.PodTemplateSpec
// It should do nothing if the feature doesn't need to configure it.
func (f *liveContainerFeature) ManageClusterAgent(managers feature.PodTemplateManagers) error {
return nil
}
// ManageSingleContainerNodeAgent allows a feature to configure the Agent container for the Node Agent's corev1.PodTemplateSpec
// if SingleContainerStrategy is enabled and can be used with the configured feature set.
// It should do nothing if the feature doesn't need to configure it.
func (f *liveContainerFeature) ManageSingleContainerNodeAgent(managers feature.PodTemplateManagers, provider string) error {
f.manageNodeAgent(apicommonv1.UnprivilegedSingleAgentContainerName, managers, provider)
return nil
}
// ManageNodeAgent allows a feature to configure the Node Agent's corev1.PodTemplateSpec
// It should do nothing if the feature doesn't need to configure it.
func (f *liveContainerFeature) ManageNodeAgent(managers feature.PodTemplateManagers, provider string) error {
f.manageNodeAgent(apicommonv1.ProcessAgentContainerName, managers, provider)
return nil
}
func (f *liveContainerFeature) manageNodeAgent(agentContainerName apicommonv1.AgentContainerName, managers feature.PodTemplateManagers, provider string) error {
// cgroups volume mount
cgroupsVol, cgroupsVolMount := volume.GetVolumes(apicommon.CgroupsVolumeName, apicommon.CgroupsHostPath, apicommon.CgroupsMountPath, true)
managers.VolumeMount().AddVolumeMountToContainer(&cgroupsVolMount, agentContainerName)
managers.Volume().AddVolume(&cgroupsVol)
// procdir volume mount
procdirVol, procdirVolMount := volume.GetVolumes(apicommon.ProcdirVolumeName, apicommon.ProcdirHostPath, apicommon.ProcdirMountPath, true)
managers.VolumeMount().AddVolumeMountToContainer(&procdirVolMount, agentContainerName)
managers.Volume().AddVolume(&procdirVol)
managers.EnvVar().AddEnvVarToContainer(agentContainerName, &corev1.EnvVar{
Name: apicommon.DDContainerCollectionEnabled,
Value: "true",
})
return nil
}
// ManageClusterChecksRunner allows a feature to configure the ClusterChecksRunner's corev1.PodTemplateSpec
// It should do nothing if the feature doesn't need to configure it.
func (f *liveContainerFeature) ManageClusterChecksRunner(managers feature.PodTemplateManagers) error {
return nil
}