Skip to content

Commit

Permalink
pinger: add timeout for dns resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Dec 26, 2019
1 parent 5343a4a commit 920053c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/pinger/ping.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pinger

import (
"context"
goping "github.com/sparrc/go-ping"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -145,7 +146,10 @@ func pingExternal(config *Configuration) {
func nslookup(config *Configuration) {
klog.Infof("start to check dns connectivity")
t1 := time.Now()
addrs, err := net.LookupHost(config.DNS)
ctx, cancel := context.WithTimeout(context.TODO(), 10 * time.Second)
defer cancel()
var r net.Resolver
addrs, err := r.LookupHost(ctx, config.DNS)
elpased := time.Since(t1)
if err != nil {
klog.Errorf("failed to resolve dns %s, %v", config.DNS, err)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/ip/static_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("[IP Allocation]", func() {
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
{
Name: name,
Image: "nginx:alpine",
},
Expand Down

0 comments on commit 920053c

Please sign in to comment.