Bump k8s.io/uitls to 8e7ff06

The reason for the bump is the new functionality of the
k8s.io/utils/exec package which allows
- to get a hold of the process' std{out,err} as `io.Reader`s
- to `Start` a process and `Wait` for it

This should help on addressing #70890 by allowing to wrap std{out,err}
of the process to be wrapped with a `io.limitedReader`.

It also updates
- k8s.io/kubernetes/pkg/probe/exec.FakeCmd
- k8s.io/kubernetes/pkg/kubelet/prober.execInContainer
- k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet.fakeCmd
to implement the changed interface.

The dependency on 'k8s.io/utils/pointer' to the new version has also
been bumped in some staging repos:
- apiserver
- kube-controller-manager
- kube-scheduler
pull/564/head
Hannes Hörl 2018-11-14 23:10:07 +00:00
parent 0df79e4daa
commit 0d4b5c98f8
12 changed files with 176 additions and 19 deletions

8
Godeps/Godeps.json generated
View File

@ -4003,19 +4003,19 @@
},
{
"ImportPath": "k8s.io/utils/clock",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
},
{
"ImportPath": "k8s.io/utils/exec",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
},
{
"ImportPath": "k8s.io/utils/exec/testing",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
},
{
"ImportPath": "k8s.io/utils/pointer",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
},
{
"ImportPath": "sigs.k8s.io/yaml",

View File

@ -34,14 +34,19 @@ type fakeCmd struct {
err error
}
func (f fakeCmd) Run() error { return f.err }
func (f fakeCmd) CombinedOutput() ([]byte, error) { return f.b, f.err }
func (f fakeCmd) Output() ([]byte, error) { return f.b, f.err }
func (f fakeCmd) SetDir(dir string) {}
func (f fakeCmd) SetStdin(in io.Reader) {}
func (f fakeCmd) SetStdout(out io.Writer) {}
func (f fakeCmd) SetStderr(out io.Writer) {}
func (f fakeCmd) Stop() {}
func (f fakeCmd) Run() error { return f.err }
func (f fakeCmd) CombinedOutput() ([]byte, error) { return f.b, f.err }
func (f fakeCmd) Output() ([]byte, error) { return f.b, f.err }
func (f fakeCmd) SetDir(dir string) {}
func (f fakeCmd) SetStdin(in io.Reader) {}
func (f fakeCmd) SetStdout(out io.Writer) {}
func (f fakeCmd) SetStderr(out io.Writer) {}
func (f fakeCmd) SetEnv([]string) {}
func (f fakeCmd) Stop() {}
func (f fakeCmd) Start() error { return nil }
func (f fakeCmd) Wait() error { return nil }
func (f fakeCmd) StdoutPipe() (io.ReadCloser, error) { return nil, nil }
func (f fakeCmd) StderrPipe() (io.ReadCloser, error) { return nil, nil }
type fakeExecer struct {
ioMap map[string]fakeCmd

View File

@ -274,6 +274,26 @@ func (eic execInContainer) SetStderr(out io.Writer) {
//unimplemented
}
func (eic execInContainer) SetEnv(env []string) {
//unimplemented
}
func (eic execInContainer) Stop() {
//unimplemented
}
func (eic execInContainer) Start() error {
return fmt.Errorf("unimplemented")
}
func (eic execInContainer) Wait() error {
return fmt.Errorf("unimplemented")
}
func (eic execInContainer) StdoutPipe() (io.ReadCloser, error) {
return nil, fmt.Errorf("unimplemented")
}
func (eic execInContainer) StderrPipe() (io.ReadCloser, error) {
return nil, fmt.Errorf("unimplemented")
}

View File

@ -50,8 +50,22 @@ func (f *FakeCmd) SetStdout(out io.Writer) {}
func (f *FakeCmd) SetStderr(out io.Writer) {}
func (f *FakeCmd) SetEnv(env []string) {}
func (f *FakeCmd) Stop() {}
func (f *FakeCmd) Start() error { return nil }
func (f *FakeCmd) Wait() error { return nil }
func (f *FakeCmd) StdoutPipe() (io.ReadCloser, error) {
return nil, nil
}
func (f *FakeCmd) StderrPipe() (io.ReadCloser, error) {
return nil, nil
}
type fakeExitError struct {
exited bool
statusCode int

View File

@ -2024,7 +2024,7 @@
},
{
"ImportPath": "k8s.io/utils/pointer",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
},
{
"ImportPath": "sigs.k8s.io/yaml",

View File

@ -160,7 +160,7 @@
},
{
"ImportPath": "k8s.io/utils/pointer",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
}
]
}

