refactor: divide log to session and backend (#487)

* refactor: divide log to session and backend
This commit is contained in:
naison
2025-03-23 13:59:10 +08:00
committed by GitHub
parent a5622b9439
commit b46f7a9877
107 changed files with 873 additions and 871 deletions

View File

@@ -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()
}