Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherrypick #341 #343

Merged
merged 2 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions cmd/crictl/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ package main
import (
"fmt"
"net/url"
"os"
"strings"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"golang.org/x/net/context"
restclient "k8s.io/client-go/rest"
remoteclient "k8s.io/client-go/tools/remotecommand"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
)

Expand Down Expand Up @@ -101,19 +98,5 @@ func Attach(client pb.RuntimeServiceClient, opts attachOptions) error {
return err
}
logrus.Debugf("Attach URL: %v", URL)
attach, err := remoteclient.NewSPDYExecutor(&restclient.Config{TLSClientConfig: restclient.TLSClientConfig{Insecure: true}}, "POST", URL)
if err != nil {
return err
}

streamOptions := remoteclient.StreamOptions{
Stdout: os.Stdout,
Stderr: os.Stderr,
Tty: opts.tty,
}
if opts.stdin {
streamOptions.Stdin = os.Stdin
}
logrus.Debugf("StreamOptions: %v", streamOptions)
return attach.Stream(streamOptions)
return stream(opts.stdin, opts.tty, URL)
}
38 changes: 30 additions & 8 deletions cmd/crictl/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package main
import (
"fmt"
"net/url"
"os"
"strings"

dockerterm "github.com/docker/docker/pkg/term"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"golang.org/x/net/context"
restclient "k8s.io/client-go/rest"
remoteclient "k8s.io/client-go/tools/remotecommand"
"k8s.io/kubernetes/pkg/kubectl/util/term"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
)

Expand Down Expand Up @@ -125,6 +126,7 @@ func Exec(client pb.RuntimeServiceClient, opts execOptions) error {
Stdout: true,
Stderr: !opts.tty,
}

logrus.Debugf("ExecRequest: %v", request)
r, err := client.Exec(context.Background(), request)
logrus.Debugf("ExecResponse: %v", r)
Expand All @@ -143,19 +145,39 @@ func Exec(client pb.RuntimeServiceClient, opts execOptions) error {
}

logrus.Debugf("Exec URL: %v", URL)
exec, err := remoteclient.NewSPDYExecutor(&restclient.Config{TLSClientConfig: restclient.TLSClientConfig{Insecure: true}}, "POST", URL)
return stream(opts.stdin, opts.tty, URL)
}

func stream(in, tty bool, url *url.URL) error {
executor, err := remoteclient.NewSPDYExecutor(&restclient.Config{TLSClientConfig: restclient.TLSClientConfig{Insecure: true}}, "POST", url)
if err != nil {
return err
}

stdin, stdout, stderr := dockerterm.StdStreams()
streamOptions := remoteclient.StreamOptions{
Stdout: os.Stdout,
Stderr: os.Stderr,
Tty: opts.tty,
Stdout: stdout,
Stderr: stderr,
Tty: tty,
}
if opts.stdin {
streamOptions.Stdin = os.Stdin
if in {
streamOptions.Stdin = stdin
}
logrus.Debugf("StreamOptions: %v", streamOptions)
return exec.Stream(streamOptions)
if !tty {
return executor.Stream(streamOptions)
}
if !in {
return fmt.Errorf("tty=true must be specified with interactive=true")
}
t := term.TTY{
In: stdin,
Out: stdout,
Raw: true,
}
if !t.IsTerminalIn() {
return fmt.Errorf("input is not a terminal")
}
streamOptions.TerminalSizeQueue = t.MonitorSize(t.GetSize())
return t.Safe(func() error { return executor.Stream(streamOptions) })
}
1 change: 1 addition & 0 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed
github.com/golang/protobuf b4deda0973fb4c70b50d226b1af49f3da59f5265
github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c
github.com/json-iterator/go f2b4162afba35581b6d4a50d3b8f34e33c144682
github.com/mitchellh/go-wordwrap ad45545899c7b13c020ea92b2072220eefad42b8
github.com/modern-go/concurrent bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94
github.com/modern-go/reflect2 05fbef0ca5da472bbf96c9322b84a53edc03c9fd
github.com/onsi/ginkgo 67b9df7f55fe1165fd9ad49aca7754cce01a42b8
Expand Down
66 changes: 66 additions & 0 deletions vendor/github.com/docker/docker/pkg/term/ascii.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions vendor/github.com/docker/docker/pkg/term/proxy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/docker/docker/pkg/term/tc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions vendor/github.com/docker/docker/pkg/term/tc_solaris_cgo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading