From 04849f25ed683a18a3499a0b41026e3acf30fbc8 Mon Sep 17 00:00:00 2001 From: terasihma Date: Tue, 19 Dec 2023 05:40:59 +0000 Subject: [PATCH] Refactor egress watcher related logs Signed-off-by: terasihma --- v2/controllers/egress_watcher.go | 7 ++----- v2/pkg/founat/fou.go | 9 ++++++--- v2/pkg/nodenet/pod.go | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/v2/controllers/egress_watcher.go b/v2/controllers/egress_watcher.go index 082a6161..1e178cdb 100644 --- a/v2/controllers/egress_watcher.go +++ b/v2/controllers/egress_watcher.go @@ -90,10 +90,8 @@ func (r *EgressWatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R return ctrl.Result{}, nil } -func (r *EgressWatcher) reconcileEgressClient(ctx context.Context, eg *coilv2.Egress, pod *corev1.Pod, l *logr.Logger) error { - logger := l.WithValues("pod_name", pod.Name, "pod_namespace", pod.Namespace) - logger.Info("reconcile egress client") - hook, err := r.getHook(ctx, eg, &logger) +func (r *EgressWatcher) reconcileEgressClient(ctx context.Context, eg *coilv2.Egress, pod *corev1.Pod, logger *logr.Logger) error { + hook, err := r.getHook(ctx, eg, logger) if err != nil { return fmt.Errorf("failed to setup NAT hook: %w", err) } @@ -185,7 +183,6 @@ func (r *EgressWatcher) hook(gwn gwNets, log *logr.Logger) func(ipv4, ipv6 net.I return fmt.Errorf("natClient hasn't been initialized: %w", err) } - log.Info("add a fou device by EgressWatcher", "gateway", gwn.gateway.String()) link, err := ft.AddPeer(gwn.gateway, gwn.sportAuto) if errors.Is(err, founat.ErrIPFamilyMismatch) { // ignore unsupported IP family link diff --git a/v2/pkg/founat/fou.go b/v2/pkg/founat/fou.go index d78ded73..015da928 100644 --- a/v2/pkg/founat/fou.go +++ b/v2/pkg/founat/fou.go @@ -100,9 +100,6 @@ func (t *fouTunnel) Init() error { if err := modProbe("fou"); err != nil { return fmt.Errorf("failed to load fou module: %w", err) } - if t.logFunc != nil { - t.logFunc("add FoU devide for IPv4") - } err := netlink.FouAdd(netlink.Fou{ Family: netlink.FAMILY_V4, Protocol: 4, // IPv4 over IPv4 (so-called IPIP) @@ -259,6 +256,9 @@ func (t *fouTunnel) addOrRecreatePeer4(addr net.IP, sportAuto bool) (string, err Local: t.local4, } + if t.logFunc != nil { + t.logFunc(fmt.Sprintf("add a new link: %s", linkName)) + } if err := netlink.LinkAdd(link); err != nil { return "", fmt.Errorf("netlink: failed to add fou link: %w", err) } @@ -325,6 +325,9 @@ func (t *fouTunnel) addOrRecreatePeer6(addr net.IP, sportAuto bool) (string, err Remote: addr, Local: t.local6, } + if t.logFunc != nil { + t.logFunc(fmt.Sprintf("add a new link: %s", linkName)) + } if err := netlink.LinkAdd(link); err != nil { return "", fmt.Errorf("netlink: failed to add fou6 link: %w", err) } diff --git a/v2/pkg/nodenet/pod.go b/v2/pkg/nodenet/pod.go index 5cfb5629..0dfd50d8 100644 --- a/v2/pkg/nodenet/pod.go +++ b/v2/pkg/nodenet/pod.go @@ -441,7 +441,6 @@ func (pn *podNetwork) Update(podIPv4, podIPv6 net.IP, hook SetupHook) error { defer containerNS.Close() err = containerNS.Do(func(ns.NetNS) error { - pn.log.Info("do the hook function", "netns", netNsPath, "pod_address", podIPv4) if hook != nil { return hook(podIPv4, podIPv6) }