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

[CECO-1240] Rename profile label key

Open khewonc opened this issue 8 months 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