ocic: Initial implementation for ocic ctr exec

We use the k8s remotecommand client API to create a
streaming executor, and then stream the executed process
into stdout/stderr.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2017-04-20 16:15:56 +02:00
parent 0ba2be0dc8
commit c676b7b6c3

View file

@ -3,12 +3,17 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"net/url"
"os"
"strings" "strings"
"time" "time"
"github.com/urfave/cli" "github.com/urfave/cli"
"golang.org/x/net/context" "golang.org/x/net/context"
restclient "k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/client/unversioned/remotecommand"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
remotecommandserver "k8s.io/kubernetes/pkg/kubelet/server/remotecommand"
) )
var containerCommand = cli.Command{ var containerCommand = cli.Command{
@ -497,16 +502,34 @@ func Exec(client pb.RuntimeServiceClient, ID string, tty bool, stdin bool, urlOn
return err return err
} }
url := r.Url
if urlOnly { if urlOnly {
fmt.Println("URL:") fmt.Println("URL:")
fmt.Println(url) fmt.Println(r.Url)
return nil return nil
} }
// Do exec here execURL, err := url.Parse(r.Url)
return nil if err != nil {
return err
}
streamExec, err := remotecommand.NewExecutor(&restclient.Config{}, "GET", execURL)
if err != nil {
return err
}
options := remotecommand.StreamOptions{
SupportedProtocols: remotecommandserver.SupportedStreamingProtocols,
Stdout: os.Stdout,
Stderr: os.Stderr,
Tty: tty,
}
if stdin {
options.Stdin = os.Stdin
}
return streamExec.Stream(options)
} }
// ListContainers sends a ListContainerRequest to the server, and parses // ListContainers sends a ListContainerRequest to the server, and parses