diff --git a/cmd/kubefwd/services/services.go b/cmd/kubefwd/services/services.go index 3ba9eea0..d0028e07 100644 --- a/cmd/kubefwd/services/services.go +++ b/cmd/kubefwd/services/services.go @@ -59,6 +59,7 @@ var mappings []string var isAllNs bool var fwdConfigurationPath string var fwdReservations []string +var timeout int func init() { // override error output from k8s.io/apimachinery/pkg/util/runtime @@ -78,6 +79,7 @@ func init() { Cmd.Flags().BoolVarP(&isAllNs, "all-namespaces", "A", false, "Enable --all-namespaces option like kubectl.") Cmd.Flags().StringSliceVarP(&fwdReservations, "reserve", "r", []string{}, "Specify an IP reservation. Specify multiple reservations by duplicating this argument.") Cmd.Flags().StringVarP(&fwdConfigurationPath, "fwd-conf", "z", "", "Define an IP reservation configuration") + Cmd.Flags().IntVarP(&timeout, "timeout", "t", 300, "Specify a timeout seconds for the port forwarding.") } @@ -432,6 +434,7 @@ func (opts *NamespaceOpts) AddServiceHandler(obj interface{}) { ClientSet: opts.ClientSet, Context: opts.Context, Namespace: opts.Namespace, + Timeout: timeout, Hostfile: opts.HostFile, ClientConfig: opts.ClientConfig, RESTClient: opts.RESTClient, diff --git a/pkg/fwdport/fwdport.go b/pkg/fwdport/fwdport.go index 70b2e8af..46348028 100644 --- a/pkg/fwdport/fwdport.go +++ b/pkg/fwdport/fwdport.go @@ -62,6 +62,8 @@ type PortForwardOpts struct { PodPort string LocalIp net.IP LocalPort string + // Timeout for the port-forwarding process + Timeout int HostFile *HostFileWithLock // Context is a unique key (string) in kubectl config representing @@ -407,14 +409,13 @@ func (pfo *PortForwardOpts) WaitUntilPodRunning(stopChannel <-chan struct{}) (*v // if the os.signal (we enter the Ctrl+C) // or ManualStop (service delete or some thing wrong) // or RunningChannel channel (the watch for pod runnings is done) - // or timeout after 300s + // or timeout after 300s(default) // we'll stop the watcher - // TODO: change the 300s timeout to custom settings. go func() { defer watcher.Stop() select { case <-stopChannel: - case <-time.After(time.Second * 300): + case <-time.After(time.Duration(pfo.Timeout) * time.Second): } }() diff --git a/pkg/fwdservice/fwdservice.go b/pkg/fwdservice/fwdservice.go index 3b559585..c3742837 100644 --- a/pkg/fwdservice/fwdservice.go +++ b/pkg/fwdservice/fwdservice.go @@ -38,6 +38,9 @@ type ServiceFWD struct { // and the pods that back them for port-forwarding Namespace string + // Timeout is specify a timeout seconds for the port forwarding. + Timeout int + // ClusterN is the ordinal index of the cluster (from configuration) // cluster 0 is considered local while > 0 is remote ClusterN int @@ -76,7 +79,8 @@ type ServiceFWD struct { ForwardIPReservations []string // cli passed IP reservations } -/** +/* +* add port map @url https://github.com/txn2/kubefwd/issues/121 */