Skip to content

Commit dc5b94d

Browse files
authored
NETOBSERV-2839: add nil-checks for OnHold mode (netobserv#2862)
agent controller had ineffective nil-checks in DeleteIfOwned (it checks for nil interface, not nil pointer!) Adding nil-pointer checks in agent_controller.go and permissions.go
1 parent 16348f5 commit dc5b94d

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎internal/controller/ebpf/agent_controller.go‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,18 @@ func (c *AgentController) reconcile(ctx context.Context, target *flowslatest.Flo
179179

180180
if target.Spec.OnHold() {
181181
c.Status.SetUnused("FlowCollector is on hold")
182-
rlog.Info("action: delete agent")
183-
err = c.DeleteIfOwned(ctx, current)
184-
if err != nil {
185-
return err
182+
if current != nil {
183+
rlog.Info("action: delete agent")
184+
err = c.DeleteIfOwned(ctx, current)
185+
if err != nil {
186+
return err
187+
}
186188
}
187-
err = c.DeleteIfOwned(ctx, c.promSvc)
188-
if err != nil {
189-
return err
189+
if c.promSvc != nil {
190+
err = c.DeleteIfOwned(ctx, c.promSvc)
191+
if err != nil {
192+
return err
193+
}
190194
}
191195
return nil
192196
}

‎internal/controller/ebpf/internal/permissions/permissions.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ func (c *Reconciler) reconcileServiceAccount(ctx context.Context, desired *flows
118118
}
119119
}
120120

121-
if desired.Spec.OnHold() {
121+
if desired.Spec.OnHold() && actual != nil {
122122
return c.DeleteIfOwned(ctx, actual)
123123
}
124124

125125
if actual == nil {
126126
rlog.Info("creating service account")
127127
return c.CreateOwned(ctx, sAcc)
128128
}
129-
rlog.Info("service account already reconciled. Doing nothing")
129+
rlog.Info("service account already reconciled, doing nothing")
130130
return nil
131131
}
132132

0 commit comments

Comments
 (0)