datadog-operator icon indicating copy to clipboard operation
datadog-operator copied to clipboard

[profiles] Override node agent env vars with profiles

Open khewonc opened this issue 1 year ago • 1 comments

What does this PR do?

Adds the ability to override node agent env vars with profiles

Motivation

Internal request https://datadoghq.atlassian.net/browse/CECO-1225

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: n/a
  • Cluster Agent: n/a

Describe your test plan

  • Spin up the operator with profiles enabled
  • Deploy a DatadogAgent with an env var override for one of the agent containers. Example:
  override:
    nodeAgent:
      containers:
        agent:
          env:
            - name: TEST
              value: "foo"
  • Check that the override works. In the above example, the agent container should have env var TEST: foo
  • Apply a profile that:
    • overrides the DatadogAgent's env var
    • adds a new env var using value
    • adds a new env var using valueFrom
    override:
      nodeAgent:
        containers:
          agent:
            env:
            - name: TEST
              value: "test"
            - {name: TEST_VALUE_FROM, valueFrom: {fieldRef: {fieldPath: status.hostIP}}}
            - name: ANOTHER_VALUE_FROM
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            resources:
              limits:
                cpu: "0.25"
          trace-agent:
            env:
            - name: TRACE_TEST
              value: "trace_test"
  • Check for expected results. If using the above examples, we'd expect the agent container for a profile-created node agent had env var TEST:test but the node agent container that wasn't created by the profile still had TEST:foo. The profile-created node agent should also have both TEST_VALUE_FROM and ANOTHER_VALUE_FROM set to the node's status.hostIP. The trace agent should have TRACE_TEST:trace_test and the process agent shouldn't have any env var overrides
# profile-created node agent
# agent container
      TEST:                                                  test
      TEST_VALUE_FROM:                                        (v1:status.hostIP)
      ANOTHER_VALUE_FROM:                                     (v1:status.hostIP)
# trace agent container
      TRACE_TEST:                                trace_test

Checklist

  • [x] PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • [x] PR has a milestone or the qa/skip-qa label

khewonc avatar Jul 01 '24 21:07 khewonc

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 55.01%. Comparing base (979aa8e) to head (4519c95). Report is 363 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1256   +/-   ##
=======================================
  Coverage   55.01%   55.01%           
=======================================
  Files         243      243           
  Lines       28002    28003    +1     
=======================================
+ Hits        15404    15405    +1     
  Misses      11729    11729           
  Partials      869      869           
Flag Coverage Δ
unittests 55.01% <100.00%> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...is/datadoghq/v1alpha1/datadogagentprofile_types.go 100.00% <ø> (ø)
pkg/agentprofile/agent_profile.go 63.32% <100.00%> (+0.14%) :arrow_up:

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 979aa8e...4519c95. 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.

codecov-commenter avatar Jul 01 '24 21:07 codecov-commenter