From 1793132198daa33c875d351ebad04745140f51eb Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 3 Oct 2022 21:16:16 +0200 Subject: [PATCH] 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' <