datadog-operator
datadog-operator copied to clipboard
Add minimal OTel Agent container
What does this PR do?
Minimal OTel agent setup with some defaults in Operator. It's enabled by otelAgentEnabled argument (disabled by default) but enabled for local testing in this branch here.
Added two TODO items where custom volume mounts and env vars should be added.
To run locally you'll need Kind cluster and Go 1.22:
# Create a local Kind cluster
# build image
make build && make docker-build
# load image in the kind cluster
kind load docker-image --name mycluster $(make -s echo-img)
# deploy
make deploy
# switch to default installation namespace
kubens system
# create secret
kubectl create secret generic datadog-secret --from-literal api-key=API_KEY
# apply DatadogAgent manifest
kubectl apply -f agent.yaml
I used following manifest for tests, it has custom command, env var and image tag overrides for illustration
apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
name: datadog-agent
spec:
global:
credentials:
apiSecret:
secretName: datadog-secret
keyName: api-key
appSecret:
secretName: datadog-secret
keyName: app-key
clusterName: otel-test
kubelet:
tlsVerify: false
features:
logCollection:
enabled: true
override:
nodeAgent:
image:
name: gcr.io/datadoghq/agent:7.54.0
containers:
otel-agent:
command:
- /bin/sleep
- "300"
env:
- name: DD_LOG_LEVEL
value: "debug"
Resulting OTel container
- command:
- /bin/sleep
- "300"
env:
- name: KUBERNETES
value: "yes"
- name: DD_CLUSTER_AGENT_ENABLED
value: "true"
- name: DD_CLUSTER_AGENT_KUBERNETES_SERVICE_NAME
value: datadog-agent-cluster-agent
- name: DD_CLUSTER_AGENT_TOKEN_NAME
value: datadog-agent-token
- name: DD_KUBERNETES_KUBELET_HOST
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: DD_CLUSTER_NAME
value: kind-rc2
- name: DD_SITE
value: datadoghq.com
- name: DD_LOG_LEVEL
value: debug
- name: DD_KUBELET_TLS_VERIFY
value: "false"
- name: DD_CLUSTER_AGENT_AUTH_TOKEN
valueFrom:
secretKeyRef:
key: token
name: datadog-agent-token
- name: DD_API_KEY
valueFrom:
secretKeyRef:
key: api-key
name: datadog-secret
- name: DD_APP_KEY
valueFrom:
secretKeyRef:
key: app-key
name: datadog-secret
- name: DD_DOGSTATSD_SOCKET
value: /var/run/datadog/dsd.socket
- name: DD_REMOTE_CONFIGURATION_ENABLED
value: "true"
image: gcr.io/datadoghq/agent:7.54.0
imagePullPolicy: IfNotPresent
name: otel-agent
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/log/datadog
name: logdatadog
- mountPath: /etc/datadog-agent/auth
name: datadog-agent-auth
readOnly: true
- mountPath: /etc/datadog-agent
name: config
- mountPath: /var/run/datadog
name: dsdsocket
- mountPath: /host/var/run
name: runtimesocketdir
readOnly: true
- mountPath: /host/proc
name: procdir
readOnly: true
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-rtqb5
readOnly: true
Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Minimum Agent Versions
Are there minimum versions of the Datadog Agent and/or Cluster Agent required?
- Agent: vX.Y.Z
- Cluster Agent: vX.Y.Z
Describe your test plan
Write there any instructions and details you may have to test your PR.
Checklist
- [ ] PR has at least one valid label:
bug,enhancement,refactoring,documentation,tooling, and/ordependencies - [ ] PR has a milestone or the
qa/skip-qalabel
Codecov Report
Attention: Patch coverage is 15.94203% with 58 lines in your changes missing coverage. Please review.
Project coverage is 54.87%. Comparing base (
76d9786) to head (c647c57). Report is 355 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #1269 +/- ##
==========================================
- Coverage 54.97% 54.87% -0.11%
==========================================
Files 243 243
Lines 28058 28120 +62
==========================================
+ Hits 15426 15430 +4
- Misses 11759 11815 +56
- Partials 873 875 +2
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 54.87% <15.94%> (-0.11%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| controllers/datadogagent/controller.go | 59.50% <100.00%> (+0.24%) |
:arrow_up: |
| controllers/datadogagent/feature/types.go | 26.92% <ø> (ø) |
|
| controllers/setup.go | 56.66% <100.00%> (+0.36%) |
:arrow_up: |
| main.go | 0.00% <0.00%> (ø) |
|
| ...lers/datadogagent/feature/enabledefault/feature.go | 29.08% <40.90%> (-0.82%) |
:arrow_down: |
| ...ontrollers/datadogagent/component/agent/default.go | 0.00% <0.00%> (ø) |
Continue to review full report in Codecov by Sentry.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 76d9786...c647c57. Read the comment docs.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.