diff --git a/main.go b/main.go index 31007554b..15f6b376b 100644 --- a/main.go +++ b/main.go @@ -263,10 +263,17 @@ func run(opts *options) error { } if opts.remoteConfigEnabled { - err = remoteconfig.NewRemoteConfigUpdater(mgr.GetClient(), ctrl.Log.WithName("remote_config")).Setup(creds) - if err != nil { - setupErrorf(setupLog, err, "Unable to set up Remote Config service") - } + go func() { + // Block until this controller manager is elected leader. We presume the + // entire process will terminate if we lose leadership, so we don't need + // to handle that. + <-mgr.Elected() + + err = remoteconfig.NewRemoteConfigUpdater(mgr.GetClient(), ctrl.Log.WithName("remote_config")).Setup(creds) + if err != nil { + setupErrorf(setupLog, err, "Unable to set up Remote Config service") + } + }() } options := controllers.SetupOptions{ diff --git a/pkg/remoteconfig/updater.go b/pkg/remoteconfig/updater.go index 8786d5a78..7fb2de94e 100644 --- a/pkg/remoteconfig/updater.go +++ b/pkg/remoteconfig/updater.go @@ -402,6 +402,8 @@ func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, cf newddaStatus.RemoteConfigConfiguration.Features.CWS.Enabled = new(bool) } newddaStatus.RemoteConfigConfiguration.Features.CWS.Enabled = cfg.SystemProbe.CWS.Enabled + } else { + newddaStatus.RemoteConfigConfiguration.Features.CWS = nil } // CSPM @@ -413,6 +415,8 @@ func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, cf newddaStatus.RemoteConfigConfiguration.Features.CSPM.Enabled = new(bool) } newddaStatus.RemoteConfigConfiguration.Features.CSPM.Enabled = cfg.SecurityAgent.CSPM.Enabled + } else { + newddaStatus.RemoteConfigConfiguration.Features.CSPM = nil } // SBOM @@ -434,6 +438,8 @@ func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, cf newddaStatus.RemoteConfigConfiguration.Features.SBOM.Host.Enabled = new(bool) } newddaStatus.RemoteConfigConfiguration.Features.SBOM.Host.Enabled = cfg.CoreAgent.SBOM.Host.Enabled + } else { + newddaStatus.RemoteConfigConfiguration.Features.SBOM.Host = nil } // SBOM CONTAINER IMAGE @@ -445,8 +451,12 @@ func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, cf newddaStatus.RemoteConfigConfiguration.Features.SBOM.ContainerImage.Enabled = new(bool) } newddaStatus.RemoteConfigConfiguration.Features.SBOM.ContainerImage.Enabled = cfg.CoreAgent.SBOM.ContainerImage.Enabled + } else { + newddaStatus.RemoteConfigConfiguration.Features.SBOM.ContainerImage = nil } + } else { + newddaStatus.RemoteConfigConfiguration.Features.SBOM = nil } // USM @@ -458,6 +468,8 @@ func (r *RemoteConfigUpdater) updateInstanceStatus(dda v2alpha1.DatadogAgent, cf newddaStatus.RemoteConfigConfiguration.Features.USM.Enabled = new(bool) } newddaStatus.RemoteConfigConfiguration.Features.USM.Enabled = cfg.SystemProbe.USM.Enabled + } else { + newddaStatus.RemoteConfigConfiguration.Features.USM = nil } if !apiequality.Semantic.DeepEqual(&dda.Status, newddaStatus) {