func()

in validators/docker_validator.go [58:88]


func (d *DockerValidator) Validate(spec SysSpec) ([]error, []error) {
	if spec.RuntimeSpec.DockerSpec == nil {
		// If DockerSpec is not specified, assume current runtime is not
		// docker, skip the docker configuration validation.
		return nil, nil
	}

	// Run 'docker info' with a JSON output and unmarshal it into a dockerInfo object
	info := dockerInfo{}
	cmd := exec.Command("docker", "info", "--format", "{{json .}}")

	// Stderr can contain warnings despite docker info success.
	var outb, errb bytes.Buffer
	cmd.Stdout = &outb
	cmd.Stderr = &errb
	err := cmd.Run()
	if err != nil {
		return nil, []error{errors.Errorf(`failed executing "docker info --format '{{json .}}'"\noutput: %s\nstderr: %s\nerror: %v`, outb.String(), errb.String(), err)}
	}
	if err := d.unmarshalDockerInfo(outb.Bytes(), &info); err != nil {
		return nil, []error{err}
	}

	// validate the resulted docker info object against the spec
	warnings, errs := d.validateDockerInfo(spec.RuntimeSpec.DockerSpec, info)

	if len(errb.String()) > 0 {
		warnings = append(warnings, errors.Errorf(`the command "docker info --format '{{json.}}'" succeeded with potential warnings\noutput: %s`, errb.String()))
	}
	return warnings, errs
}