Skip to content

Commit

Permalink
Refactor egress watcher related logs
Browse files Browse the repository at this point in the history
Signed-off-by: terasihma <[email protected]>
  • Loading branch information
terassyi committed Feb 2, 2024
1 parent e53d459 commit 2c8c327
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 2 additions & 5 deletions v2/controllers/egress_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions v2/pkg/founat/fou.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion v2/pkg/nodenet/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,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)
}
Expand Down

0 comments on commit 2c8c327

Please sign in to comment.