From 546b74427a0f8faedb5b03bda95afcf73f3bebf4 Mon Sep 17 00:00:00 2001 From: mrdoggopat Date: Wed, 2 Oct 2024 09:30:32 -0400 Subject: [PATCH] refactor otlp feature.go a bit more --- api/datadoghq/v2alpha1/test/builder.go | 10 ++++---- .../datadogagent/feature/otlp/feature.go | 23 ++++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/api/datadoghq/v2alpha1/test/builder.go b/api/datadoghq/v2alpha1/test/builder.go index 486755b3f..83c64f662 100644 --- a/api/datadoghq/v2alpha1/test/builder.go +++ b/api/datadoghq/v2alpha1/test/builder.go @@ -607,21 +607,21 @@ func (builder *DatadogAgentBuilder) WithOTLPGRPCSettings(enabled bool, hostPortE builder.datadogAgent.Spec.Features.OTLP.Receiver.Protocols.GRPC = &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(enabled), HostPortConfig: &v2alpha1.HostPortConfig{ - Enabled: apiutils.NewBoolPointer(hostportenabled), - Port: apiutils.NewInt32Pointer(customhostport), + Enabled: apiutils.NewBoolPointer(hostPortEnabled), + Port: apiutils.NewInt32Pointer(customHostPort), }, Endpoint: apiutils.NewStringPointer(endpoint), } return builder } -func (builder *DatadogAgentBuilder) WithOTLPHTTPSettings(enabled bool, hostportenabled bool, customhostport int32, endpoint string) *DatadogAgentBuilder { +func (builder *DatadogAgentBuilder) WithOTLPHTTPSettings(enabled bool, hostPortEnabled bool, customHostPort int32, endpoint string) *DatadogAgentBuilder { builder.initOTLP() builder.datadogAgent.Spec.Features.OTLP.Receiver.Protocols.HTTP = &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(enabled), HostPortConfig: &v2alpha1.HostPortConfig{ - Enabled: apiutils.NewBoolPointer(hostportenabled), - Port: apiutils.NewInt32Pointer(customhostport), + Enabled: apiutils.NewBoolPointer(hostPortEnabled), + Port: apiutils.NewInt32Pointer(customHostPort), }, Endpoint: apiutils.NewStringPointer(endpoint), } diff --git a/internal/controller/datadogagent/feature/otlp/feature.go b/internal/controller/datadogagent/feature/otlp/feature.go index 939169ca8..cb7036d92 100644 --- a/internal/controller/datadogagent/feature/otlp/feature.go +++ b/internal/controller/datadogagent/feature/otlp/feature.go @@ -75,9 +75,7 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req f.grpcEnabled = true } if otlp.Receiver.Protocols.GRPC.HostPortConfig != nil { - if apiutils.BoolValue(otlp.Receiver.Protocols.GRPC.HostPortConfig.Enabled) { - f.grpcHostPortEnabled = *otlp.Receiver.Protocols.GRPC.HostPortConfig.Enabled - } + f.grpcHostPortEnabled = apiutils.BoolValue(otlp.Receiver.Protocols.GRPC.HostPortConfig.Enabled) if otlp.Receiver.Protocols.GRPC.HostPortConfig.Port != nil { f.grpcCustomHostPort = *otlp.Receiver.Protocols.GRPC.HostPortConfig.Port } @@ -90,9 +88,7 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req f.httpEnabled = true } if otlp.Receiver.Protocols.HTTP.HostPortConfig != nil { - if apiutils.BoolValue(otlp.Receiver.Protocols.HTTP.HostPortConfig.Enabled) { - f.httpHostPortEnabled = *otlp.Receiver.Protocols.HTTP.HostPortConfig.Enabled - } + f.httpHostPortEnabled = apiutils.BoolValue(otlp.Receiver.Protocols.HTTP.HostPortConfig.Enabled) if otlp.Receiver.Protocols.HTTP.HostPortConfig.Port != nil { f.httpCustomHostPort = *otlp.Receiver.Protocols.HTTP.HostPortConfig.Port } @@ -294,9 +290,9 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov Protocol: corev1.ProtocolTCP, } if f.grpcHostPortEnabled { - otlpgrpcPort.HostPort = f.grpcCustomHostPort - if f.grpcCustomHostPort == 0 { - otlpgrpcPort.HostPort = port + otlpgrpcPort.HostPort = port + if f.grpcCustomHostPort != 0 { + otlpgrpcPort.HostPort = f.grpcCustomHostPort } } envVar := &corev1.EnvVar{ @@ -322,17 +318,16 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov Protocol: corev1.ProtocolTCP, } if f.httpHostPortEnabled { - otlphttpPort.HostPort = f.httpCustomHostPort - if f.httpCustomHostPort == 0 { - otlphttpPort.HostPort = port + otlphttpPort.HostPort = port + if f.httpCustomHostPort != 0 { + otlphttpPort.HostPort = f.httpCustomHostPort } } - managers.Port().AddPortToContainer(apicommon.CoreAgentContainerName, otlphttpPort) envVar := &corev1.EnvVar{ Name: apicommon.DDOTLPHTTPEndpoint, Value: f.httpEndpoint, } - + managers.Port().AddPortToContainer(apicommon.CoreAgentContainerName, otlphttpPort) managers.EnvVar().AddEnvVarToContainer(apicommon.CoreAgentContainerName, envVar) if f.usingAPM { managers.EnvVar().AddEnvVarToContainer(apicommon.TraceAgentContainerName, envVar)