mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-29 18:02:00 +08:00
refactor: divide log to session and backend (#487)
* refactor: divide log to session and backend
This commit is contained in:
@@ -8,11 +8,11 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/utils/pointer"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/config"
|
||||
plog "github.com/wencaiwulue/kubevpn/v2/pkg/log"
|
||||
)
|
||||
|
||||
func (c *ConnectOptions) setupSignalHandler() {
|
||||
@@ -20,12 +20,12 @@ func (c *ConnectOptions) setupSignalHandler() {
|
||||
signal.Notify(stopChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL)
|
||||
select {
|
||||
case <-stopChan:
|
||||
c.Cleanup()
|
||||
c.Cleanup(context.Background())
|
||||
case <-c.ctx.Done():
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ConnectOptions) Cleanup() {
|
||||
func (c *ConnectOptions) Cleanup(ctx context.Context) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
@@ -37,9 +37,9 @@ func (c *ConnectOptions) Cleanup() {
|
||||
|
||||
c.once.Do(func() {
|
||||
if inUserDaemon {
|
||||
log.Info("Performing cleanup operations")
|
||||
plog.G(ctx).Info("Performing cleanup operations")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
ctx2, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer cancel()
|
||||
var ips []net.IP
|
||||
if c.localTunIPv4 != nil && c.localTunIPv4.IP != nil {
|
||||
@@ -49,24 +49,24 @@ func (c *ConnectOptions) Cleanup() {
|
||||
ips = append(ips, c.localTunIPv6.IP)
|
||||
}
|
||||
if c.dhcp != nil {
|
||||
err := c.dhcp.ReleaseIP(ctx, ips...)
|
||||
err := c.dhcp.ReleaseIP(ctx2, ips...)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to release IP to dhcp, err: %v", err)
|
||||
plog.G(ctx).Errorf("Failed to release IP to DHCP server: %v", err)
|
||||
}
|
||||
}
|
||||
if c.clientset != nil {
|
||||
_ = c.clientset.CoreV1().Pods(c.Namespace).Delete(ctx, config.CniNetName, v1.DeleteOptions{GracePeriodSeconds: pointer.Int64(0)})
|
||||
_ = c.clientset.CoreV1().Pods(c.Namespace).Delete(ctx2, config.CniNetName, v1.DeleteOptions{GracePeriodSeconds: pointer.Int64(0)})
|
||||
}
|
||||
// leave proxy resources
|
||||
err := c.LeaveAllProxyResources(ctx)
|
||||
err := c.LeaveAllProxyResources(ctx2)
|
||||
if err != nil {
|
||||
log.Errorf("Leave proxy resources error: %v", err)
|
||||
plog.G(ctx).Errorf("Leave proxy resources error: %v", err)
|
||||
}
|
||||
|
||||
for _, function := range c.getRolloutFunc() {
|
||||
if function != nil {
|
||||
if err = function(); err != nil {
|
||||
log.Warnf("Rollout function error: %v", err)
|
||||
plog.G(ctx).Warnf("Rollout function error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (c *ConnectOptions) Cleanup() {
|
||||
}
|
||||
if c.dnsConfig != nil {
|
||||
if inUserDaemon {
|
||||
log.Infof("Clearing DNS settings")
|
||||
plog.G(ctx2).Infof("Clearing DNS settings")
|
||||
}
|
||||
c.dnsConfig.CancelDNS()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user