Created
April 20, 2017 11:31
-
-
Save sameo/3f6b14c47e2b88d052aadce790643b12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/cmd/ocic/container.go b/cmd/ocic/container.go | |
| index e4fe4cd..57c575f 100644 | |
| --- a/cmd/ocic/container.go | |
| +++ b/cmd/ocic/container.go | |
| @@ -1,14 +1,19 @@ | |
| package main | |
| import ( | |
| + "bufio" | |
| "fmt" | |
| "log" | |
| + "net/http" | |
| "strings" | |
| "time" | |
| "github.com/urfave/cli" | |
| "golang.org/x/net/context" | |
| pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" | |
| + "k8s.io/kubernetes/pkg/util/httpstream/spdy/" | |
| + "k8s.io/kubernetes/pkg/util/httpstream/" | |
| + "k8s.io/kubernetes/pkg/kubelet/server/remotecommand/" | |
| ) | |
| var containerCommand = cli.Command{ | |
| @@ -497,15 +502,40 @@ func Exec(client pb.RuntimeServiceClient, ID string, tty bool, stdin bool, urlOn | |
| return err | |
| } | |
| - url := r.Url | |
| - | |
| if urlOnly { | |
| fmt.Println("URL:") | |
| - fmt.Println(url) | |
| + fmt.Println(r.url) | |
| return nil | |
| } | |
| + req, err := http.NewRequest("GET", r.url, nil) | |
| + if err != nil { | |
| + return err | |
| + } | |
| + | |
| + // Upgrade Headers | |
| + req.Header.Add(httpstream.HeaderUpgrade, spdy.HeaderSpdy31) | |
| + req.Header.Add(httpstream.HeaderConnection, httpstream.HeaderUpgrade) | |
| + | |
| + // Protocol headers | |
| + for _, pv := range remotecommand.SupportedStreamingProtocols { | |
| + req.Header.Add(httpstream.HeaderProtocolVersion, pv) | |
| + } | |
| + | |
| // Do exec here | |
| + client := http.Client{} | |
| + resp, err := client.Do(req) | |
| + fmt.Println("Resp: %v", resp) | |
| + | |
| + reader := bufio.NewReader(resp.Body) | |
| + for { | |
| + line, err := reader.ReadBytes('\n') | |
| + if err != nil { | |
| + break | |
| + } | |
| + fmt.Println(string(line)) | |
| + } | |
| + | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment