[CECO-1240] Rename profile label key
What does this PR do?
- Renames the profile label key from
agent.datadoghq.com/profiletoagent.datadoghq.com/datadogagentprofile - Uses the dap name only as the label value instead of
<namespace>-<name>, e.g.agent.datadoghq.com/datadogagentprofile:dap-testinstead ofagent.datadoghq.com/profile:default-dap-test - Removes old profile label from nodes, daemonsets, and pods
- Uses
datadogagentprofileanddatadogagentprofile_namespaceinstead ofnameandnamespacein profile-specific logs so they are more useful in the logs ui
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
- Test the migration from operator <1.8.0 to 1.8.0+ to test the migration from old profile label to new profile label
a. Spin up <1.8.0 operator version with profiles enabled:
helm install operator --set image.tag="1.6.0" --set datadogAgentProfile.enabled=true datadog/datadog-operatorb. Deploy DDA and DAP c. Check that the agent pod, ds, ds pod template spec, and node have the old label key and valueagent.datadoghq.com/profile:<profile-ns>-<profile-name>and that the nodeaffinity for the default daemonset (ds that doesn't have the namexxx-with-profile-<profile-ns>-<profile-name>) has an expression for theagent.datadoghq.com/profilekey d. Upgrade the operator to 1.8.0+ e. Check that the agent pod, ds, ds pod template spec, and node have the new label key and valueagent.datadoghq.com/datadogagentprofile:<profile-name>and that the nodeaffinity for the default daemonset has an expression for theagent.datadoghq.com/datadogagentprofilekey - Test that the removal of profiles removes the profile label on nodes
a. Delete the profile
b. Check that the agent pods, ds, and nodes don't have any profile label. The default daemonset should still have a nodeaffinity expression for the
agent.datadoghq.com/datadogagentprofilekey
Example label and nodeaffinity expression (for <1.8.0):
# label
agent.datadoghq.com/profile: default-dap-test
# nodeaffinity expression
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: agent.datadoghq.com/profile
operator: DoesNotExist
Example label and nodeaffinity expression (for 1.8.0+):
# label
agent.datadoghq.com/datadogagentprofile: dap-test
# nodeaffinity expression
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: agent.datadoghq.com/datadogagentprofile
operator: DoesNotExist
- Create an invalid profile (remove the profileAffinity from the profile) and check that the log uses
datadogagentprofileanddatadogagentprofile_namespaceinstead ofnameandnamespace
{"level":"ERROR","ts":"2024-06-13T16:08:28Z","logger":"controllers.DatadogAgent","msg":"profile spec is invalid, skipping","datadogagent":"default/datadog","datadogagentprofile":"invalid-dap","datadogagentprofile_namespace":"default","error":"profileAffinity must be defined"}
{"level":"ERROR","ts":"2024-06-13T16:08:28Z","logger":"controllers.DatadogAgent","msg":"profile cannot be applied","datadogagent":"default/datadog","datadogagentprofile":"invalid-dap","datadogagentprofile_namespace":"default","error":"profileAffinity must be defined"}
Checklist
- [x] PR has at least one valid label:
bug,enhancement,refactoring,documentation,tooling, and/ordependencies - [x] PR has a milestone or the
qa/skip-qalabel
Codecov Report
Attention: Patch coverage is 69.23077% with 8 lines in your changes missing coverage. Please review.
Project coverage is 55.33%. Comparing base (
ff60347) to head (b5feb95).
Additional details and impacted files
@@ Coverage Diff @@
## main #1230 +/- ##
=======================================
Coverage 55.32% 55.33%
=======================================
Files 241 241
Lines 27889 27889
=======================================
+ Hits 15430 15432 +2
+ Misses 11587 11586 -1
+ Partials 872 871 -1
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 55.33% <69.23%> (+<0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files | Coverage Δ | |
|---|---|---|
| ...ontrollers/datadogagent/controller_reconcile_v2.go | 53.91% <100.00%> (ø) |
|
| controllers/datadogagent/finalizer.go | 63.33% <88.88%> (+2.64%) |
:arrow_up: |
| ...rollers/datadogagent/controller_reconcile_agent.go | 50.42% <77.77%> (+0.28%) |
:arrow_up: |
| pkg/agentprofile/agent_profile.go | 60.74% <50.00%> (-0.33%) |
:arrow_down: |
| ...ers/datadogagent/controller_reconcile_v2_common.go | 27.46% <0.00%> (-0.30%) |
:arrow_down: |
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 ff60347...b5feb95. Read the comment docs.