1
0
mirror of https://github.com/rancher/rke.git synced 2025-09-01 06:56:29 +00:00

recoverable provisioning

This commit is contained in:
moelsayed
2018-01-11 01:03:08 +02:00
parent 34199e7f4a
commit 4c08db1d53
10 changed files with 264 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package docker
import (
"archive/tar"
"context"
"fmt"
"io"
@@ -271,3 +272,20 @@ func IsSupportedDockerVersion(info types.Info, K8sVersion string) (bool, error)
}
return false, nil
}
func ReadFileFromContainer(ctx context.Context, dClient *client.Client, hostname, container, filePath string) (string, error) {
reader, _, err := dClient.CopyFromContainer(ctx, container, filePath)
if err != nil {
return "", fmt.Errorf("Failed to copy file [%s] from container [%s] on host [%s]: %v", filePath, container, hostname, err)
}
defer reader.Close()
tarReader := tar.NewReader(reader)
if _, err := tarReader.Next(); err != nil {
return "", err
}
file, err := ioutil.ReadAll(tarReader)
if err != nil {
return "", err
}
return string(file), nil
}