Skip to content

Commit

Permalink
Merge pull request #392 from tanyifeng/fix_ipv6_dial
Browse files Browse the repository at this point in the history
fix error way of parsing URL for cmd exec and attach
  • Loading branch information
k8s-ci-robot authored Oct 15, 2018
2 parents 03e7c88 + f428b77 commit f559d44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 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 = kubeletURLHost
}
if URL.Scheme == "" {
URL.Scheme = kubeletURLSchema
}

logrus.Debugf("Attach URL: %v", URL)
return stream(opts.stdin, opts.tty, URL)
}
16 changes: 10 additions & 6 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,7 +32,8 @@ import (

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

var runtimeExecCommand = cli.Command{
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 = kubeletURLHost
}

if URL.Scheme == "" {
URL.Scheme = kubeletURLSchema
}

logrus.Debugf("Exec URL: %v", URL)
return stream(opts.stdin, opts.tty, URL)
}
Expand Down
13 changes: 9 additions & 4 deletions cmd/crictl/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/url"
"os"
"os/signal"
"strings"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -78,14 +77,20 @@ func PortForward(client pb.RuntimeServiceClient, opts portforwardOptions) error
return err
}
portforwardURL := r.Url
if !strings.HasPrefix(portforwardURL, "http") {
portforwardURL = kubeletURLPrefix + portforwardURL
}

URL, err := url.Parse(portforwardURL)
if err != nil {
return err
}

if URL.Host == "" {
URL.Host = kubeletURLHost
}

if URL.Scheme == "" {
URL.Scheme = kubeletURLSchema
}

logrus.Debugf("PortForward URL: %v", URL)
transport, upgrader, err := spdy.RoundTripperFor(&restclient.Config{})
if err != nil {
Expand Down

0 comments on commit f559d44

Please sign in to comment.