View File

@ -160,7 +160,7 @@
},
{
"ImportPath": "k8s.io/utils/pointer",
"Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed"
"Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc"
}
]
}

5
vendor/k8s.io/utils/clock/clock.go generated vendored
View File

@ -44,21 +44,24 @@ func (RealClock) Since(ts time.Time) time.Duration {
return time.Since(ts)
}
// Same as time.After(d).
// After is the same as time.After(d).
func (RealClock) After(d time.Duration) <-chan time.Time {
return time.After(d)
}
// NewTimer is the same as time.NewTimer(d)
func (RealClock) NewTimer(d time.Duration) Timer {
return &realTimer{
timer: time.NewTimer(d),
}
}
// Tick is the same as time.Tick(d)
func (RealClock) Tick(d time.Duration) <-chan time.Time {
return time.Tick(d)
}
// Sleep is the same as time.Sleep(d)
func (RealClock) Sleep(d time.Duration) {
time.Sleep(d)
}

37
vendor/k8s.io/utils/exec/exec.go generated vendored
View File

@ -60,6 +60,17 @@ type Cmd interface {
SetStdin(in io.Reader)
SetStdout(out io.Writer)
SetStderr(out io.Writer)
SetEnv(env []string)
// StdoutPipe and StderrPipe for getting the process' Stdout and Stderr as
// Readers
StdoutPipe() (io.ReadCloser, error)
StderrPipe() (io.ReadCloser, error)
// Start and Wait are for running a process non-blocking
Start() error
Wait() error
// Stops the command by sending SIGTERM. It is not guaranteed the
// process will stop before this function returns. If the process is not
// responding, an internal timer function will send a SIGKILL to force
@ -121,6 +132,30 @@ func (cmd *cmdWrapper) SetStderr(out io.Writer) {
cmd.Stderr = out
}
func (cmd *cmdWrapper) SetEnv(env []string) {
cmd.Env = env
}
func (cmd *cmdWrapper) StdoutPipe() (io.ReadCloser, error) {
r, err := (*osexec.Cmd)(cmd).StdoutPipe()
return r, handleError(err)
}
func (cmd *cmdWrapper) StderrPipe() (io.ReadCloser, error) {
r, err := (*osexec.Cmd)(cmd).StderrPipe()
return r, handleError(err)
}
func (cmd *cmdWrapper) Start() error {
err := (*osexec.Cmd)(cmd).Start()
return handleError(err)
}
func (cmd *cmdWrapper) Wait() error {
err := (*osexec.Cmd)(cmd).Wait()
return handleError(err)
}
// Run is part of the Cmd interface.
func (cmd *cmdWrapper) Run() error {
err := (*osexec.Cmd)(cmd).Run()
@ -206,10 +241,12 @@ func (e CodeExitError) String() string {
return e.Err.Error()
}
// Exited is to check if the process has finished
func (e CodeExitError) Exited() bool {
return true
}
// ExitStatus is for checking the error code
func (e CodeExitError) ExitStatus() int {
return e.Code
}

View File

@ -24,7 +24,7 @@ import (
"k8s.io/utils/exec"
)
// A simple scripted Interface type.
// FakeExec is a simple scripted Interface type.
type FakeExec struct {
CommandScript []FakeCommandAction
CommandCalls int
@ -33,8 +33,10 @@ type FakeExec struct {
var _ exec.Interface = &FakeExec{}
// FakeCommandAction is the function to be executed
type FakeCommandAction func(cmd string, args ...string) exec.Cmd
// Command is to track the commands that are executed
func (fake *FakeExec) Command(cmd string, args ...string) exec.Cmd {
if fake.CommandCalls > len(fake.CommandScript)-1 {
panic(fmt.Sprintf("ran out of Command() actions. Could not handle command [%d]: %s args: %v", fake.CommandCalls, cmd, args))
@ -44,15 +46,17 @@ func (fake *FakeExec) Command(cmd string, args ...string) exec.Cmd {
return fake.CommandScript[i](cmd, args...)
}
// CommandContext wraps arguments into exec.Cmd
func (fake *FakeExec) CommandContext(ctx context.Context, cmd string, args ...string) exec.Cmd {
return fake.Command(cmd, args...)
}
// LookPath is for finding the path of a file
func (fake *FakeExec) LookPath(file string) (string, error) {
return fake.LookPathFunc(file)
}
// A simple scripted Cmd type.
// FakeCmd is a simple scripted Cmd type.
type FakeCmd struct {
Argv []string
CombinedOutputScript []FakeCombinedOutputAction
@ -65,34 +69,84 @@ type FakeCmd struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Env []string
StdoutPipeResponse FakeStdIOPipeResponse
StderrPipeResponse FakeStdIOPipeResponse
WaitResponse error
StartResponse error
}
var _ exec.Cmd = &FakeCmd{}
// InitFakeCmd is for creating a fake exec.Cmd
func InitFakeCmd(fake *FakeCmd, cmd string, args ...string) exec.Cmd {
fake.Argv = append([]string{cmd}, args...)
return fake
}
// FakeStdIOPipeResponse holds responses to use as fakes for the StdoutPipe and
// StderrPipe method calls
type FakeStdIOPipeResponse struct {
ReadCloser io.ReadCloser
Error error
}
// FakeCombinedOutputAction is a function type
type FakeCombinedOutputAction func() ([]byte, error)
// FakeRunAction is a function type
type FakeRunAction func() ([]byte, []byte, error)
// SetDir sets the directory
func (fake *FakeCmd) SetDir(dir string) {
fake.Dirs = append(fake.Dirs, dir)
}
// SetStdin sets the stdin
func (fake *FakeCmd) SetStdin(in io.Reader) {
fake.Stdin = in
}
// SetStdout sets the stdout
func (fake *FakeCmd) SetStdout(out io.Writer) {
fake.Stdout = out
}
// SetStderr sets the stderr
func (fake *FakeCmd) SetStderr(out io.Writer) {
fake.Stderr = out
}
// SetEnv sets the environment variables
func (fake *FakeCmd) SetEnv(env []string) {
fake.Env = env
}
// StdoutPipe returns an injected ReadCloser & error (via StdoutPipeResponse)
// to be able to inject an output stream on Stdout
func (fake *FakeCmd) StdoutPipe() (io.ReadCloser, error) {
return fake.StdoutPipeResponse.ReadCloser, fake.StdoutPipeResponse.Error
}
// StderrPipe returns an injected ReadCloser & error (via StderrPipeResponse)
// to be able to inject an output stream on Stderr
func (fake *FakeCmd) StderrPipe() (io.ReadCloser, error) {
return fake.StderrPipeResponse.ReadCloser, fake.StderrPipeResponse.Error
}
// Start mimicks starting the process (in the background) and returns the
// injected StartResponse
func (fake *FakeCmd) Start() error {
return fake.StartResponse
}
// Wait mimicks waiting for the process to exit returns the
// injected WaitResponse
func (fake *FakeCmd) Wait() error {
return fake.WaitResponse
}
// Run sets runs the command
func (fake *FakeCmd) Run() error {
if fake.RunCalls > len(fake.RunScript)-1 {
panic("ran out of Run() actions")
@ -113,6 +167,7 @@ func (fake *FakeCmd) Run() error {
return err
}
// CombinedOutput returns the output from the command
func (fake *FakeCmd) CombinedOutput() ([]byte, error) {
if fake.CombinedOutputCalls > len(fake.CombinedOutputScript)-1 {
panic("ran out of CombinedOutput() actions")
@ -126,15 +181,17 @@ func (fake *FakeCmd) CombinedOutput() ([]byte, error) {
return fake.CombinedOutputScript[i]()
}
// Output is the response from the command
func (fake *FakeCmd) Output() ([]byte, error) {
return nil, fmt.Errorf("unimplemented")
}
// Stop is to stop the process
func (fake *FakeCmd) Stop() {
// no-op
}
// A simple fake ExitError type.
// FakeExitError is a simple fake ExitError type.
type FakeExitError struct {
Status int
}
@ -149,10 +206,12 @@ func (fake FakeExitError) Error() string {
return fake.String()
}
// Exited always returns true
func (fake FakeExitError) Exited() bool {
return true
}
// ExitStatus returns the fake status
func (fake FakeExitError) ExitStatus() int {
return fake.Status
}

9
vendor/k8s.io/utils/pointer/OWNERS generated vendored Normal file
View File

@ -0,0 +1,9 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- apelisse
- stewart-yu
- thockin
reviewers:
- apelisse
- stewart-yu
- thockin

View File

@ -74,3 +74,13 @@ func BoolPtr(b bool) *bool {
func StringPtr(s string) *string {
return &s
}
// Float32Ptr returns a pointer to the passed float32.
func Float32Ptr(i float32) *float32 {
return &i
}
// Float64Ptr returns a pointer to the passed float64.
func Float64Ptr(i float64) *float64 {
return &i
}