Skip to content

Commit e686774

Browse files
committed
Review suggestions
1 parent 1542192 commit e686774

4 files changed

Lines changed: 27 additions & 14 deletions

File tree

cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func run(opts *options) error {
341341
}
342342

343343
if opts.remoteUpdatesEnabled {
344-
if rcErr := setupFleetDaemon(setupLog, mgr, rcUpdater.Client()); rcErr != nil {
344+
if rcErr := setupFleetDaemon(setupLog, mgr, rcUpdater.Client(), opts.createControllerRevisions && opts.datadogAgentInternalEnabled); rcErr != nil {
345345
setupErrorf(setupLog, rcErr, "Unable to setup Fleet daemon")
346346
}
347347
}
@@ -665,7 +665,7 @@ func setupAndStartHelmMetadataForwarder(logger logr.Logger, mgr manager.Manager,
665665
return mgr.Add(hmf)
666666
}
667667

668-
func setupFleetDaemon(logger logr.Logger, mgr manager.Manager, rcClient remoteconfig.RCClient) error {
669-
daemon := fleet.NewDaemon(rcClient, mgr.GetClient())
668+
func setupFleetDaemon(logger logr.Logger, mgr manager.Manager, rcClient remoteconfig.RCClient, revisionsEnabled bool) error {
669+
daemon := fleet.NewDaemon(rcClient, mgr.GetClient(), revisionsEnabled)
670670
return mgr.Add(daemon)
671671
}

internal/controller/datadogagent/experiment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ func (r *Reconciler) rollback(
159159
// Merge snapshot annotations (Datadog-only keys) on top of current annotations
160160
// so that non-Datadog annotations (user metadata, tooling labels, etc.) are preserved.
161161
merged := maps.Clone(current.Annotations)
162+
if merged == nil {
163+
merged = make(map[string]string, len(snapshot.Annotations))
164+
}
162165
maps.Copy(merged, snapshot.Annotations)
163166

164167
toUpdate := &v2alpha1.DatadogAgent{

pkg/fleet/daemon.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ var _ manager.LeaderElectionRunnable = &Daemon{}
3232
// Daemon subscribes to fleet-specific RC products (installer configs and tasks)
3333
// and runs after leader election as a controller-runtime Runnable.
3434
type Daemon struct {
35-
rcClient remoteconfig.RCClient
36-
client client.Client
37-
mu sync.RWMutex
38-
configs map[string]installerConfig // keyed by config ID; replaced on each RC update
35+
rcClient remoteconfig.RCClient
36+
client client.Client
37+
revisionsEnabled bool
38+
mu sync.RWMutex
39+
configs map[string]installerConfig // keyed by config ID; replaced on each RC update
3940
}
4041

41-
// NewDaemon creates a new Fleet Daemon.
42-
func NewDaemon(rcClient remoteconfig.RCClient, k8sClient client.Client) *Daemon {
42+
// NewDaemon creates a new Fleet Daemon. When revisionsEnabled is false, experiment
43+
// signals are rejected because the reconciler cannot process them without the
44+
// ControllerRevision machinery.
45+
func NewDaemon(rcClient remoteconfig.RCClient, k8sClient client.Client, revisionsEnabled bool) *Daemon {
4346
return &Daemon{
44-
rcClient: rcClient,
45-
client: k8sClient,
46-
configs: make(map[string]installerConfig),
47+
rcClient: rcClient,
48+
client: k8sClient,
49+
revisionsEnabled: revisionsEnabled,
50+
configs: make(map[string]installerConfig),
4751
}
4852
}
4953

@@ -101,6 +105,11 @@ func (d *Daemon) getConfig(id string) (installerConfig, error) {
101105
// handleRemoteAPIRequest dispatches the incoming task to the appropriate handler.
102106
func (d *Daemon) handleRemoteAPIRequest(ctx context.Context, req remoteAPIRequest) error {
103107
ctrl.LoggerFrom(ctx).Info("Received remote API request", "id", req.ID, "package", req.Package, "method", req.Method)
108+
109+
if !d.revisionsEnabled {
110+
return fmt.Errorf("experiment signals require the CreateControllerRevisions and DatadogAgentInternal feature gates")
111+
}
112+
104113
switch req.Method {
105114
case methodStartDatadogAgentExperiment:
106115
return d.startDatadogAgentExperiment(ctx, req)

pkg/fleet/daemon_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ func testDaemon(dda *v2alpha1.DatadogAgent, configs map[string]installerConfig)
3838
}
3939
c := b.Build()
4040
return &Daemon{
41-
client: c,
42-
configs: configs,
41+
client: c,
42+
revisionsEnabled: true,
43+
configs: configs,
4344
}, c
4445
}
4546

0 commit comments

Comments
 (0)