Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TCP instead of ICMP to check outbound connectivity #77794

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 11 additions & 18 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ var (
// BusyBoxImage is the image URI of BusyBox.
BusyBoxImage = imageutils.GetE2EImage(imageutils.BusyBox)

// AgnHostImage is the image URI of AgnHost
AgnHostImage = imageutils.GetE2EImage(imageutils.Agnhost)
saiyan86 marked this conversation as resolved.
Show resolved Hide resolved

// For parsing Kubectl version for version-skewed testing.
gitVersionRegexp = regexp.MustCompile("GitVersion:\"(v.+?)\"")

Expand Down Expand Up @@ -474,8 +477,8 @@ func ProxyMode(f *Framework) (string, error) {
Containers: []v1.Container{
{
Name: "detector",
Image: imageutils.GetE2EImage(imageutils.Agnhost),
Command: []string{"/bin/sleep", "3600"},
Image: AgnHostImage,
Command: []string{"pause"},
saiyan86 marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
Expand Down Expand Up @@ -2876,29 +2879,19 @@ func UnblockNetwork(from string, to string) {
}
}

// PingCommand is the type to hold ping command.
type PingCommand string

const (
// IPv4PingCommand is a ping command for IPv4.
IPv4PingCommand PingCommand = "ping"
// IPv6PingCommand is a ping command for IPv6.
IPv6PingCommand PingCommand = "ping6"
)

// CheckConnectivityToHost launches a pod to test connectivity to the specified
// host. An error will be returned if the host is not reachable from the pod.
//
// An empty nodeName will use the schedule to choose where the pod is executed.
func CheckConnectivityToHost(f *Framework, nodeName, podName, host string, pingCmd PingCommand, timeout int) error {
func CheckConnectivityToHost(f *Framework, nodeName, podName, host string, port, timeout int) error {
contName := fmt.Sprintf("%s-container", podName)

command := []string{
string(pingCmd),
"-c", "3", // send 3 pings
"-W", "2", // wait at most 2 seconds for a reply
"nc",
"-vz",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-u option is not specified, so TCP is always used instead of ICMP and UDP, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. By default is TCP.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the PR title should be Use TCP instead of ICMP to check outbound connectivity without UDP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I have changed the PR title. Will submit another PR is UDP is needed later.

"-w", strconv.Itoa(timeout),
host,
strconv.Itoa(port),
}

pod := &v1.Pod{
Expand All @@ -2909,7 +2902,7 @@ func CheckConnectivityToHost(f *Framework, nodeName, podName, host string, pingC
Containers: []v1.Container{
{
Name: contName,
Image: BusyBoxImage,
Image: AgnHostImage,
Command: command,
},
},
Expand Down Expand Up @@ -3257,7 +3250,7 @@ func (f *Framework) NewAgnhostPod(name string, args ...string) *v1.Pod {
Containers: []v1.Container{
{
Name: "agnhost",
Image: imageutils.GetE2EImage(imageutils.Agnhost),
Image: AgnHostImage,
Args: args,
},
},
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/network/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ var _ = SIGDescribe("Networking", func() {
})

ginkgo.It("should provide Internet connection for containers [Feature:Networking-IPv4]", func() {
ginkgo.By("Running container which tries to ping 8.8.8.8")
ginkgo.By("Running container which tries to connect to 8.8.8.8")
framework.ExpectNoError(
framework.CheckConnectivityToHost(f, "", "ping-test", "8.8.8.8", framework.IPv4PingCommand, 30))
framework.CheckConnectivityToHost(f, "", "connectivity-test", "8.8.8.8", 53, 30))
})

ginkgo.It("should provide Internet connection for containers [Feature:Networking-IPv6][Experimental]", func() {
ginkgo.By("Running container which tries to ping 2001:4860:4860::8888")
ginkgo.By("Running container which tries to connect to 2001:4860:4860::8888")
framework.ExpectNoError(
framework.CheckConnectivityToHost(f, "", "ping-test", "2001:4860:4860::8888", framework.IPv6PingCommand, 30))
framework.CheckConnectivityToHost(f, "", "connectivity-test", "2001:4860:4860::8888", 53, 30))
})

// First test because it has no dependencies on variables created later on.
Expand Down