Skip to content

Commit

Permalink
Add minimal OTel Agent container (#1269)
Browse files Browse the repository at this point in the history
* Add minimal OTel Agent container

* Fix the otel-agent command path and add a comment where OTel agent container is being added

* fix config path

* Remove test config

* add container port + hostport

* Update main.go

Co-authored-by: Celene <celene@datadoghq.com>

* Update apis/datadoghq/common/v1/types.go

Co-authored-by: Celene <celene@datadoghq.com>

---------

Co-authored-by: Dinesh Gurumurthy <dinesh.gurumurthy@datadoghq.com>
Co-authored-by: Celene <celene@datadoghq.com>
  • Loading branch information
3 people authored Jul 12, 2024
1 parent 76d9786 commit 4bc766f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 7 deletions.
1 change: 1 addition & 0 deletions apis/datadoghq/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const (

AgentCustomConfigVolumePath = "/etc/datadog-agent/datadog.yaml"
SystemProbeConfigVolumePath = "/etc/datadog-agent/system-probe.yaml"
OtelCustomConfigVolumePath = "/etc/datadog-agent/otel-config.yaml"

LogDatadogVolumeName = "logdatadog"
LogDatadogVolumePath = "/var/log/datadog"
Expand Down
2 changes: 2 additions & 0 deletions apis/datadoghq/common/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const (
SecurityAgentContainerName AgentContainerName = "security-agent"
// SystemProbeContainerName is the name of the System Probe container
SystemProbeContainerName AgentContainerName = "system-probe"
// OtelAgent is the name of the OTel container
OtelAgent AgentContainerName = "otel-agent"
// AllContainers is used internally to reference all containers in the pod
AllContainers AgentContainerName = "all"
// ClusterAgentContainerName is the name of the Cluster Agent container
Expand Down
49 changes: 49 additions & 0 deletions controllers/datadogagent/component/agent/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func agentOptimizedContainers(dda metav1.Object, requiredContainers []common.Age
containers = append(containers, securityAgentContainer(dda))
case common.SystemProbeContainerName:
containers = append(containers, systemProbeContainer(dda))
case common.OtelAgent:
containers = append(containers, otelAgentContainer(dda))
}
}

Expand Down Expand Up @@ -186,6 +188,33 @@ func processAgentContainer(dda metav1.Object) corev1.Container {
}
}

func otelAgentContainer(dda metav1.Object) corev1.Container {
return corev1.Container{
Name: string(common.OtelAgent),
Image: agentImage(),
Command: []string{
"/otel-agent",
fmt.Sprintf("--config=%s", apicommon.OtelCustomConfigVolumePath),
},
Env: envVarsForOtelAgent(dda),
VolumeMounts: volumeMountsForOtelAgent(),
Ports: []corev1.ContainerPort{
{
Name: "grpc",
ContainerPort: 4317,
HostPort: 4317,
Protocol: corev1.ProtocolTCP,
},
{
Name: "http",
ContainerPort: 4318,
HostPort: 4318,
Protocol: corev1.ProtocolTCP,
},
},
}
}

func securityAgentContainer(dda metav1.Object) corev1.Container {
return corev1.Container{
Name: string(common.SecurityAgentContainerName),
Expand Down Expand Up @@ -339,6 +368,14 @@ func envVarsForSecurityAgent(dda metav1.Object) []corev1.EnvVar {
return append(envs, commonEnvVars(dda)...)
}

func envVarsForOtelAgent(dda metav1.Object) []corev1.EnvVar {
envs := []corev1.EnvVar{
// TODO: add additional env vars here
}

return append(envs, commonEnvVars(dda)...)
}

func volumeMountsForInitConfig() []corev1.VolumeMount {
return []corev1.VolumeMount{
component.GetVolumeMountForLogs(),
Expand Down Expand Up @@ -439,6 +476,18 @@ func volumeMountsForSeccompSetup() []corev1.VolumeMount {
}
}

func volumeMountsForOtelAgent() []corev1.VolumeMount {
return []corev1.VolumeMount{
// TODO: add/remove volume mounts
component.GetVolumeMountForLogs(),
component.GetVolumeMountForAuth(true),
component.GetVolumeMountForConfig(),
component.GetVolumeMountForDogstatsdSocket(false),
component.GetVolumeMountForRuntimeSocket(true),
component.GetVolumeMountForProc(),
}
}

// DefaultSeccompConfigDataForSystemProbe returns configmap data for the default seccomp profile
func DefaultSeccompConfigDataForSystemProbe() map[string]string {
return map[string]string{
Expand Down
2 changes: 2 additions & 0 deletions controllers/datadogagent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type ReconcilerOptions struct {
IntrospectionEnabled bool
DatadogAgentProfileEnabled bool
ProcessChecksInCoreAgentEnabled bool
OtelAgentEnabled bool
}

// Reconciler is the internal reconciler for Datadog Agent
Expand Down Expand Up @@ -169,6 +170,7 @@ func reconcilerOptionsToFeatureOptions(opts *ReconcilerOptions, logger logr.Logg
SupportExtendedDaemonset: opts.ExtendedDaemonsetOptions.Enabled,
Logger: logger,
ProcessChecksInCoreAgentEnabled: opts.ProcessChecksInCoreAgentEnabled,
OtelAgentEnabled: opts.OtelAgentEnabled,
}
}

Expand Down
34 changes: 27 additions & 7 deletions controllers/datadogagent/feature/enabledefault/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func buildDefaultFeature(options *feature.Options) feature.Feature {

if options != nil {
dF.logger = options.Logger
dF.otelAgentEnabled = options.OtelAgentEnabled
}

return dF
Expand All @@ -68,6 +69,7 @@ type defaultFeature struct {
clusterChecksRunner clusterChecksRunnerConfig
logger logr.Logger
disableNonResourceRules bool
otelAgentEnabled bool

customConfigAnnotationKey string
customConfigAnnotationValue string
Expand Down Expand Up @@ -184,14 +186,32 @@ func (f *defaultFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredC
f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(string(feature.DefaultIDType))
}

return feature.RequiredComponents{
ClusterAgent: feature.RequiredComponent{
IsRequired: &trueValue,
},
Agent: feature.RequiredComponent{
IsRequired: &trueValue,
},
//
// In Operator 1.9 OTel Agent will be configured through a feature.
// In the meantime we add the OTel Agent as a required component here, if the flag is enabled.
if f.otelAgentEnabled {
return feature.RequiredComponents{
ClusterAgent: feature.RequiredComponent{
IsRequired: &trueValue,
},
Agent: feature.RequiredComponent{
IsRequired: &trueValue,
Containers: []commonv1.AgentContainerName{
commonv1.OtelAgent,
},
},
}
} else {
return feature.RequiredComponents{
ClusterAgent: feature.RequiredComponent{
IsRequired: &trueValue,
},
Agent: feature.RequiredComponent{
IsRequired: &trueValue,
},
}
}

}

func (f *defaultFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) feature.RequiredComponents {
Expand Down
1 change: 1 addition & 0 deletions controllers/datadogagent/feature/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ type Options struct {
Logger logr.Logger

ProcessChecksInCoreAgentEnabled bool
OtelAgentEnabled bool
}

// BuildFunc function type used by each Feature during its factory registration.
Expand Down
1 change: 1 addition & 0 deletions controllers/datadogagent/merger/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var AllAgentContainers = map[commonv1.AgentContainerName]struct{}{
commonv1.ProcessAgentContainerName: {},
commonv1.SecurityAgentContainerName: {},
commonv1.SystemProbeContainerName: {},
commonv1.OtelAgent: {},
// DCA containers
commonv1.ClusterAgentContainerName: {},
// CCR container name is equivalent to core agent container name
Expand Down
2 changes: 2 additions & 0 deletions controllers/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type SetupOptions struct {
IntrospectionEnabled bool
DatadogAgentProfileEnabled bool
ProcessChecksInCoreAgentEnabled bool
OtelAgentEnabled bool
}

// ExtendedDaemonsetOptions defines ExtendedDaemonset options
Expand Down Expand Up @@ -154,6 +155,7 @@ func startDatadogAgent(logger logr.Logger, mgr manager.Manager, vInfo *version.I
IntrospectionEnabled: options.IntrospectionEnabled,
DatadogAgentProfileEnabled: options.DatadogAgentProfileEnabled,
ProcessChecksInCoreAgentEnabled: options.ProcessChecksInCoreAgentEnabled,
OtelAgentEnabled: options.OtelAgentEnabled,
},
}).SetupWithManager(mgr)
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type options struct {
datadogAgentProfileEnabled bool
remoteConfigEnabled bool
processChecksInCoreAgentEnabled bool
otelAgentEnabled bool

// Secret Backend options
secretBackendCommand string
Expand Down Expand Up @@ -161,6 +162,7 @@ func (opts *options) Parse() {
flag.BoolVar(&opts.datadogAgentProfileEnabled, "datadogAgentProfileEnabled", false, "Enable DatadogAgentProfile controller (beta)")
flag.BoolVar(&opts.remoteConfigEnabled, "remoteConfigEnabled", false, "Enable RemoteConfig capabilities in the Operator (beta)")
flag.BoolVar(&opts.processChecksInCoreAgentEnabled, "processChecksInCoreAgentEnabled", false, "Enable running process checks in the core agent (beta)")
flag.BoolVar(&opts.otelAgentEnabled, "otelAgentEnabled", false, "Enable the OTel agent container (beta)")

// ExtendedDaemonset configuration
flag.BoolVar(&opts.supportExtendedDaemonset, "supportExtendedDaemonset", false, "Support usage of Datadog ExtendedDaemonset CRD.")
Expand Down Expand Up @@ -289,6 +291,7 @@ func run(opts *options) error {
IntrospectionEnabled: opts.introspectionEnabled,
DatadogAgentProfileEnabled: opts.datadogAgentProfileEnabled,
ProcessChecksInCoreAgentEnabled: opts.processChecksInCoreAgentEnabled,
OtelAgentEnabled: opts.otelAgentEnabled,
}

if err = controllers.SetupControllers(setupLog, mgr, options); err != nil {
Expand Down

0 comments on commit 4bc766f

Please sign in to comment.