diff --git a/cmd/loxilb-agent/agent.go b/cmd/loxilb-agent/agent.go index 682ab98..b791a90 100644 --- a/cmd/loxilb-agent/agent.go +++ b/cmd/loxilb-agent/agent.go @@ -42,6 +42,7 @@ import ( // https://github.com/kubernetes/kubernetes/blob/release-1.17/pkg/controller/apis/config/v1alpha1/defaults.go#L120 const informerDefaultResync = 12 * time.Hour +var closeSig os.Signal var ( capturedSignals = []os.Signal{syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT} notifyCh = make(chan os.Signal, 2) @@ -195,7 +196,10 @@ func run(o *Options) error { <-stopCh - lbManager.DeleteAllLoadBalancer() + if closeSig == syscall.SIGTERM { + klog.Info("flushing LoxiLB rules") + lbManager.DeleteAllLoadBalancer() + } klog.Info("Stopping loxilb Agent") return nil @@ -205,7 +209,7 @@ func RegisterSignalHandlers() <-chan struct{} { stopCh := make(chan struct{}) go func() { - <-notifyCh + closeSig = <-notifyCh close(stopCh) <-notifyCh klog.Warning("Received second signal, will force exit")