Skip to content

[Backport v1.26] Fix AppArmor annotations for absent containers in annotation overrides#2899

Merged
tbavelier merged 1 commit into
v1.26from
backport-2897-to-v1.26
Apr 14, 2026
Merged

[Backport v1.26] Fix AppArmor annotations for absent containers in annotation overrides#2899
tbavelier merged 1 commit into
v1.26from
backport-2897-to-v1.26

Conversation

@dd-octo-sts

@dd-octo-sts dd-octo-sts Bot commented Apr 14, 2026

Copy link
Copy Markdown

Backport 9678903 from #2897.


…verrides

The fix in a0dc8c0 added a container existence check to overrideAppArmorProfile(), preventing invalid AppArmor annotations when a container (e.g. security-agent with directSendFromSystemProbe=true) is absent from the pod spec.

However, the same guard was missing from the direct annotation loop in PodTemplateSpec(), which blindly copies spec.override.nodeAgent.annotations to the pod template. Any AppArmor annotation set via that path would bypass the existing fix and still produce an invalid DaemonSet.

Apply the same container existence check when iterating override.Annotations: skip AppArmor annotations (container.apparmor.security.beta.kubernetes.io/<name>) if <name> does not match any container in the pod spec.

What does this PR do?

A brief description of the change being made with this pull request.

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/or dependencies
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed (see: signing commits)

#2897)

* Fix AppArmor annotations for absent containers in direct annotation overrides

The fix in a0dc8c0 added a container existence check to
overrideAppArmorProfile(), preventing invalid AppArmor annotations when
a container (e.g. security-agent with directSendFromSystemProbe=true) is
absent from the pod spec.

However, the same guard was missing from the direct annotation loop in
PodTemplateSpec(), which blindly copies spec.override.nodeAgent.annotations
to the pod template. Any AppArmor annotation set via that path would bypass
the existing fix and still produce an invalid DaemonSet.

Apply the same container existence check when iterating override.Annotations:
skip AppArmor annotations (container.apparmor.security.beta.kubernetes.io/<name>)
if <name> does not match any container in the pod spec.

* Use slices shared helper instead of duplicating same logic

* Add unit tests

---------

Co-authored-by: Timothée Bavelier <[email protected]>
(cherry picked from commit 9678903)
@dd-octo-sts
dd-octo-sts Bot requested a review from a team as a code owner April 14, 2026 07:04
@dd-octo-sts dd-octo-sts Bot added bug Something isn't working backport label added by backport action bot label added by backport bot team/container-platform labels Apr 14, 2026
@dd-octo-sts dd-octo-sts Bot added this to the v1.26.0 milestone Apr 14, 2026
@codecov-commenter

codecov-commenter commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.07%. Comparing base (6c7d6e8) to head (0c9eaa9).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##            v1.26    #2899      +/-   ##
==========================================
+ Coverage   40.06%   40.07%   +0.01%     
==========================================
  Files         319      319              
  Lines       28039    28041       +2     
==========================================
+ Hits        11233    11237       +4     
+ Misses      15983    15982       -1     
+ Partials      823      822       -1     
Flag Coverage Δ
unittests 40.07% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
...rnal/controller/datadogagent/override/container.go 95.94% <100.00%> (-0.16%) ⬇️
...ontroller/datadogagent/override/podtemplatespec.go 80.12% <100.00%> (+2.42%) ⬆️

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 6c7d6e8...0c9eaa9. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tbavelier
tbavelier merged commit 7d61c8e into v1.26 Apr 14, 2026
57 checks passed
@tbavelier
tbavelier deleted the backport-2897-to-v1.26 branch April 14, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport label added by backport action bot label added by backport bot bug Something isn't working team/container-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants