-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[defaults] Fix cluster agent token autogeneration #447
Conversation
Codecov Report
@@ Coverage Diff @@
## main #447 +/- ##
=======================================
Coverage 60.60% 60.60%
=======================================
Files 3 3
Lines 132 132
=======================================
Hits 80 80
Misses 40 40
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
defaultClusterAgentToken(dda, dso) | ||
} | ||
|
||
func defaultClusterAgentToken(dda *DatadogAgent, dso *DatadogAgentStatus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this change is not fully backward compatible.
what happen if the dso.ClusterAgent.GeneratedToken
was already defined?
can we add another step in the function to get the token present in status.ClusterAgent.GeneratedToken
if present ? and copy it into dda.Status.DefaultOverride.Credentials.Token
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new commit with this 👍
} else if isClusterAgentEnabled(dda.Spec.ClusterAgent) && dda.Status.ClusterAgent != nil { | ||
data[datadoghqv1alpha1.DefaultTokenKey] = []byte(dda.Status.ClusterAgent.GeneratedToken) | ||
} else if isClusterAgentEnabled(dda.Spec.ClusterAgent) { | ||
if dda.Status.DefaultOverride != nil && dda.Status.DefaultOverride.Credentials != nil && dda.Status.DefaultOverride.Credentials.Token != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: create a function the return the token, or check that it is defined.
I saw the same code here: https://github.com/DataDog/datadog-operator/pull/447/files#diff-c46f55565558bd8d50d96ff9d37415ce9a6adbb913178786b3e413ce10440be4R160-R162
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new commit with this 👍
bbb4113
to
768d927
Compare
What does this PR do?
Currently, when a cluster agent token is not specified, it is not autogenerated properly and agents cannot connect to the cluster agent. This PR fixes the issue.
When a token is not specified, this PR autogenerates one and stores it in the "DefaultOverride" attribute of the spec.
Additional Notes
When the secret that contains the token changes, the cluster agent and the agents are not restarted, so they keep using the old token. This issue is not fixed by this PR yet.
Describe your test plan
credentials.token
). Check the status of the agents (agent status
) and verify that they can connect with the cluster agent. Also check that when the datadog agent is deleted, the secret with the token (has the same name as the datadog agent object) is also deleted. You can also check that in the status of the datadog agent,defaultOverride.credentials.token
matches the token stored in the secret.credentials.token
) and check the same except thedefaultOverride
part, which doesn't apply in this case.