Skip to content

Commit f559d44

Browse files
authored
Merge pull request #392 from tanyifeng/fix_ipv6_dial
fix error way of parsing URL for cmd exec and attach
2 parents 03e7c88 + f428b77 commit f559d44

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

cmd/crictl/attach.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package main
1919
import (
2020
"fmt"
2121
"net/url"
22-
"strings"
2322

2423
"github.com/sirupsen/logrus"
2524
"github.com/urfave/cli"
@@ -89,14 +88,19 @@ func Attach(client pb.RuntimeServiceClient, opts attachOptions) error {
8988
return err
9089
}
9190
attachURL := r.Url
92-
if !strings.HasPrefix(attachURL, "http") {
93-
attachURL = kubeletURLPrefix + attachURL
94-
}
9591

9692
URL, err := url.Parse(attachURL)
9793
if err != nil {
9894
return err
9995
}
96+
97+
if URL.Host == "" {
98+
URL.Host = kubeletURLHost
99+
}
100+
if URL.Scheme == "" {
101+
URL.Scheme = kubeletURLSchema
102+
}
103+
100104
logrus.Debugf("Attach URL: %v", URL)
101105
return stream(opts.stdin, opts.tty, URL)
102106
}

cmd/crictl/exec.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package main
1919
import (
2020
"fmt"
2121
"net/url"
22-
"strings"
2322

2423
dockerterm "github.com/docker/docker/pkg/term"
2524
"github.com/sirupsen/logrus"
@@ -33,7 +32,8 @@ import (
3332

3433
const (
3534
// TODO: make this configurable in kubelet.
36-
kubeletURLPrefix = "http://127.0.0.1:10250"
35+
kubeletURLSchema = "http"
36+
kubeletURLHost = "http://127.0.0.1:10250"
3737
)
3838

3939
var runtimeExecCommand = cli.Command{
@@ -134,16 +134,20 @@ func Exec(client pb.RuntimeServiceClient, opts execOptions) error {
134134
return err
135135
}
136136
execURL := r.Url
137-
if !strings.HasPrefix(execURL, "http") {
138-
execURL = kubeletURLPrefix + execURL
139-
140-
}
141137

142138
URL, err := url.Parse(execURL)
143139
if err != nil {
144140
return err
145141
}
146142

143+
if URL.Host == "" {
144+
URL.Host = kubeletURLHost
145+
}
146+
147+
if URL.Scheme == "" {
148+
URL.Scheme = kubeletURLSchema
149+
}
150+
147151
logrus.Debugf("Exec URL: %v", URL)
148152
return stream(opts.stdin, opts.tty, URL)
149153
}

cmd/crictl/portforward.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net/url"
2323
"os"
2424
"os/signal"
25-
"strings"
2625

2726
"github.com/sirupsen/logrus"
2827
"github.com/urfave/cli"
@@ -78,14 +77,20 @@ func PortForward(client pb.RuntimeServiceClient, opts portforwardOptions) error
7877
return err
7978
}
8079
portforwardURL := r.Url
81-
if !strings.HasPrefix(portforwardURL, "http") {
82-
portforwardURL = kubeletURLPrefix + portforwardURL
83-
}
8480

8581
URL, err := url.Parse(portforwardURL)
8682
if err != nil {
8783
return err
8884
}
85+
86+
if URL.Host == "" {
87+
URL.Host = kubeletURLHost
88+
}
89+
90+
if URL.Scheme == "" {
91+
URL.Scheme = kubeletURLSchema
92+
}
93+
8994
logrus.Debugf("PortForward URL: %v", URL)
9095
transport, upgrader, err := spdy.RoundTripperFor(&restclient.Config{})
9196
if err != nil {

0 commit comments

Comments
 (0)