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

[CECO-1240] Rename profile label key

Open khewonc opened this issue 1 year ago • 1 comments

What does this PR do?

  • Renames the profile label key from agent.datadoghq.com/profile to agent.datadoghq.com/datadogagentprofile
  • Uses the dap name only as the label value instead of <namespace>-<name>, e.g. agent.datadoghq.com/datadogagentprofile:dap-test instead of agent.datadoghq.com/profile:default-dap-test
  • Removes old profile label from nodes, daemonsets, and pods
  • Uses datadogagentprofile and datadogagentprofile_namespace instead of name and namespace in 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

  1. 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-operator b. Deploy DDA and DAP c. Check that the agent pod, ds, ds pod template spec, and node have the old label key and value agent.datadoghq.com/profile:<profile-ns>-<profile-name> and that the nodeaffinity for the default daemonset (ds that doesn't have the name xxx-with-profile-<profile-ns>-<profile-name>) has an expression for the agent.datadoghq.com/profile key 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 value agent.datadoghq.com/datadogagentprofile:<profile-name> and that the nodeaffinity for the default daemonset has an expression for the agent.datadoghq.com/datadogagentprofile key
  2. 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/datadogagentprofile key

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
  1. Create an invalid profile (remove the profileAffinity from the profile) and check that the log uses datadogagentprofile and datadogagentprofile_namespace instead of name and namespace
{"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/or dependencies
  • [x] PR has a milestone or the qa/skip-qa label

khewonc avatar Jun 10 '24 20:06 khewonc

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

Impacted file tree graph

@@           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 data Powered by Codecov. Last update ff60347...b5feb95. Read the comment docs.

codecov-commenter avatar Jun 10 '24 20:06 codecov-commenter