diff --git a/cmd/pinger/pinger.go b/cmd/pinger/pinger.go index bd4e0cdbf58..a3f7d5c6772 100644 --- a/cmd/pinger/pinger.go +++ b/cmd/pinger/pinger.go @@ -41,19 +41,15 @@ func CmdMain() { } if config.EnableVerboseConnCheck { - go func() { - addr := util.JoinHostPort("0.0.0.0", config.TCPConnCheckPort) - if err := util.TCPConnectivityListen(addr); err != nil { - util.LogFatalAndExit(err, "failed to start TCP listen on addr %s ", addr) - } - }() - - go func() { - addr := util.JoinHostPort("0.0.0.0", config.UDPConnCheckPort) - if err := util.UDPConnectivityListen(addr); err != nil { - util.LogFatalAndExit(err, "failed to start UDP listen on addr %s ", addr) - } - }() + addr := util.JoinHostPort("0.0.0.0", config.UDPConnCheckPort) + if err = util.UDPConnectivityListen(addr); err != nil { + util.LogFatalAndExit(err, "failed to start UDP listen on addr %s", addr) + } + + addr = util.JoinHostPort("0.0.0.0", config.TCPConnCheckPort) + if err = util.TCPConnectivityListen(addr); err != nil { + util.LogFatalAndExit(err, "failed to start TCP listen on addr %s", addr) + } } } pinger.StartPinger(config) diff --git a/dist/images/kubectl-ko b/dist/images/kubectl-ko index 96f85aebc16..092aa1b58fe 100755 --- a/dist/images/kubectl-ko +++ b/dist/images/kubectl-ko @@ -17,6 +17,8 @@ CONN_CHECK_SERVER="conn-check-server" PERF_GC_COMMAND=() LAST_PERF_FAILED_LOG="" OVN_TRACE=0 +TCP_CONN_CHECK_PORT=${TCP_CONN_CHECK_PORT:-8100} +UDP_CONN_CHECK_PORT=${UDP_CONN_CHECK_PORT:-8101} showHelp(){ echo "kubectl ko {subcommand} [option...]" @@ -543,27 +545,31 @@ spec: command: - /kube-ovn/kube-ovn-pinger args: + - --ds-namespace=$KUBE_OVN_NS + - --ds-name=$subnetName-$CONN_CHECK_SERVER - --enable-verbose-conn-check=true + - --tcp-conn-check-port=$TCP_CONN_CHECK_PORT + - --udp-conn-check-port=$UDP_CONN_CHECK_PORT env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name + readinessProbe: + failureThreshold: 1 + initialDelaySeconds: 3 + periodSeconds: 5 + successThreshold: 1 + tcpSocket: + port: $TCP_CONN_CHECK_PORT + timeoutSeconds: 1 EOF isfailed=true - for i in {0..59} - do - if kubectl wait pod --for=condition=Ready -l app=$CONN_CHECK_LABEL -n $KUBE_OVN_NS 2> /dev/null; then - isfailed=false - break - fi - sleep 1; \ - done - - if $isfailed; then + if kubectl -n $KUBE_OVN_NS rollout status ds $subnetName-$CONN_CHECK_SERVER --timeout=30s; then + isfailed=false + else echo "Error ds $subnetName-$CONN_CHECK_SERVER pod not ready" - return fi } @@ -721,10 +727,15 @@ diagnose(){ fi pingers=$(kubectl -n $KUBE_OVN_NS get po --no-headers -o custom-columns=NAME:.metadata.name -l app=kube-ovn-pinger) + cmd=( + /kube-ovn/kube-ovn-pinger --mode=job --ds-name=$subnetName-$CONN_CHECK_SERVER --ds-namespace=$KUBE_OVN_NS + --tcp-conn-check-port=$TCP_CONN_CHECK_PORT --udp-conn-check-port=$UDP_CONN_CHECK_PORT + --external-address=1.1.1.1,2606:4700:4700::1111 --target-ip-ports=$targetIPPorts + ) for pinger in $pingers do echo "#### pinger $pinger on namespace $KUBE_OVN_NS diagnose results:" - kubectl exec -n $KUBE_OVN_NS "$pinger" -- /kube-ovn/kube-ovn-pinger --mode=job --ds-name=$subnetName-$CONN_CHECK_SERVER --ds-namespace=$KUBE_OVN_NS --enable-verbose-conn-check=true --external-address=114.114.114.114,2400:3200::1 --target-ip-ports=$targetIPPorts + kubectl exec -n $KUBE_OVN_NS "$pinger" -- ${cmd[*]} echo "" done ;; diff --git a/pkg/util/net.go b/pkg/util/net.go index 800acea7d78..2c570b9447c 100644 --- a/pkg/util/net.go +++ b/pkg/util/net.go @@ -555,13 +555,17 @@ func TCPConnectivityListen(address string) error { return fmt.Errorf("listen failed with err %v", err) } - for { - conn, err := listener.Accept() - if err != nil { - continue + go func() { + for { + conn, err := listener.Accept() + if err != nil { + continue + } + _ = conn.Close() } - _ = conn.Close() - } + }() + + return nil } func UDPConnectivityCheck(address string) error { @@ -609,17 +613,21 @@ func UDPConnectivityListen(address string) error { buffer := make([]byte, 1024) - for { - _, clientAddr, err := conn.ReadFromUDP(buffer) - if err != nil { - continue - } + go func() { + for { + _, clientAddr, err := conn.ReadFromUDP(buffer) + if err != nil { + continue + } - _, err = conn.WriteToUDP([]byte("health check"), clientAddr) - if err != nil { - continue + _, err = conn.WriteToUDP([]byte("health check"), clientAddr) + if err != nil { + continue + } } - } + }() + + return nil } func GetDefaultListenAddr() string { diff --git a/test/e2e/kube-ovn/kubectl-ko/kubectl-ko.go b/test/e2e/kube-ovn/kubectl-ko/kubectl-ko.go index 556d56f8648..50426d72fd7 100644 --- a/test/e2e/kube-ovn/kubectl-ko/kubectl-ko.go +++ b/test/e2e/kube-ovn/kubectl-ko/kubectl-ko.go @@ -130,10 +130,10 @@ var _ = framework.Describe("[group:kubectl-ko]", func() { supportARP := !f.VersionPriorTo(1, 11) supportDstMAC := !f.VersionPriorTo(1, 10) if !supportARP { - framework.Logf("Support for ARP was introduce in v1.11") + framework.Logf("Support for ARP was introduced in v1.11") } if !supportDstMAC { - framework.Logf("Support for destination MAC was introduce in v1.10") + framework.Logf("Support for destination MAC was introduced in v1.10") } for _, ip := range pod.Status.PodIPs { @@ -165,7 +165,7 @@ var _ = framework.Describe("[group:kubectl-ko]", func() { }) framework.ConformanceIt(`should support "kubectl ko trace " for pod with host network`, func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") ginkgo.By("Creating pod " + podName + " with host network") pod := framework.MakePod(namespaceName, podName, nil, nil, "", nil, nil) @@ -198,7 +198,7 @@ var _ = framework.Describe("[group:kubectl-ko]", func() { }) framework.ConformanceIt(`should support "kubectl ko trace "`, func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") ginkgo.By("Getting nodes") nodeList, err := e2enode.GetReadySchedulableNodes(context.Background(), cs) @@ -237,15 +237,15 @@ var _ = framework.Describe("[group:kubectl-ko]", func() { }) framework.ConformanceIt(`should support "kubectl ko log kube-ovn all"`, func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") components := [...]string{"kube-ovn", "ovn", "ovs", "linux", "all"} for _, component := range components { execOrDie(fmt.Sprintf("ko log %s", component)) } }) - framework.ConformanceIt(`should support "kubectl ko diagnose subnet IPPorts "`, func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + framework.ConformanceIt(`should support "kubectl ko diagnose subnet IPPorts "`, func() { + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") execOrDie("ko diagnose subnet ovn-default") execOrDie("ko diagnose IPPorts tcp-114.114.114.114-53,udp-114.114.114.114-53") }) diff --git a/test/e2e/kube-ovn/node/node.go b/test/e2e/kube-ovn/node/node.go index 34dce3b1803..b6fa561736e 100644 --- a/test/e2e/kube-ovn/node/node.go +++ b/test/e2e/kube-ovn/node/node.go @@ -105,7 +105,7 @@ var _ = framework.OrderedDescribe("[group:node]", func() { }) framework.ConformanceIt("should access overlay pods using node ip", func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") ginkgo.By("Creating subnet " + subnetName) subnet = framework.MakeSubnet(subnetName, "", cidr, "", "", "", nil, nil, nil) @@ -145,7 +145,7 @@ var _ = framework.OrderedDescribe("[group:node]", func() { }) framework.ConformanceIt("should access overlay services using node ip", func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") ginkgo.By("Creating subnet " + subnetName) subnet = framework.MakeSubnet(subnetName, "", cidr, "", "", "", nil, nil, nil) diff --git a/test/e2e/kube-ovn/switch_lb_rule/switch_lb_rule.go b/test/e2e/kube-ovn/switch_lb_rule/switch_lb_rule.go index ea8a75721b4..a1ad07766a7 100644 --- a/test/e2e/kube-ovn/switch_lb_rule/switch_lb_rule.go +++ b/test/e2e/kube-ovn/switch_lb_rule/switch_lb_rule.go @@ -122,7 +122,7 @@ var _ = framework.Describe("[group:slr]", func() { }) framework.ConformanceIt("should access sts and slr svc ok", func() { - f.SkipVersionPriorTo(1, 12, "This feature was introduce in v1.12") + f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12") ginkgo.By("1. Creating sts svc with slr") var ( clientPod *corev1.Pod