Skip to content

Commit

Permalink
fix error way of parsing URL for cmd exec and attach
Browse files Browse the repository at this point in the history
Signed-off-by: t00416110 <[email protected]>
  • Loading branch information
t00416110 committed Oct 11, 2018
1 parent e4dff19 commit fb80177
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions cmd/crictl/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"
"net/url"
"strings"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -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)
}
14 changes: 9 additions & 5 deletions cmd/crictl/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"
"net/url"
"strings"

dockerterm "github.com/docker/docker/pkg/term"
"github.com/sirupsen/logrus"
Expand All @@ -33,6 +32,7 @@ import (

const (
// TODO: make this configurable in kubelet.
kubeletURLSchema = "http"
kubeletURLPrefix = "http://127.0.0.1:10250"
)

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit fb80177

Please sign in to comment.