From 64731baffe26ccd1065892e80a4c68575356c772 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 3 Oct 2022 19:10:48 +0200 Subject: [PATCH 1/2] e2e storage: add logging to proxy This is optional and can be used to capture the result of command execution in the log output. --- test/e2e/storage/drivers/proxy/io.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/e2e/storage/drivers/proxy/io.go b/test/e2e/storage/drivers/proxy/io.go index b44962a32d4..3d67f840455 100644 --- a/test/e2e/storage/drivers/proxy/io.go +++ b/test/e2e/storage/drivers/proxy/io.go @@ -20,6 +20,7 @@ import ( "fmt" "io" + "k8s.io/klog/v2" "k8s.io/kubernetes/test/e2e/framework" e2epod "k8s.io/kubernetes/test/e2e/framework/pod" "k8s.io/kubernetes/test/e2e/storage/drivers/csi-test/mock/service" @@ -30,6 +31,7 @@ type PodDirIO struct { Namespace string PodName string ContainerName string + Logger *klog.Logger } var _ service.DirIO = PodDirIO{} @@ -88,7 +90,7 @@ func (p PodDirIO) RemoveAll(path string) error { } func (p PodDirIO) execute(command []string, stdin io.Reader) (string, string, error) { - return e2epod.ExecWithOptions(p.F, e2epod.ExecOptions{ + stdout, stderr, err := e2epod.ExecWithOptions(framework.ExecOptions{ Command: command, Namespace: p.Namespace, PodName: p.PodName, @@ -98,4 +100,10 @@ func (p PodDirIO) execute(command []string, stdin io.Reader) (string, string, er CaptureStderr: true, Quiet: true, }) + if p.Logger != nil { + p.Logger.Info("Command completed", "command", command, "stdout", stdout, "stderr", stderr, "err", err) + + } + return stdout, stderr, err + } From 1793132198daa33c875d351ebad04745140f51eb Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 3 Oct 2022 21:16:16 +0200 Subject: [PATCH 2/2] e2e storage: avoid usage of stdin for file creation It turned out to be unreliable (see https://github.com/kubernetes/kubernetes/issues/112834). Encoding the data inside the command as input for base64 is a workaround that is fine for small amounts of data. It becomes less efficient and/or unusable for large amounts. --- test/e2e/storage/drivers/proxy/io.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/e2e/storage/drivers/proxy/io.go b/test/e2e/storage/drivers/proxy/io.go index 3d67f840455..df0a06c01d4 100644 --- a/test/e2e/storage/drivers/proxy/io.go +++ b/test/e2e/storage/drivers/proxy/io.go @@ -17,6 +17,7 @@ limitations under the License. package proxy import ( + "encoding/base64" "fmt" "io" @@ -66,9 +67,23 @@ func (p PodDirIO) Mkdir(path string) error { } func (p PodDirIO) CreateFile(path string, content io.Reader) error { - _, stderr, err := p.execute([]string{"dd", "of=" + path}, content) + // Piping the content into dd via stdin turned out to be unreliable. + // Sometimes dd would stop after writing zero bytes, without an error + // from ExecWithOptions (reported as + // https://github.com/kubernetes/kubernetes/issues/112834). + // + // Therefore the content is now encoded inside the command itself. + data, err := io.ReadAll(content) if err != nil { - return fmt.Errorf("dd of=%s: stderr=%q, %v", path, stderr, err) + return fmt.Errorf("read content: %v", err) + } + encoded := make([]byte, base64.StdEncoding.EncodedLen(len(data))) + base64.StdEncoding.Encode(encoded, data) + _, stderr, err := p.execute([]string{"sh", "-c", fmt.Sprintf(`base64 -d >'%s' <