Skip to content

Instantly share code, notes, and snippets.

@sameo
Created April 20, 2017 11:31
Show Gist options
  • Select an option

  • Save sameo/3f6b14c47e2b88d052aadce790643b12 to your computer and use it in GitHub Desktop.

Select an option

Save sameo/3f6b14c47e2b88d052aadce790643b12 to your computer and use it in GitHub Desktop.
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