Skip to content

Commit

Permalink
Merge pull request #267 from cybozu-go/refactor-egress-watcher-log
Browse files Browse the repository at this point in the history
Refactor egress watcher related logs
  • Loading branch information
terassyi authored Feb 2, 2024
2 parents d7db96b + 5bf7591 commit 92ed8d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 2 additions & 6 deletions v2/controllers/egress_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type EgressWatcher struct {
func (r *EgressWatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)

logger.Info("start reconciling egress")
eg := &coilv2.Egress{}
if err := r.Get(ctx, req.NamespacedName, eg); err != nil {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -90,10 +89,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 +182,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 FoU device: %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 FoU device: %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 92ed8d9

Please sign in to comment.