From 0d4b5c98f81a3e04b18610f983eb1b68e5fa11bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Wed, 14 Nov 2018 23:10:07 +0000 Subject: [PATCH] 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 --- Godeps/Godeps.json | 8 +-- cmd/kubeadm/app/phases/kubelet/flags_test.go | 21 +++--- pkg/kubelet/prober/prober.go | 20 ++++++ pkg/probe/exec/exec_test.go | 14 ++++ .../src/k8s.io/apiserver/Godeps/Godeps.json | 2 +- .../Godeps/Godeps.json | 2 +- .../k8s.io/kube-scheduler/Godeps/Godeps.json | 2 +- vendor/k8s.io/utils/clock/clock.go | 5 +- vendor/k8s.io/utils/exec/exec.go | 37 +++++++++++ vendor/k8s.io/utils/exec/testing/fake_exec.go | 65 ++++++++++++++++++- vendor/k8s.io/utils/pointer/OWNERS | 9 +++ vendor/k8s.io/utils/pointer/pointer.go | 10 +++ 12 files changed, 176 insertions(+), 19 deletions(-) create mode 100644 vendor/k8s.io/utils/pointer/OWNERS diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 12d8f93dbd..991be1a21d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -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", diff --git a/cmd/kubeadm/app/phases/kubelet/flags_test.go b/cmd/kubeadm/app/phases/kubelet/flags_test.go index 26d4774c39..1b06330504 100644 --- a/cmd/kubeadm/app/phases/kubelet/flags_test.go +++ b/cmd/kubeadm/app/phases/kubelet/flags_test.go @@ -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 diff --git a/pkg/kubelet/prober/prober.go b/pkg/kubelet/prober/prober.go index efec60c98d..cc69ec02f7 100644 --- a/pkg/kubelet/prober/prober.go +++ b/pkg/kubelet/prober/prober.go @@ -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") +} diff --git a/pkg/probe/exec/exec_test.go b/pkg/probe/exec/exec_test.go index 3621983059..1d8eebb063 100644 --- a/pkg/probe/exec/exec_test.go +++ b/pkg/probe/exec/exec_test.go @@ -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 diff --git a/staging/src/k8s.io/apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiserver/Godeps/Godeps.json index 9162cebbf6..675bd50092 100644 --- a/staging/src/k8s.io/apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiserver/Godeps/Godeps.json @@ -2024,7 +2024,7 @@ }, { "ImportPath": "k8s.io/utils/pointer", - "Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed" + "Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc" }, { "ImportPath": "sigs.k8s.io/yaml", diff --git a/staging/src/k8s.io/kube-controller-manager/Godeps/Godeps.json b/staging/src/k8s.io/kube-controller-manager/Godeps/Godeps.json index 8927874f37..3df12ff4c0 100644 --- a/staging/src/k8s.io/kube-controller-manager/Godeps/Godeps.json +++ b/staging/src/k8s.io/kube-controller-manager/Godeps/Godeps.json @@ -160,7 +160,7 @@ }, { "ImportPath": "k8s.io/utils/pointer", - "Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed" + "Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc" } ] } diff --git a/staging/src/k8s.io/kube-scheduler/Godeps/Godeps.json b/staging/src/k8s.io/kube-scheduler/Godeps/Godeps.json index 99bbabbf4a..422e30596b 100644 --- a/staging/src/k8s.io/kube-scheduler/Godeps/Godeps.json +++ b/staging/src/k8s.io/kube-scheduler/Godeps/Godeps.json @@ -160,7 +160,7 @@ }, { "ImportPath": "k8s.io/utils/pointer", - "Rev": "66066c83e385e385ccc3c964b44fd7dcd413d0ed" + "Rev": "8e7ff06bf0e2d3289061230af203e430a15b6dcc" } ] } diff --git a/vendor/k8s.io/utils/clock/clock.go b/vendor/k8s.io/utils/clock/clock.go index 3d53c62b1a..789c0238c8 100644 --- a/vendor/k8s.io/utils/clock/clock.go +++ b/vendor/k8s.io/utils/clock/clock.go @@ -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) } diff --git a/vendor/k8s.io/utils/exec/exec.go b/vendor/k8s.io/utils/exec/exec.go index 07735d8814..96bec01ca8 100644 --- a/vendor/k8s.io/utils/exec/exec.go +++ b/vendor/k8s.io/utils/exec/exec.go @@ -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 } diff --git a/vendor/k8s.io/utils/exec/testing/fake_exec.go b/vendor/k8s.io/utils/exec/testing/fake_exec.go index 32cbae2523..66b5de8b31 100644 --- a/vendor/k8s.io/utils/exec/testing/fake_exec.go +++ b/vendor/k8s.io/utils/exec/testing/fake_exec.go @@ -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 } diff --git a/vendor/k8s.io/utils/pointer/OWNERS b/vendor/k8s.io/utils/pointer/OWNERS new file mode 100644 index 0000000000..2f328f4c90 --- /dev/null +++ b/vendor/k8s.io/utils/pointer/OWNERS @@ -0,0 +1,9 @@ +# See the OWNERS docs at https://go.k8s.io/owners +approvers: +- apelisse +- stewart-yu +- thockin +reviewers: +- apelisse +- stewart-yu +- thockin diff --git a/vendor/k8s.io/utils/pointer/pointer.go b/vendor/k8s.io/utils/pointer/pointer.go index 5fbfc6e00f..a11a540f46 100644 --- a/vendor/k8s.io/utils/pointer/pointer.go +++ b/vendor/k8s.io/utils/pointer/pointer.go @@ -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 +}