diff --git a/cmd/crictl/attach.go b/cmd/crictl/attach.go index eef5fd57e8..35a1b9dd28 100644 --- a/cmd/crictl/attach.go +++ b/cmd/crictl/attach.go @@ -19,7 +19,6 @@ package main import ( "fmt" "net/url" - "strings" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -89,14 +88,19 @@ func Attach(client pb.RuntimeServiceClient, opts attachOptions) error { return err } attachURL := r.Url - if !strings.HasPrefix(attachURL, "http") { - attachURL = kubeletURLPrefix + attachURL - } URL, err := url.Parse(attachURL) if err != nil { return err } + + if URL.Host == "" { + URL.Host = kubeletURLPrefix + } + if URL.Scheme == "" { + URL.Scheme = kubeletURLSchema + } + logrus.Debugf("Attach URL: %v", URL) return stream(opts.stdin, opts.tty, URL) } diff --git a/cmd/crictl/exec.go b/cmd/crictl/exec.go index 008dd58dd2..cc02a16e9f 100644 --- a/cmd/crictl/exec.go +++ b/cmd/crictl/exec.go @@ -19,7 +19,6 @@ package main import ( "fmt" "net/url" - "strings" dockerterm "github.com/docker/docker/pkg/term" "github.com/sirupsen/logrus" @@ -33,6 +32,7 @@ import ( const ( // TODO: make this configurable in kubelet. + kubeletURLSchema = "http" kubeletURLPrefix = "http://127.0.0.1:10250" ) @@ -134,16 +134,20 @@ func Exec(client pb.RuntimeServiceClient, opts execOptions) error { return err } execURL := r.Url - if !strings.HasPrefix(execURL, "http") { - execURL = kubeletURLPrefix + execURL - - } URL, err := url.Parse(execURL) if err != nil { return err } + if URL.Host == "" { + URL.Host = kubeletURLPrefix + } + + if URL.Scheme == "" { + URL.Scheme = kubeletURLSchema + } + logrus.Debugf("Exec URL: %v", URL) return stream(opts.stdin, opts.tty, URL) }