From 7fe7979731652651cf2f4b6518a50c75f46e54e5 Mon Sep 17 00:00:00 2001 From: mrmcpat <109171317+mrdoggopat@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:11:57 -0400 Subject: [PATCH] Allow the ability to disable or specify custom host ports for OTLP (#1440) * add the ability to disable hostPorts for otlp and specify custom hostPorts * revise documentation to note that host ports are enabled by default for otlp * fix single container host port logic * refactor some of the logic * fix the logic in the datadogagent defaults for otlp hostports * Update api/datadoghq/v2alpha1/test/builder.go Co-authored-by: khewonc <39867936+khewonc@users.noreply.github.com> * refactor otlp feature.go a bit more Signed-off-by: mrmcpat * tweaking some otlp host port test cases for more clarity Signed-off-by: mrmcpat --------- Signed-off-by: mrmcpat Co-authored-by: khewonc <39867936+khewonc@users.noreply.github.com> --- .../v2alpha1/datadogagent_default.go | 28 ++- .../v2alpha1/datadogagent_default_test.go | 130 ++++++---- api/datadoghq/v2alpha1/datadogagent_types.go | 15 +- api/datadoghq/v2alpha1/test/builder.go | 16 +- .../v2alpha1/zz_generated.deepcopy.go | 10 + .../v2alpha1/zz_generated.openapi.go | 20 +- .../bases/v1/datadoghq.com_datadogagents.yaml | 84 +++++-- docs/configuration.v2alpha1.md | 12 +- .../datadogagent/feature/otlp/feature.go | 54 +++- .../datadogagent/feature/otlp/feature_test.go | 234 +++++++++++++++--- 10 files changed, 480 insertions(+), 123 deletions(-) diff --git a/api/datadoghq/v2alpha1/datadogagent_default.go b/api/datadoghq/v2alpha1/datadogagent_default.go index c4f4bb59a..2c641c7bb 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default.go +++ b/api/datadoghq/v2alpha1/datadogagent_default.go @@ -61,10 +61,12 @@ const ( defaultDogstatsdSocketEnabled bool = true defaultDogstatsdHostSocketPath string = apicommon.DogstatsdAPMSocketHostPath + "/" + apicommon.DogstatsdSocketName - defaultOTLPGRPCEnabled bool = false - defaultOTLPGRPCEndpoint string = "0.0.0.0:4317" - defaultOTLPHTTPEnabled bool = false - defaultOTLPHTTPEndpoint string = "0.0.0.0:4318" + defaultOTLPGRPCEnabled bool = false + defaultOTLPGRPCHostPortEnabled bool = true + defaultOTLPGRPCEndpoint string = "0.0.0.0:4317" + defaultOTLPHTTPEnabled bool = false + defaultOTLPHTTPHostPortEnabled bool = true + defaultOTLPHTTPEndpoint string = "0.0.0.0:4318" defaultRemoteConfigurationEnabled bool = true @@ -381,13 +383,31 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { if ddaSpec.Features.OTLP.Receiver.Protocols.GRPC == nil { ddaSpec.Features.OTLP.Receiver.Protocols.GRPC = &OTLPGRPCConfig{} } + apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Enabled, defaultOTLPGRPCEnabled) + + if apiutils.BoolValue(ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Enabled) { + if ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig == nil { + ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig = &HostPortConfig{} + } + apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig.Enabled, defaultOTLPGRPCHostPortEnabled) + } + apiutils.DefaultStringIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Endpoint, defaultOTLPGRPCEndpoint) if ddaSpec.Features.OTLP.Receiver.Protocols.HTTP == nil { ddaSpec.Features.OTLP.Receiver.Protocols.HTTP = &OTLPHTTPConfig{} } + apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Enabled, defaultOTLPHTTPEnabled) + + if apiutils.BoolValue(ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Enabled) { + if ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig == nil { + ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig = &HostPortConfig{} + } + apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig.Enabled, defaultOTLPHTTPHostPortEnabled) + } + apiutils.DefaultStringIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Endpoint, defaultOTLPHTTPEndpoint) // RemoteConfiguration feature diff --git a/api/datadoghq/v2alpha1/datadogagent_default_test.go b/api/datadoghq/v2alpha1/datadogagent_default_test.go index 0bd4e3bd6..7533de7cb 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default_test.go +++ b/api/datadoghq/v2alpha1/datadogagent_default_test.go @@ -242,12 +242,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -430,12 +432,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, EventCollection: &EventCollectionFeatureConfig{ @@ -551,12 +555,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -681,12 +687,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -806,12 +814,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -933,12 +943,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1065,12 +1077,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(valueTrue), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(valueTrue), + HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)}, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(valueTrue), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(valueTrue), + HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)}, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1190,12 +1204,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1318,12 +1334,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1447,12 +1465,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1574,12 +1594,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1721,12 +1743,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ @@ -1859,12 +1883,14 @@ func Test_defaultFeatures(t *testing.T) { }, OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ GRPC: &OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, HTTP: &OTLPHTTPConfig{ - Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), - Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, RemoteConfiguration: &RemoteConfigurationFeatureConfig{ diff --git a/api/datadoghq/v2alpha1/datadogagent_types.go b/api/datadoghq/v2alpha1/datadogagent_types.go index a12e52ac1..213d2246d 100644 --- a/api/datadoghq/v2alpha1/datadogagent_types.go +++ b/api/datadoghq/v2alpha1/datadogagent_types.go @@ -549,10 +549,15 @@ type OTLPProtocolsConfig struct { // OTLPGRPCConfig contains configuration for the OTLP ingest OTLP/gRPC receiver. // +k8s:openapi-gen=true type OTLPGRPCConfig struct { - // Enable the OTLP/gRPC endpoint. + // Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled. // +optional Enabled *bool `json:"enabled,omitempty"` + // Enable hostPort for OTLP/gRPC + // Default: true + // +optional + HostPortConfig *HostPortConfig `json:"hostPortConfig,omitempty"` + // Endpoint for OTLP/gRPC. // gRPC supports several naming schemes: https://github.com/grpc/grpc/blob/master/doc/naming.md // The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`). @@ -564,10 +569,15 @@ type OTLPGRPCConfig struct { // OTLPHTTPConfig contains configuration for the OTLP ingest OTLP/HTTP receiver. // +k8s:openapi-gen=true type OTLPHTTPConfig struct { - // Enable the OTLP/HTTP endpoint. + // Enable the OTLP/HTTP endpoint. Host port is enabled by default and can be disabled. // +optional Enabled *bool `json:"enabled,omitempty"` + // Enable hostPorts for OTLP/HTTP + // Default: true + // +optional + HostPortConfig *HostPortConfig `json:"hostPortConfig,omitempty"` + // Endpoint for OTLP/HTTP. // Default: '0.0.0.0:4318'. // +optional @@ -967,7 +977,6 @@ type KubeletConfig struct { // HostPortConfig contains host port configuration. type HostPortConfig struct { // Enabled enables host port configuration - // Default: false // +optional Enabled *bool `json:"enabled,omitempty"` diff --git a/api/datadoghq/v2alpha1/test/builder.go b/api/datadoghq/v2alpha1/test/builder.go index de457beb9..ba7b4c7f8 100644 --- a/api/datadoghq/v2alpha1/test/builder.go +++ b/api/datadoghq/v2alpha1/test/builder.go @@ -602,19 +602,27 @@ func (builder *DatadogAgentBuilder) initOTLP() { } } -func (builder *DatadogAgentBuilder) WithOTLPGRPCSettings(enabled bool, endpoint string) *DatadogAgentBuilder { +func (builder *DatadogAgentBuilder) WithOTLPGRPCSettings(enabled bool, hostPortEnabled bool, customHostPort int32, endpoint string) *DatadogAgentBuilder { builder.initOTLP() builder.datadogAgent.Spec.Features.OTLP.Receiver.Protocols.GRPC = &v2alpha1.OTLPGRPCConfig{ - Enabled: apiutils.NewBoolPointer(enabled), + Enabled: apiutils.NewBoolPointer(enabled), + HostPortConfig: &v2alpha1.HostPortConfig{ + Enabled: apiutils.NewBoolPointer(hostPortEnabled), + Port: apiutils.NewInt32Pointer(customHostPort), + }, Endpoint: apiutils.NewStringPointer(endpoint), } return builder } -func (builder *DatadogAgentBuilder) WithOTLPHTTPSettings(enabled bool, 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), + Enabled: apiutils.NewBoolPointer(enabled), + HostPortConfig: &v2alpha1.HostPortConfig{ + Enabled: apiutils.NewBoolPointer(hostPortEnabled), + Port: apiutils.NewInt32Pointer(customHostPort), + }, Endpoint: apiutils.NewStringPointer(endpoint), } return builder diff --git a/api/datadoghq/v2alpha1/zz_generated.deepcopy.go b/api/datadoghq/v2alpha1/zz_generated.deepcopy.go index 509b7c399..c6b27c8e4 100644 --- a/api/datadoghq/v2alpha1/zz_generated.deepcopy.go +++ b/api/datadoghq/v2alpha1/zz_generated.deepcopy.go @@ -1965,6 +1965,11 @@ func (in *OTLPGRPCConfig) DeepCopyInto(out *OTLPGRPCConfig) { *out = new(bool) **out = **in } + if in.HostPortConfig != nil { + in, out := &in.HostPortConfig, &out.HostPortConfig + *out = new(HostPortConfig) + (*in).DeepCopyInto(*out) + } if in.Endpoint != nil { in, out := &in.Endpoint, &out.Endpoint *out = new(string) @@ -1990,6 +1995,11 @@ func (in *OTLPHTTPConfig) DeepCopyInto(out *OTLPHTTPConfig) { *out = new(bool) **out = **in } + if in.HostPortConfig != nil { + in, out := &in.HostPortConfig, &out.HostPortConfig + *out = new(HostPortConfig) + (*in).DeepCopyInto(*out) + } if in.Endpoint != nil { in, out := &in.Endpoint, &out.Endpoint *out = new(string) diff --git a/api/datadoghq/v2alpha1/zz_generated.openapi.go b/api/datadoghq/v2alpha1/zz_generated.openapi.go index f48719612..d3bf1a3d2 100644 --- a/api/datadoghq/v2alpha1/zz_generated.openapi.go +++ b/api/datadoghq/v2alpha1/zz_generated.openapi.go @@ -1153,11 +1153,17 @@ func schema__api_datadoghq_v2alpha1_OTLPGRPCConfig(ref common.ReferenceCallback) Properties: map[string]spec.Schema{ "enabled": { SchemaProps: spec.SchemaProps{ - Description: "Enable the OTLP/gRPC endpoint.", + Description: "Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled.", Type: []string{"boolean"}, Format: "", }, }, + "hostPortConfig": { + SchemaProps: spec.SchemaProps{ + Description: "Enable hostPort for OTLP/gRPC Default: true", + Ref: ref("./api/datadoghq/v2alpha1.HostPortConfig"), + }, + }, "endpoint": { SchemaProps: spec.SchemaProps{ Description: "Endpoint for OTLP/gRPC. gRPC supports several naming schemes: https://github.com/grpc/grpc/blob/master/doc/naming.md The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`). Default: `0.0.0.0:4317`.", @@ -1168,6 +1174,8 @@ func schema__api_datadoghq_v2alpha1_OTLPGRPCConfig(ref common.ReferenceCallback) }, }, }, + Dependencies: []string{ + "./api/datadoghq/v2alpha1.HostPortConfig"}, } } @@ -1180,11 +1188,17 @@ func schema__api_datadoghq_v2alpha1_OTLPHTTPConfig(ref common.ReferenceCallback) Properties: map[string]spec.Schema{ "enabled": { SchemaProps: spec.SchemaProps{ - Description: "Enable the OTLP/HTTP endpoint.", + Description: "Enable the OTLP/HTTP endpoint. Host port is enabled by default and can be disabled.", Type: []string{"boolean"}, Format: "", }, }, + "hostPortConfig": { + SchemaProps: spec.SchemaProps{ + Description: "Enable hostPorts for OTLP/HTTP Default: true", + Ref: ref("./api/datadoghq/v2alpha1.HostPortConfig"), + }, + }, "endpoint": { SchemaProps: spec.SchemaProps{ Description: "Endpoint for OTLP/HTTP. Default: '0.0.0.0:4318'.", @@ -1195,6 +1209,8 @@ func schema__api_datadoghq_v2alpha1_OTLPHTTPConfig(ref common.ReferenceCallback) }, }, }, + Dependencies: []string{ + "./api/datadoghq/v2alpha1.HostPortConfig"}, } } diff --git a/config/crd/bases/v1/datadoghq.com_datadogagents.yaml b/config/crd/bases/v1/datadoghq.com_datadogagents.yaml index 51771dfb5..a9af8f660 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogagents.yaml +++ b/config/crd/bases/v1/datadoghq.com_datadogagents.yaml @@ -454,9 +454,7 @@ spec: Port Default: 8126 properties: enabled: - description: |- - Enabled enables host port configuration - Default: false + description: Enabled enables host port configuration type: boolean hostPort: description: |- @@ -760,9 +758,7 @@ spec: Port Default: 8125 properties: enabled: - description: |- - Enabled enables host port configuration - Default: false + description: Enabled enables host port configuration type: boolean hostPort: description: |- @@ -1270,7 +1266,7 @@ spec: description: GRPC contains configuration for the OTLP ingest OTLP/gRPC receiver. properties: enabled: - description: Enable the OTLP/gRPC endpoint. + description: Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled. type: boolean endpoint: description: |- @@ -1279,18 +1275,48 @@ spec: The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`). Default: `0.0.0.0:4317`. type: string + hostPortConfig: + description: |- + Enable hostPort for OTLP/gRPC + Default: true + properties: + enabled: + description: Enabled enables host port configuration + type: boolean + hostPort: + description: |- + Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) + If HostNetwork is enabled, this value must match the ContainerPort. + format: int32 + type: integer + type: object type: object http: description: HTTP contains configuration for the OTLP ingest OTLP/HTTP receiver. properties: enabled: - description: Enable the OTLP/HTTP endpoint. + description: Enable the OTLP/HTTP endpoint. Host port is enabled by default and can be disabled. type: boolean endpoint: description: |- Endpoint for OTLP/HTTP. Default: '0.0.0.0:4318'. type: string + hostPortConfig: + description: |- + Enable hostPorts for OTLP/HTTP + Default: true + properties: + enabled: + description: Enabled enables host port configuration + type: boolean + hostPort: + description: |- + Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) + If HostNetwork is enabled, this value must match the ContainerPort. + format: int32 + type: integer + type: object type: object type: object type: object @@ -6503,9 +6529,7 @@ spec: Port Default: 8126 properties: enabled: - description: |- - Enabled enables host port configuration - Default: false + description: Enabled enables host port configuration type: boolean hostPort: description: |- @@ -6809,9 +6833,7 @@ spec: Port Default: 8125 properties: enabled: - description: |- - Enabled enables host port configuration - Default: false + description: Enabled enables host port configuration type: boolean hostPort: description: |- @@ -7319,7 +7341,7 @@ spec: description: GRPC contains configuration for the OTLP ingest OTLP/gRPC receiver. properties: enabled: - description: Enable the OTLP/gRPC endpoint. + description: Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled. type: boolean endpoint: description: |- @@ -7328,18 +7350,48 @@ spec: The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`). Default: `0.0.0.0:4317`. type: string + hostPortConfig: + description: |- + Enable hostPort for OTLP/gRPC + Default: true + properties: + enabled: + description: Enabled enables host port configuration + type: boolean + hostPort: + description: |- + Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) + If HostNetwork is enabled, this value must match the ContainerPort. + format: int32 + type: integer + type: object type: object http: description: HTTP contains configuration for the OTLP ingest OTLP/HTTP receiver. properties: enabled: - description: Enable the OTLP/HTTP endpoint. + description: Enable the OTLP/HTTP endpoint. Host port is enabled by default and can be disabled. type: boolean endpoint: description: |- Endpoint for OTLP/HTTP. Default: '0.0.0.0:4318'. type: string + hostPortConfig: + description: |- + Enable hostPorts for OTLP/HTTP + Default: true + properties: + enabled: + description: Enabled enables host port configuration + type: boolean + hostPort: + description: |- + Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) + If HostNetwork is enabled, this value must match the ContainerPort. + format: int32 + type: integer + type: object type: object type: object type: object diff --git a/docs/configuration.v2alpha1.md b/docs/configuration.v2alpha1.md index 1ff16ed0a..9e73bc151 100644 --- a/docs/configuration.v2alpha1.md +++ b/docs/configuration.v2alpha1.md @@ -54,7 +54,7 @@ spec: | features.admissionController.serviceName | ServiceName corresponds to the webhook service name. | | features.admissionController.webhookName | WebhookName is a custom name for the MutatingWebhookConfiguration. Default: "datadog-webhook" | | features.apm.enabled | Enabled enables Application Performance Monitoring. Default: true | -| features.apm.hostPortConfig.enabled | Enabled enables host port configuration Default: false | +| features.apm.hostPortConfig.enabled | Enabled enables host port configuration | | features.apm.hostPortConfig.hostPort | Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) If HostNetwork is enabled, this value must match the ContainerPort. | | features.apm.instrumentation.disabledNamespaces | DisabledNamespaces disables injecting the Datadog APM libraries into pods in specific namespaces. | | features.apm.instrumentation.enabled | Enabled enables injecting the Datadog APM libraries into all pods in the cluster. Default: false | @@ -83,7 +83,7 @@ spec: | features.cws.remoteConfiguration.enabled | Enabled enables Remote Configuration for Cloud Workload Security. Default: true | | features.cws.securityProfiles.enabled | Enabled enables Security Profiles collection for Cloud Workload Security. Default: true | | features.cws.syscallMonitorEnabled | SyscallMonitorEnabled enables Syscall Monitoring (recommended for troubleshooting only). Default: false | -| features.dogstatsd.hostPortConfig.enabled | Enabled enables host port configuration Default: false | +| features.dogstatsd.hostPortConfig.enabled | Enabled enables host port configuration | | features.dogstatsd.hostPortConfig.hostPort | Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) If HostNetwork is enabled, this value must match the ContainerPort. | | features.dogstatsd.mapperProfiles.configData | ConfigData corresponds to the configuration file content. | | features.dogstatsd.mapperProfiles.configMap.items | Items maps a ConfigMap data `key` to a file `path` mount. | @@ -139,10 +139,14 @@ spec: | features.orchestratorExplorer.enabled | Enabled enables the Orchestrator Explorer. Default: true | | features.orchestratorExplorer.extraTags | Additional tags to associate with the collected data in the form of `a b c`. This is a Cluster Agent option distinct from DD_TAGS that is used in the Orchestrator Explorer. | | features.orchestratorExplorer.scrubContainers | ScrubContainers enables scrubbing of sensitive container data (passwords, tokens, etc. ). Default: true | -| features.otlp.receiver.protocols.grpc.enabled | Enable the OTLP/gRPC endpoint. | +| features.otlp.receiver.protocols.grpc.enabled | Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled. | | features.otlp.receiver.protocols.grpc.endpoint | Endpoint for OTLP/gRPC. gRPC supports several naming schemes: https://github.com/grpc/grpc/blob/master/doc/naming.md The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`). Default: `0.0.0.0:4317`. | -| features.otlp.receiver.protocols.http.enabled | Enable the OTLP/HTTP endpoint. | +| features.otlp.receiver.protocols.grpc.hostPortConfig.enabled | Enabled enables host port configuration | +| features.otlp.receiver.protocols.grpc.hostPortConfig.hostPort | Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) If HostNetwork is enabled, this value must match the ContainerPort. | +| features.otlp.receiver.protocols.http.enabled | Enable the OTLP/HTTP endpoint. Host port is enabled by default and can be disabled. | | features.otlp.receiver.protocols.http.endpoint | Endpoint for OTLP/HTTP. Default: '0.0.0.0:4318'. | +| features.otlp.receiver.protocols.http.hostPortConfig.enabled | Enabled enables host port configuration | +| features.otlp.receiver.protocols.http.hostPortConfig.hostPort | Port takes a port number (0 < x < 65536) to expose on the host. (Most containers do not need this.) If HostNetwork is enabled, this value must match the ContainerPort. | | features.processDiscovery.enabled | Enabled enables the Process Discovery check in the Agent. Default: true | | features.prometheusScrape.additionalConfigs | AdditionalConfigs allows adding advanced Prometheus check configurations with custom discovery rules. | | features.prometheusScrape.enableServiceEndpoints | EnableServiceEndpoints enables generating dedicated checks for service endpoints. Default: false | diff --git a/internal/controller/datadogagent/feature/otlp/feature.go b/internal/controller/datadogagent/feature/otlp/feature.go index 8c2218176..fde79fc6b 100644 --- a/internal/controller/datadogagent/feature/otlp/feature.go +++ b/internal/controller/datadogagent/feature/otlp/feature.go @@ -44,11 +44,15 @@ func buildOTLPFeature(options *feature.Options) feature.Feature { type otlpFeature struct { logger logr.Logger - grpcEnabled bool - grpcEndpoint string + grpcEnabled bool + grpcHostPortEnabled bool + grpcCustomHostPort int32 + grpcEndpoint string - httpEnabled bool - httpEndpoint string + httpEnabled bool + httpHostPortEnabled bool + httpCustomHostPort int32 + httpEndpoint string usingAPM bool @@ -70,6 +74,12 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req if apiutils.BoolValue(otlp.Receiver.Protocols.GRPC.Enabled) { f.grpcEnabled = true } + if otlp.Receiver.Protocols.GRPC.HostPortConfig != nil { + 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 + } + } if otlp.Receiver.Protocols.GRPC.Endpoint != nil { f.grpcEndpoint = *otlp.Receiver.Protocols.GRPC.Endpoint } @@ -77,6 +87,12 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req if apiutils.BoolValue(otlp.Receiver.Protocols.HTTP.Enabled) { f.httpEnabled = true } + if otlp.Receiver.Protocols.HTTP.HostPortConfig != nil { + 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 + } + } if otlp.Receiver.Protocols.HTTP.Endpoint != nil { f.httpEndpoint = *otlp.Receiver.Protocols.HTTP.Endpoint } @@ -205,7 +221,6 @@ func (f *otlpFeature) ManageSingleContainerNodeAgent(managers feature.PodTemplat f.logger.Error(err, "invalid OTLP/gRPC endpoint") return fmt.Errorf("invalid OTLP/gRPC endpoint: %w", err) } - port, err := extractPortEndpoint(f.grpcEndpoint) if err != nil { f.logger.Error(err, "failed to extract port from OTLP/gRPC endpoint") @@ -214,9 +229,14 @@ func (f *otlpFeature) ManageSingleContainerNodeAgent(managers feature.PodTemplat otlpgrpcPort := &corev1.ContainerPort{ Name: apicommon.OTLPGRPCPortName, ContainerPort: port, - HostPort: port, Protocol: corev1.ProtocolTCP, } + if f.grpcHostPortEnabled { + otlpgrpcPort.HostPort = f.grpcCustomHostPort + if f.grpcCustomHostPort == 0 { + otlpgrpcPort.HostPort = port + } + } envVar := &corev1.EnvVar{ Name: apicommon.DDOTLPgRPCEndpoint, Value: f.grpcEndpoint, @@ -234,9 +254,14 @@ func (f *otlpFeature) ManageSingleContainerNodeAgent(managers feature.PodTemplat otlphttpPort := &corev1.ContainerPort{ Name: apicommon.OTLPHTTPPortName, ContainerPort: port, - HostPort: port, Protocol: corev1.ProtocolTCP, } + if f.httpHostPortEnabled { + otlphttpPort.HostPort = f.httpCustomHostPort + if f.httpCustomHostPort == 0 { + otlphttpPort.HostPort = port + } + } envVar := &corev1.EnvVar{ Name: apicommon.DDOTLPHTTPEndpoint, Value: f.httpEndpoint, @@ -256,7 +281,6 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov f.logger.Error(err, "invalid OTLP/gRPC endpoint") return fmt.Errorf("invalid OTLP/gRPC endpoint: %w", err) } - port, err := extractPortEndpoint(f.grpcEndpoint) if err != nil { f.logger.Error(err, "failed to extract port from OTLP/gRPC endpoint") @@ -265,9 +289,14 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov otlpgrpcPort := &corev1.ContainerPort{ Name: apicommon.OTLPGRPCPortName, ContainerPort: port, - HostPort: port, Protocol: corev1.ProtocolTCP, } + if f.grpcHostPortEnabled { + otlpgrpcPort.HostPort = port + if f.grpcCustomHostPort != 0 { + otlpgrpcPort.HostPort = f.grpcCustomHostPort + } + } envVar := &corev1.EnvVar{ Name: apicommon.DDOTLPgRPCEndpoint, Value: f.grpcEndpoint, @@ -288,9 +317,14 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov otlphttpPort := &corev1.ContainerPort{ Name: apicommon.OTLPHTTPPortName, ContainerPort: port, - HostPort: port, Protocol: corev1.ProtocolTCP, } + if f.httpHostPortEnabled { + otlphttpPort.HostPort = port + if f.httpCustomHostPort != 0 { + otlphttpPort.HostPort = f.httpCustomHostPort + } + } envVar := &corev1.EnvVar{ Name: apicommon.DDOTLPHTTPEndpoint, Value: f.httpEndpoint, diff --git a/internal/controller/datadogagent/feature/otlp/feature_test.go b/internal/controller/datadogagent/feature/otlp/feature_test.go index 3202e8cce..0869bf6d4 100644 --- a/internal/controller/datadogagent/feature/otlp/feature_test.go +++ b/internal/controller/datadogagent/feature/otlp/feature_test.go @@ -26,11 +26,15 @@ func TestOTLPFeature(t *testing.T) { { Name: "gRPC and HTTP enabled, APM", DDA: newAgent(Settings{ - EnabledGRPC: true, - EndpointGRPC: "0.0.0.0:4317", - EnabledHTTP: true, - EndpointHTTP: "0.0.0.0:4318", - APM: true, + EnabledGRPC: true, + EnabledGRPCHostPort: true, + CustomGRPCHostPort: 4317, + EndpointGRPC: "0.0.0.0:4317", + EnabledHTTP: true, + EnabledHTTPHostPort: true, + CustomHTTPHostPort: 4318, + EndpointHTTP: "0.0.0.0:4318", + APM: true, }), WantConfigure: true, Agent: testExpected(Expected{ @@ -64,11 +68,13 @@ func TestOTLPFeature(t *testing.T) { { Name: "[single container] gRPC and HTTP enabled, APM", DDA: newAgentSingleContainer(Settings{ - EnabledGRPC: true, - EndpointGRPC: "0.0.0.0:4317", - EnabledHTTP: true, - EndpointHTTP: "0.0.0.0:4318", - APM: true, + EnabledGRPC: true, + EnabledGRPCHostPort: true, + EndpointGRPC: "0.0.0.0:4317", + EnabledHTTP: true, + EnabledHTTPHostPort: true, + EndpointHTTP: "0.0.0.0:4318", + APM: true, }), WantConfigure: true, Agent: testExpectedSingleContainer(Expected{ @@ -99,11 +105,173 @@ func TestOTLPFeature(t *testing.T) { }, }), }, + { + Name: "gRPC and HTTP enabled, hostPorts disabled", + DDA: newAgent(Settings{ + EnabledGRPC: true, + EnabledGRPCHostPort: false, + EndpointGRPC: "0.0.0.0:4317", + EnabledHTTP: true, + EnabledHTTPHostPort: false, + EndpointHTTP: "0.0.0.0:4318", + APM: true, + }), + WantConfigure: true, + Agent: testExpected(Expected{ + EnvVars: []*corev1.EnvVar{ + { + Name: apicommon.DDOTLPgRPCEndpoint, + Value: "0.0.0.0:4317", + }, + { + Name: apicommon.DDOTLPHTTPEndpoint, + Value: "0.0.0.0:4318", + }, + }, + CheckTraceAgent: true, + Ports: []*corev1.ContainerPort{ + { + Name: apicommon.OTLPGRPCPortName, + ContainerPort: 4317, + Protocol: corev1.ProtocolTCP, + }, + { + Name: apicommon.OTLPHTTPPortName, + ContainerPort: 4318, + Protocol: corev1.ProtocolTCP, + }, + }, + }), + }, + { + Name: "[single container] gRPC and HTTP enabled, hostPorts disabled", + DDA: newAgentSingleContainer(Settings{ + EnabledGRPC: true, + EnabledGRPCHostPort: false, + EndpointGRPC: "0.0.0.0:4317", + EnabledHTTP: true, + EnabledHTTPHostPort: false, + EndpointHTTP: "0.0.0.0:4318", + APM: true, + }), + WantConfigure: true, + Agent: testExpectedSingleContainer(Expected{ + EnvVars: []*corev1.EnvVar{ + { + Name: apicommon.DDOTLPgRPCEndpoint, + Value: "0.0.0.0:4317", + }, + { + Name: apicommon.DDOTLPHTTPEndpoint, + Value: "0.0.0.0:4318", + }, + }, + CheckTraceAgent: true, + Ports: []*corev1.ContainerPort{ + { + Name: apicommon.OTLPGRPCPortName, + ContainerPort: 4317, + Protocol: corev1.ProtocolTCP, + }, + { + Name: apicommon.OTLPHTTPPortName, + ContainerPort: 4318, + Protocol: corev1.ProtocolTCP, + }, + }, + }), + }, + { + Name: "gRPC and HTTP enabled, custom hostports", + DDA: newAgent(Settings{ + EnabledGRPC: true, + EnabledGRPCHostPort: true, + CustomGRPCHostPort: 4315, + EndpointGRPC: "0.0.0.0:4317", + EnabledHTTP: true, + EnabledHTTPHostPort: true, + CustomHTTPHostPort: 4316, + EndpointHTTP: "0.0.0.0:4318", + APM: true, + }), + WantConfigure: true, + Agent: testExpected(Expected{ + EnvVars: []*corev1.EnvVar{ + { + Name: apicommon.DDOTLPgRPCEndpoint, + Value: "0.0.0.0:4317", + }, + { + Name: apicommon.DDOTLPHTTPEndpoint, + Value: "0.0.0.0:4318", + }, + }, + CheckTraceAgent: true, + Ports: []*corev1.ContainerPort{ + { + Name: apicommon.OTLPGRPCPortName, + ContainerPort: 4317, + HostPort: 4315, + Protocol: corev1.ProtocolTCP, + }, + { + Name: apicommon.OTLPHTTPPortName, + ContainerPort: 4318, + HostPort: 4316, + Protocol: corev1.ProtocolTCP, + }, + }, + }), + }, + { + Name: "[single container] gRPC and HTTP enabled, custom hostports", + DDA: newAgentSingleContainer(Settings{ + EnabledGRPC: true, + EnabledGRPCHostPort: true, + CustomGRPCHostPort: 4315, + EndpointGRPC: "0.0.0.0:4317", + EnabledHTTP: true, + EnabledHTTPHostPort: true, + CustomHTTPHostPort: 4316, + EndpointHTTP: "0.0.0.0:4318", + APM: true, + }), + WantConfigure: true, + Agent: testExpectedSingleContainer(Expected{ + EnvVars: []*corev1.EnvVar{ + { + Name: apicommon.DDOTLPgRPCEndpoint, + Value: "0.0.0.0:4317", + }, + { + Name: apicommon.DDOTLPHTTPEndpoint, + Value: "0.0.0.0:4318", + }, + }, + CheckTraceAgent: true, + Ports: []*corev1.ContainerPort{ + { + Name: apicommon.OTLPGRPCPortName, + ContainerPort: 4317, + HostPort: 4315, + Protocol: corev1.ProtocolTCP, + }, + { + Name: apicommon.OTLPHTTPPortName, + ContainerPort: 4318, + HostPort: 4316, + Protocol: corev1.ProtocolTCP, + }, + }, + }), + }, { Name: "gRPC enabled, no APM", DDA: newAgent(Settings{ - EnabledGRPC: true, - EndpointGRPC: "0.0.0.0:4317", + EnabledGRPC: true, + EnabledGRPCHostPort: true, + CustomGRPCHostPort: 0, + EndpointGRPC: "0.0.0.0:4317", }), WantConfigure: true, Agent: testExpected(Expected{ @@ -126,8 +294,10 @@ func TestOTLPFeature(t *testing.T) { { Name: "[single container] gRPC enabled, no APM", DDA: newAgentSingleContainer(Settings{ - EnabledGRPC: true, - EndpointGRPC: "0.0.0.0:4317", + EnabledGRPC: true, + EnabledGRPCHostPort: true, + CustomGRPCHostPort: 0, + EndpointGRPC: "0.0.0.0:4317", }), WantConfigure: true, Agent: testExpectedSingleContainer(Expected{ @@ -150,9 +320,11 @@ func TestOTLPFeature(t *testing.T) { { Name: "HTTP enabled, APM", DDA: newAgent(Settings{ - EnabledHTTP: true, - EndpointHTTP: "somehostname:4318", - APM: true, + EnabledHTTP: true, + EnabledHTTPHostPort: true, + CustomHTTPHostPort: 0, + EndpointHTTP: "somehostname:4318", + APM: true, }), WantConfigure: true, Agent: testExpected(Expected{ @@ -176,9 +348,11 @@ func TestOTLPFeature(t *testing.T) { { Name: "[single container] HTTP enabled, APM", DDA: newAgentSingleContainer(Settings{ - EnabledHTTP: true, - EndpointHTTP: "somehostname:4318", - APM: true, + EnabledHTTP: true, + EnabledHTTPHostPort: true, + CustomHTTPHostPort: 0, + EndpointHTTP: "somehostname:4318", + APM: true, }), WantConfigure: true, Agent: testExpectedSingleContainer(Expected{ @@ -205,26 +379,30 @@ func TestOTLPFeature(t *testing.T) { } type Settings struct { - EnabledGRPC bool - EndpointGRPC string - EnabledHTTP bool - EndpointHTTP string + EnabledGRPC bool + CustomGRPCHostPort int32 + EnabledGRPCHostPort bool + EndpointGRPC string + EnabledHTTP bool + CustomHTTPHostPort int32 + EnabledHTTPHostPort bool + EndpointHTTP string APM bool } func newAgent(set Settings) *v2alpha1.DatadogAgent { return v2alpha1test.NewDatadogAgentBuilder(). - WithOTLPGRPCSettings(set.EnabledGRPC, set.EndpointGRPC). - WithOTLPHTTPSettings(set.EnabledHTTP, set.EndpointHTTP). + WithOTLPGRPCSettings(set.EnabledGRPC, set.EnabledGRPCHostPort, set.CustomGRPCHostPort, set.EndpointGRPC). + WithOTLPHTTPSettings(set.EnabledHTTP, set.EnabledHTTPHostPort, set.CustomHTTPHostPort, set.EndpointHTTP). WithAPMEnabled(set.APM). Build() } func newAgentSingleContainer(set Settings) *v2alpha1.DatadogAgent { return v2alpha1test.NewDatadogAgentBuilder(). - WithOTLPGRPCSettings(set.EnabledGRPC, set.EndpointGRPC). - WithOTLPHTTPSettings(set.EnabledHTTP, set.EndpointHTTP). + WithOTLPGRPCSettings(set.EnabledGRPC, set.EnabledGRPCHostPort, set.CustomGRPCHostPort, set.EndpointGRPC). + WithOTLPHTTPSettings(set.EnabledHTTP, set.EnabledHTTPHostPort, set.CustomHTTPHostPort, set.EndpointHTTP). WithAPMEnabled(set.APM). WithSingleContainerStrategy(true). Build()