Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (f *otelAgentGatewayFeature) ID() feature.IDType {
return feature.OtelAgentGatewayIDType
}

func (f *otelAgentGatewayFeature) Configure(dda metav1.Object, ddaSpec *v2alpha1.DatadogAgentSpec, _ *v2alpha1.RemoteConfigConfiguration) (reqComp feature.RequiredComponents) {
func (f *otelAgentGatewayFeature) Configure(dda metav1.Object, ddaSpec *v2alpha1.DatadogAgentSpec, ddaRCStatus *v2alpha1.RemoteConfigConfiguration) (reqComp feature.RequiredComponents) {
// Merge configuration from Status.RemoteConfigConfiguration into the Spec
mergeConfigs(ddaSpec, ddaRCStatus)

if ddaSpec.Features.OtelAgentGateway == nil || !apiutils.BoolValue(ddaSpec.Features.OtelAgentGateway.Enabled) {
return reqComp
}
Expand Down Expand Up @@ -100,6 +103,22 @@ func (f *otelAgentGatewayFeature) Configure(dda metav1.Object, ddaSpec *v2alpha1
return reqComp
}

func mergeConfigs(ddaSpec *v2alpha1.DatadogAgentSpec, ddaRCStatus *v2alpha1.RemoteConfigConfiguration) {
if ddaRCStatus == nil || ddaRCStatus.Features == nil || ddaRCStatus.Features.OtelAgentGateway == nil || ddaRCStatus.Features.OtelAgentGateway.Enabled == nil {
return
}

if ddaSpec.Features == nil {
ddaSpec.Features = &v2alpha1.DatadogFeatures{}
}

if ddaSpec.Features.OtelAgentGateway == nil {
ddaSpec.Features.OtelAgentGateway = &v2alpha1.OtelAgentGatewayFeatureConfig{}
}

ddaSpec.Features.OtelAgentGateway.Enabled = ddaRCStatus.Features.OtelAgentGateway.Enabled
}

func (f *otelAgentGatewayFeature) buildOTelAgentCoreConfigMap() (*corev1.ConfigMap, error) {
if f.customConfig != nil && f.customConfig.ConfigData != nil {
cm, err := configmap.BuildConfigMapConfigData(f.owner.GetNamespace(), f.customConfig.ConfigData, f.configMapName, otelConfigFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"
"github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1"
apiutils "github.com/DataDog/datadog-operator/api/utils"
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/common"
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature"
Expand Down Expand Up @@ -197,6 +198,25 @@ func Test_otelAgentGatewayFeature_Configure(t *testing.T) {
defaultVolumes(defaultLocalObjectReferenceName),
),
},
{
Name: "otel agent gateway enabled via remote config",
DDA: func() *v2alpha1.DatadogAgent {
dda := testutils.NewDatadogAgentBuilder().
WithOTelAgentGatewayEnabled(false).
Build()
dda.Status.RemoteConfigConfiguration = &v2alpha1.RemoteConfigConfiguration{
Features: &v2alpha1.DatadogFeatures{
OtelAgentGateway: &v2alpha1.OtelAgentGatewayFeatureConfig{
Enabled: ptr.To(true),
},
},
}
return dda
}(),
WantConfigure: true,
WantDependenciesFunc: testExpectedDepsCreatedCM,
OtelAgentGateway: testExpectedOtelAgentGateway(apicommon.OtelAgent, defaultExpectedPorts, defaultAnnotations, defaultVolumeMounts, defaultVolumes(defaultLocalObjectReferenceName)),
},
{
Name: "otel agent gateway enabled with featureGates",
DDA: testutils.NewDatadogAgentBuilder().
Expand Down
34 changes: 29 additions & 5 deletions pkg/remoteconfig/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ type DatadogProductRemoteConfig interface {

// DatadogAgentRemoteConfig contains the struct used to update DatadogAgent object from RemoteConfig
type DatadogAgentRemoteConfig struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CoreAgent *CoreAgentFeaturesConfig `json:"config,omitempty"`
SystemProbe *SystemProbeFeaturesConfig `json:"system_probe,omitempty"`
SecurityAgent *SecurityAgentFeaturesConfig `json:"security_agent,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CoreAgent *CoreAgentFeaturesConfig `json:"config,omitempty"`
SystemProbe *SystemProbeFeaturesConfig `json:"system_probe,omitempty"`
SecurityAgent *SecurityAgentFeaturesConfig `json:"security_agent,omitempty"`
OtelAgentGateway *FeatureEnabledConfig `json:"otel_agent_gateway,omitempty"`
}

// GetID returns the ID of the configuration
Expand Down Expand Up @@ -490,6 +491,16 @@ func mergeConfigs(dst, src *DatadogAgentRemoteConfig) {
}
}

// OtelAgentGateway
if src.OtelAgentGateway != nil {
if dst.OtelAgentGateway == nil {
dst.OtelAgentGateway = &FeatureEnabledConfig{}
}
if src.OtelAgentGateway.Enabled != nil {
dst.OtelAgentGateway.Enabled = src.OtelAgentGateway.Enabled
}
}

}

func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, config DatadogProductRemoteConfig) error {
Expand Down Expand Up @@ -586,6 +597,19 @@ func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, co
newddaStatus.RemoteConfigConfiguration.Features.USM = nil
}

// OtelAgentGateway
if cfg.OtelAgentGateway != nil {
if newddaStatus.RemoteConfigConfiguration.Features.OtelAgentGateway == nil {
newddaStatus.RemoteConfigConfiguration.Features.OtelAgentGateway = &v2alpha1.OtelAgentGatewayFeatureConfig{}
}
if newddaStatus.RemoteConfigConfiguration.Features.OtelAgentGateway.Enabled == nil {
newddaStatus.RemoteConfigConfiguration.Features.OtelAgentGateway.Enabled = new(bool)
}
newddaStatus.RemoteConfigConfiguration.Features.OtelAgentGateway.Enabled = cfg.OtelAgentGateway.Enabled
} else {
newddaStatus.RemoteConfigConfiguration.Features.OtelAgentGateway = nil
}

if !apiequality.Semantic.DeepEqual(&dda.Status, newddaStatus) {
ddaUpdate := dda.DeepCopy()
ddaUpdate.Status = *newddaStatus
Expand Down
Loading