Skip to content
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

Improve defaulting when spec.Agent|ClusterAgent empty #351

Merged
merged 2 commits into from
Aug 10, 2021

Conversation

clamoriniere
Copy link
Collaborator

What does this PR do?

  • Improve agent defaulting by enabling it if spec.Agent is empty.
  • Improve ClusterAgent defaulting by enabling it if spec.ClusterAgent
    is empty.
  • Fix credentials verification function.

Motivation

DatadogAgent should valide even if only "spec.Credentials" and spec.Features are
provided.

Additional Notes

N/A

Describe your test plan

Deploy the example: examples/datadogagent/datadog-agent-with-credential-secret.yaml

Expected results:

  • ClusterAgent should be deployed
  • Agent should be deployed

@clamoriniere clamoriniere requested a review from a team as a code owner August 9, 2021 11:42
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: bug, enhancement, documentation

@clamoriniere clamoriniere added this to the v0.7 milestone Aug 9, 2021
@clamoriniere clamoriniere added bug Something isn't working component/controller labels Aug 9, 2021
* Improve agent defaulting by enabling it if `spec.Agent` is empty.
* Improve ClusterAgent defaulting by enabling it if `spec.ClusterAgent`
  is empty.
* Fix credentials verification function.
@codecov-commenter
Copy link

Codecov Report

Merging #351 (8c9b7ce) into main (f8b6a29) will decrease coverage by 0.00%.
The diff coverage is 72.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #351      +/-   ##
==========================================
- Coverage   64.36%   64.36%   -0.01%     
==========================================
  Files          62       62              
  Lines        6879     6907      +28     
==========================================
+ Hits         4428     4446      +18     
- Misses       2135     2144       +9     
- Partials      316      317       +1     
Flag Coverage Δ
unittests 64.36% <72.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
controllers/datadogagent/controller.go 51.80% <ø> (ø)
api/v1alpha1/datadogagent_default.go 82.23% <58.33%> (-1.28%) ⬇️
controllers/datadogagent/secret_agent.go 78.94% <78.94%> (+2.94%) ⬆️
controllers/datadogagent/clusteragent.go 72.35% <100.00%> (+0.10%) ⬆️
controllers/datadogagent/secret.go 46.66% <0.00%> (-1.67%) ⬇️
controllers/datadogagent/utils.go 84.29% <0.00%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f8b6a29...8c9b7ce. Read the comment docs.

@clamoriniere clamoriniere changed the title Improve defaulting when spec.Agent|ClustetAgent empty Improve defaulting when spec.Agent|ClusterAgent empty Aug 9, 2021
Copy link
Contributor

@CharlyF CharlyF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious about extra checks but I might be missing something, looks good otherwise

@@ -902,7 +909,10 @@ func DefaultDatadogFeaturePrometheusScrape(ft *DatadogFeatures) *PrometheusScrap
func DefaultDatadogFeatureNetworkMonitoring(ft *DatadogFeatures) *NetworkMonitoringConfig {
if ft.NetworkMonitoring == nil {
ft.NetworkMonitoring = &NetworkMonitoringConfig{Enabled: NewBoolPointer(false)}
return ft.NetworkMonitoring

if !BoolValue(ft.NetworkMonitoring.Enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it'll always be the case, why adding it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if never we change the default Enabled value.
I tried to use the same pattern on every Default... fonction

@@ -920,15 +930,23 @@ func DefaultDatadogFeatureNetworkMonitoring(ft *DatadogFeatures) *NetworkMonitor
func DefaultDatadogAgentSpecClusterAgent(clusterAgent *DatadogAgentSpecClusterAgentSpec) *DatadogAgentSpecClusterAgentSpec {
if IsEqualStruct(*clusterAgent, DatadogAgentSpecClusterAgentSpec{}) {
clusterAgent.Enabled = NewBoolPointer(true)
return clusterAgent

if !BoolValue(clusterAgent.Enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never be the case I believe

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, it was to follow the same pattern everywhere.

@@ -999,7 +1017,10 @@ func DefaultDatadogAgentSpecClusterAgentConfig(dca *DatadogAgentSpecClusterAgent
func DefaultExternalMetrics(conf *ClusterAgentConfig) *ExternalMetricsConfig {
if conf.ExternalMetrics == nil {
conf.ExternalMetrics = &ExternalMetricsConfig{Enabled: NewBoolPointer(false)}
return conf.ExternalMetrics

if !BoolValue(conf.ExternalMetrics.Enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -1019,7 +1040,10 @@ func DefaultExternalMetrics(conf *ClusterAgentConfig) *ExternalMetricsConfig {
func DefaultAdmissionController(conf *ClusterAgentConfig) *AdmissionControllerConfig {
if conf.AdmissionController == nil {
conf.AdmissionController = &AdmissionControllerConfig{Enabled: NewBoolPointer(defaultAdmissionControllerEnabled)}
return conf.AdmissionController

if !BoolValue(conf.AdmissionController.Enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -1075,7 +1099,10 @@ func DefaultDatadogClusterAgentImage(dca *DatadogAgentSpecClusterAgentSpec, name
func DefaultDatadogAgentSpecClusterChecksRunner(clusterChecksRunner *DatadogAgentSpecClusterChecksRunnerSpec) *DatadogAgentSpecClusterChecksRunnerSpec {
if IsEqualStruct(clusterChecksRunner, DatadogAgentSpecClusterChecksRunnerSpec{}) {
clusterChecksRunner.Enabled = NewBoolPointer(false)
return clusterChecksRunner

if !BoolValue(clusterChecksRunner.Enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -763,7 +766,10 @@ func getClusterAgentMetricsProviderPort(config datadoghqv1alpha1.ClusterAgentCon
}

func getAdmissionControllerServiceName(dda *datadoghqv1alpha1.DatadogAgent) string {
if isClusterAgentEnabled(dda.Spec.ClusterAgent) && dda.Spec.ClusterAgent.Config.AdmissionController != nil && dda.Spec.ClusterAgent.Config.AdmissionController.ServiceName != nil {
if isClusterAgentEnabled(dda.Spec.ClusterAgent) &&
dda.Spec.ClusterAgent.Config != nil &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the config necessary for the admission controller?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the function takes value in dda.Spec.ClusterAgent.Config.AdmissionController.
due to the bug in the DefaultClusterAgent() when if IsEqualStruct(*clusterAgent, DatadogAgentSpecClusterAgentSpec{}) was true, the dda.Spec.ClusterAgent.Config was nil.

I think it is ok to keep this change, because it is always better to check point value before using it.

@clamoriniere clamoriniere merged commit fad93d8 into main Aug 10, 2021
@clamoriniere clamoriniere deleted the clamorinere/defaulting-fix branch August 10, 2021 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component/controller
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants