mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
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.
This commit is contained in:
parent
64731baffe
commit
1793132198
@ -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' <<EOF
|
||||
%s
|
||||
EOF`, path, string(encoded))}, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decoding into %q: stderr=%q, %v", path, stderr, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -90,7 +105,7 @@ func (p PodDirIO) RemoveAll(path string) error {
|
||||
}
|
||||
|
||||
func (p PodDirIO) execute(command []string, stdin io.Reader) (string, string, error) {
|
||||
stdout, stderr, err := e2epod.ExecWithOptions(framework.ExecOptions{
|
||||
stdout, stderr, err := e2epod.ExecWithOptions(p.F, e2epod.ExecOptions{
|
||||
Command: command,
|
||||
Namespace: p.Namespace,
|
||||
PodName: p.PodName,
|
||||
|
Loading…
Reference in New Issue
Block a user