Skip to content

Commit 2a4782a

Browse files
ironymanneolit123
andcommitted
Split stderr and stdout in docker info parse
Co-authored-by: Lubomir I. Ivanov <neolit123@gmail.com>
1 parent 43713be commit 2a4782a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

validators/docker_validator.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package system
1818

1919
import (
20+
"bytes"
2021
"encoding/json"
2122
"os/exec"
2223
"regexp"
@@ -63,16 +64,27 @@ func (d *DockerValidator) Validate(spec SysSpec) ([]error, []error) {
6364

6465
// Run 'docker info' with a JSON output and unmarshal it into a dockerInfo object
6566
info := dockerInfo{}
66-
out, err := exec.Command("docker", "info", "--format", "{{json .}}").CombinedOutput()
67+
cmd := exec.Command("docker", "info", "--format", "{{json .}}")
68+
69+
// Stderr can contain warnings despite docker info success.
70+
var outb, errb bytes.Buffer
71+
cmd.Stdout = &outb
72+
cmd.Stderr = &errb
73+
err := cmd.Run()
6774
if err != nil {
68-
return nil, []error{errors.Errorf(`failed executing "docker info --format '{{json .}}'"\noutput: %s\nerror: %v`, string(out), err)}
75+
return nil, []error{errors.Errorf(`failed executing "docker info --format '{{json .}}'"\noutput: %s\nstderr: %s\nerror: %v`, outb.String(), errb.String(), err)}
6976
}
70-
if err := d.unmarshalDockerInfo(out, &info); err != nil {
77+
if err := d.unmarshalDockerInfo(outb.Bytes(), &info); err != nil {
7178
return nil, []error{err}
7279
}
7380

7481
// validate the resulted docker info object against the spec
75-
return d.validateDockerInfo(spec.RuntimeSpec.DockerSpec, info)
82+
warnings, errs := d.validateDockerInfo(spec.RuntimeSpec.DockerSpec, info)
83+
84+
if len(errb.String()) > 0 {
85+
warnings = append(warnings, errors.Errorf(`the command "docker info --format '{{json.}}'" succeeded with potential warnings\noutput: %s`, errb.String()))
86+
}
87+
return warnings, errs
7688
}
7789

7890
func (d *DockerValidator) unmarshalDockerInfo(b []byte, info *dockerInfo) error {

0 commit comments

Comments
 (0)