Skip to content

Commit

Permalink
[remote config] Respect leader election and update Status.RemoteConfi…
Browse files Browse the repository at this point in the history
…gConfiguration if parameters are empty (#1228)

* respect leader election

* clear status params if corresponding config is empty
  • Loading branch information
celenechang authored Jun 11, 2024
1 parent c46b61d commit 288d981
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
12 changes: 12 additions & 0 deletions pkg/remoteconfig/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 288d981

Please sign in to comment.