Auto-restart Datadog agents on API key change in a K8s Secret #1718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
When the API key is stored in a Kubernetes Secret, the reconciliation code adds a SHA256 hash of the secret's data as a new environment variable. This change spreads to all objects.
So, if the secret's data changes, it triggers a rolling update for the cluster agent ReplicaSet and agent DaemonSet, making them use the new API key.
Motivation
The Datadog agent doesn't update secrets already in memory, like the API key. If the API key is changed and the old one is revoked, the agent and cluster agent can't send data until they are restarted with the new key.
Even though data is buffered, there might be a temporary gap and a risk of data loss if the agents can't send data.
Using Kubernetes' built-in methods to update the agents when the key changes avoid the need for custom code. Not using labels and annotations prevents the accidental creation of custom metrics.
Additional Notes
No notes
Minimum Agent Versions
Not applicable, changes are on the reconciliation code.
Describe your test plan
I created additional test cases in internal/controller/datadogagent/controller_reconcile_v2_test.go and also manually verified the change works in a kind cluster
Manual test plan:
examples/datadogagent/datadog-agent-with-secret-keys.yaml
Checklist
bug
,enhancement
,refactoring
,documentation
,tooling
, and/ordependencies
qa/skip-qa
label