1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-31 22:46:25 +00:00

Add etcd snapshot fix and more log messages to certificate bundle

Add function to collect stdout and stderr logs from containers
This commit is contained in:
galal-hussein
2018-07-18 22:44:55 +02:00
committed by Alena Prokharchyk
parent b483981539
commit 3ce50d28d3
5 changed files with 52 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ package docker
import (
"archive/tar"
"bytes"
"context"
"encoding/base64"
"encoding/json"
@@ -17,6 +18,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/rancher/rke/log"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
@@ -362,6 +364,22 @@ func ReadContainerLogs(ctx context.Context, dClient *client.Client, containerNam
return dClient.ContainerLogs(ctx, containerName, types.ContainerLogsOptions{Follow: follow, ShowStdout: true, ShowStderr: true, Timestamps: false, Tail: tail})
}
func GetContainerLogsStdoutStderr(ctx context.Context, dClient *client.Client, containerName, tail string) (string, error) {
var containerStderr bytes.Buffer
var containerStdout bytes.Buffer
var containerLog string
clogs, logserr := ReadContainerLogs(ctx, dClient, containerName, false, tail)
if logserr != nil {
logrus.Debug("logserr: %v", logserr)
return containerLog, fmt.Errorf("Failed to get gather logs from container [%s]: %v", containerName, logserr)
}
defer clogs.Close()
stdcopy.StdCopy(&containerStdout, &containerStderr, clogs)
containerLog = containerStderr.String()
containerLog = strings.TrimSuffix(containerLog, "\n")
return containerLog, nil
}
func tryRegistryAuth(pr v3.PrivateRegistry) types.RequestPrivilegeFunc {
return func() (string, error) {
return getRegistryAuth(pr)