Increase time for port forwarding exponentially in fission CLI (#2468)

This commit is contained in:
Shubham Bansal
2022-07-07 15:36:36 +05:30
committed by GitHub
parent 655456ee03
commit 5838340594
+17 -8
View File
@@ -36,6 +36,8 @@ import (
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
const maxDuration time.Duration = 2000
// Port forward a free local port to a pod on the cluster. The pod is // Port forward a free local port to a pod on the cluster. The pod is
// found in the specified namespace by labelSelector. The pod's port // found in the specified namespace by labelSelector. The pod's port
// is found by looking for a service in the same namespace and using // is found by looking for a service in the same namespace and using
@@ -50,16 +52,21 @@ func SetupPortForward(namespace, labelSelector string, kubeContext string) (stri
return "", errors.Wrap(err, "error finding unused port") return "", errors.Wrap(err, "error finding unused port")
} }
var waitDuration time.Duration = 50
console.Verbose(2, "Waiting for local port %v", localPort) console.Verbose(2, "Waiting for local port %v", localPort)
for { for {
conn, _ := net.DialTimeout("tcp", conn, _ := net.DialTimeout("tcp",
net.JoinHostPort("", localPort), time.Millisecond) net.JoinHostPort("", localPort), time.Millisecond*waitDuration)
if conn != nil { if conn != nil {
conn.Close() conn.Close()
waitDuration *= 2
if waitDuration > maxDuration {
waitDuration = maxDuration
}
} else { } else {
break break
} }
time.Sleep(time.Millisecond * 50)
} }
console.Verbose(2, "Starting port forward from local port %v", localPort) console.Verbose(2, "Starting port forward from local port %v", localPort)
@@ -73,19 +80,21 @@ func SetupPortForward(namespace, labelSelector string, kubeContext string) (stri
<-readyC <-readyC
console.Verbose(2, "Waiting for port forward %v to start...", localPort) console.Verbose(2, "Waiting for port forward %v to start...", localPort)
waitDuration = 50
for { for {
conn, err := net.DialTimeout("tcp", conn, err := net.DialTimeout("tcp",
net.JoinHostPort("", localPort), time.Millisecond) net.JoinHostPort("", localPort), time.Millisecond*waitDuration)
if err != nil { if err != nil {
console.Verbose(2, "Error dialing on local port %v: %s", localPort, err.Error()) console.Verbose(2, "Error dialing on local port %v: %s", localPort, err.Error())
time.Sleep(time.Millisecond * 50) waitDuration *= 2
continue if waitDuration > maxDuration {
} waitDuration = maxDuration
if conn != nil { }
} else {
conn.Close() conn.Close()
break break
} }
time.Sleep(time.Millisecond * 50)
} }
console.Verbose(2, "Port forward from local port %v started", localPort) console.Verbose(2, "Port forward from local port %v started", localPort)