-
Notifications
You must be signed in to change notification settings - Fork 98
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
Conversation
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.
This pull request does not contain a valid label. Please add one of the following labels: bug, enhancement, documentation
* 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.
dd88076
to
8c9b7ce
Compare
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
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) { |
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.
This seems like it'll always be the case, why adding it?
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.
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) { |
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.
This will never be the case I believe
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.
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) { |
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.
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) { |
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.
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) { |
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.
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 && |
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.
why is the config necessary for the admission controller?
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.
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.
What does this PR do?
spec.Agent
is empty.spec.ClusterAgent
is empty.
Motivation
DatadogAgent should valide even if only "spec.Credentials" and
spec.Features
areprovided.
Additional Notes
N/A
Describe your test plan
Deploy the example:
examples/datadogagent/datadog-agent-with-credential-secret.yaml
Expected results: