Skip to content

Commit

Permalink
fix golang lint
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Jul 10, 2023
1 parent 95c2a80 commit 15b9d0a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
8 changes: 3 additions & 5 deletions pkg/daemon/gateway_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,10 @@ func (c *Controller) reconcileTProxyIPTableRules(protocol string) error {
continue
}

hostIP := pod.Status.HostIP

subnet, err := c.subnetsLister.Get(subnetName)
if err != nil {
err = fmt.Errorf("failed to get subnet '%s', err: %v", subnetName, err)
continue
return err
}

if subnet.Spec.Vpc == c.config.ClusterRouter {
Expand Down Expand Up @@ -868,11 +866,11 @@ func (c *Controller) reconcileTProxyIPTableRules(protocol string) error {
tProxyPreRoutingMarkMask := fmt.Sprintf("%#x/%#x", TProxyPreroutingMark, TProxyPreroutingMask)
if protocol == kubeovnv1.ProtocolIPv4 {
tproxyOutputRules = append(tproxyOutputRules, util.IPTableRule{Table: MANGLE, Chain: OvnOutput, Rule: strings.Fields(fmt.Sprintf(`-d %s/32 -p tcp -m tcp --dport %s -j MARK --set-xmark %s`, podIP, probePort, tProxyPostroutingMarkMask))})
tproxyPreRoutingRules = append(tproxyPreRoutingRules, util.IPTableRule{Table: MANGLE, Chain: OvnPrerouting, Rule: strings.Fields(fmt.Sprintf(`-d %s/32 -p tcp -m tcp --dport %s -j TPROXY --on-port %d --on-ip %s --tproxy-mark %s`, podIP, probePort, util.TProxyListenPort, hostIP, tProxyPreRoutingMarkMask))})
tproxyPreRoutingRules = append(tproxyPreRoutingRules, util.IPTableRule{Table: MANGLE, Chain: OvnPrerouting, Rule: strings.Fields(fmt.Sprintf(`-d %s/32 -p tcp -m tcp --dport %s -j TPROXY --on-port %d --on-ip %s --tproxy-mark %s`, podIP, probePort, util.TProxyListenPort, pod.Status.HostIP, tProxyPreRoutingMarkMask))})
}
if protocol == kubeovnv1.ProtocolIPv6 {
tproxyOutputRules = append(tproxyOutputRules, util.IPTableRule{Table: MANGLE, Chain: OvnOutput, Rule: strings.Fields(fmt.Sprintf(`-d %s/128 -p tcp -m tcp --dport %s -j MARK --set-xmark %s`, podIP, probePort, tProxyPostroutingMarkMask))})
tproxyPreRoutingRules = append(tproxyPreRoutingRules, util.IPTableRule{Table: MANGLE, Chain: OvnPrerouting, Rule: strings.Fields(fmt.Sprintf(`-d %s/128 -p tcp -m tcp --dport %s -j TPROXY --on-port %d --on-ip %s --tproxy-mark %s`, podIP, probePort, util.TProxyListenPort, hostIP, tProxyPreRoutingMarkMask))})
tproxyPreRoutingRules = append(tproxyPreRoutingRules, util.IPTableRule{Table: MANGLE, Chain: OvnPrerouting, Rule: strings.Fields(fmt.Sprintf(`-d %s/128 -p tcp -m tcp --dport %s -j TPROXY --on-port %d --on-ip %s --tproxy-mark %s`, podIP, probePort, util.TProxyListenPort, pod.Status.HostIP, tProxyPreRoutingMarkMask))})
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/daemon/tproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Controller) StartTProxyTCPPortProbe() {

subnet, err := c.subnetsLister.Get(subnetName)
if err != nil {
err = fmt.Errorf("failed to get subnet '%s', err: %v", subnetName, err)
klog.Errorf("failed to get subnet '%s', err: %v", subnetName, err)
continue
}

Expand Down Expand Up @@ -284,7 +284,7 @@ func listenTCP() {
for {
conn, err := tcpListener.Accept()
if err != nil {
if netErr, ok := err.(net.Error); ok && netErr.Temporary() {
if netErr, ok := err.(net.Error); ok {
klog.Errorf("Temporary error while accepting connection: %s", netErr)
}
klog.Fatalf("Unrecoverable error while accepting connection: %s", err)
Expand Down Expand Up @@ -365,7 +365,10 @@ func probePortInNs(podIP, probePort string, transferHTTPMessage bool, conn net.C
streamWait.Add(2)

streamConn := func(dst io.Writer, src io.Reader) {
io.Copy(dst, src)
if _, err := io.Copy(dst, src); err != nil {
klog.Errorf("copy stream from dst %v to src %v failed err: %v ", dst, src, err)
}

streamWait.Done()
}

Expand All @@ -377,7 +380,6 @@ func probePortInNs(podIP, probePort string, transferHTTPMessage bool, conn net.C
}
return nil
})
return
}

func getIPPortString(podIP, port string) string {
Expand Down
3 changes: 3 additions & 0 deletions pkg/tproxy/tproxy_tcp.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

package tproxy

import (
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/kube-ovn/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var _ = framework.Describe("[group:pod]", func() {
InitialDelaySeconds: 10,
}

pod = podClient.Create(pod)
_ = podClient.Create(pod)
time.Sleep(11 * time.Second)

pod = podClient.GetPod(podName)
Expand Down Expand Up @@ -222,7 +222,7 @@ var _ = framework.Describe("[group:pod]", func() {
InitialDelaySeconds: 10,
}

pod = podClient.Create(pod)
_ = podClient.Create(pod)
time.Sleep(11 * time.Second)

pod = podClient.GetPod(podName)
Expand Down

0 comments on commit 15b9d0a

Please sign in to comment.