Skip to content

Commit

Permalink
Merge pull request #347 from msherif1234/fix_ds_restart
Browse files Browse the repository at this point in the history
OCPBUGS-11888: handle daemonSet pods restart
  • Loading branch information
openshift-merge-robot committed May 18, 2023
2 parents 079a7e6 + 76bd82f commit 9e9f369
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions controllers/ingressnodefirewallnodestate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func (r *IngressNodeFirewallNodeStateReconciler) Reconcile(ctx context.Context,
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
return r.reconcileResource(ctx, req, nodeState, true)
return r.reconcileResource(ctx, nodeState, true)
}
// Error reading the object - requeue the request.
r.Log.Error(err, "Failed to get IngressNodeFirewallNodeState")
return ctrl.Result{}, err
}

r.Log.Info("Reconciling resource and programming bpf", "name", nodeState.Name, "namespace", nodeState.Namespace)
return r.reconcileResource(ctx, req, nodeState, false)
return r.reconcileResource(ctx, nodeState, false)
}

// SetupWithManager sets up the controller with the Manager.
Expand All @@ -90,7 +90,7 @@ var mock ebpfsyncer.EbpfSyncer = nil
// reconcileResource reconciles the resource by getting the EbpfDaemon singleton's SyncInterfaceIngressRules method.
// For mock tests, var mock can be overwritten.
func (r *IngressNodeFirewallNodeStateReconciler) reconcileResource(
ctx context.Context, req ctrl.Request, instance *infv1alpha1.IngressNodeFirewallNodeState, isDelete bool) (ctrl.Result, error) {
ctx context.Context, instance *infv1alpha1.IngressNodeFirewallNodeState, isDelete bool) (ctrl.Result, error) {
if err := ebpfsyncer.GetEbpfSyncer(ctx, r.Log, r.Stats, mock).SyncInterfaceIngressRules(instance.Spec.InterfaceIngressRules, isDelete); err != nil {
return ctrl.Result{}, errors.Wrapf(err, "FailedToSyncIngressNodeFirewallResources")
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/ebpfsyncer/ebpfsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package ebpfsyncer
import (
"context"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"

"github.com/openshift/ingress-node-firewall/api/v1alpha1"
infv1alpha1 "github.com/openshift/ingress-node-firewall/api/v1alpha1"
Expand Down Expand Up @@ -72,6 +75,8 @@ func (e *ebpfSingleton) SyncInterfaceIngressRules(
logger := e.log.WithName("syncIngressNodeFirewallResources")
logger.Info("Running sync operation", "ifaceIngressRules", ifaceIngressRules, "isDelete", isDelete)

sigc := make(chan os.Signal, 1)

// Stop the poller for the time of this operation and start it again afterwards.
if e.stats != nil {
e.stats.StopPoll()
Expand All @@ -82,6 +87,15 @@ func (e *ebpfSingleton) SyncInterfaceIngressRules(
}()
}

signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
go func(c chan os.Signal) {
// Wait for a SIGTERM
<-c
if e.c != nil {
e.resetAll()
}
}(sigc)

// Create a new manager if none exists.
if err := e.createNewManager(); err != nil {
return err
Expand Down

0 comments on commit 9e9f369

Please sign in to comment.