Merge pull request #531 from joscha-alisch/dont-allow-same-port-twice

Try to open port before allowing it
mine
Fernand Galiana 2020-02-20 13:49:48 -07:00 committed by GitHub
commit 07e67c7e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package view
import (
"errors"
"fmt"
"net"
"strings"
"github.com/derailed/k9s/internal/client"
@ -140,3 +141,11 @@ func (c *Container) isForwardable(path string) ([]string, bool) {
return pp, true
}
func tryListenPort(port string) error {
server, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
if err != nil {
return err
}
return server.Close()
}