sonobuoy: Index | Examples | Files | Directories

package results

import ""

Package results provides a low level API to extract data from a Sonobuoy result archive.



Package Files

doc.go junit.go manual.go output.go processing.go raw.go reader.go


const (
    // JUnitStdoutKey is the key in the Items.Details map for the system-out output.
    JUnitStdoutKey = "system-out"

    // JUnitStderrKey is the key in the Items.Details map for the system-out output.
    JUnitStderrKey = "system-err"

    // JUnitFailureKey is the key in the Items.Details map for the failure output.
    JUnitFailureKey = "failure"

    // JUnitErrorKey is the key in the Items.Details map for the error output.
    JUnitErrorKey = "error"
const (
    // StatusFailed is the key we base junit pass/failure off of and save into
    // our canonical results format.
    StatusFailed = "failed"

    // StatusPassed is the key we base junit pass/failure off of and save into
    // our canonical results format.
    StatusPassed = "passed"

    // StatusSkipped is the key we base junit pass/failure off of and save into
    // our canonical results format.
    StatusSkipped = "skipped"

    // StatusUnknown is the key we fallback to in our canonical results format
    // if another can not be determined.
    StatusUnknown = "unknown"

    // StatusTimeout is the key used when the plugin does not report results within the
    // timeout period. It will be treated as a failure (e.g. its parent will be marked
    // as a failure).
    StatusTimeout = "timeout"

    // PostProcessedResultsFile is the name of the file we create when doing
    // postprocessing on the plugin results.
    PostProcessedResultsFile = "sonobuoy_results.yaml"
const (
    ResultFormatJUnit  = "junit"
    ResultFormatE2E    = "e2e"
    ResultFormatRaw    = "raw"
    ResultFormatManual = "manual"

ResultFormat constants are the supported values for the resultFormat field which enables post processing.

const (
    // PluginsDir defines where in the archive directories for plugin results are.
    PluginsDir = "plugins/"

    // ResultsDir defines where in the archive the plugin results are.
    // Example: plugins/<name>/results
    ResultsDir = "results/"

    // ErrorsDir defines where in the archive the errors running the plugin get reported.
    // These are the Sonobuoy reported errors, e.g. failure to start a plugin, timeout, etc.
    // This is not the appropriate directory for things like test failures.
    // Example: plugins/<name>/errors
    ErrorsDir = "errors/"

    // DefaultErrFile is the file name used when Sonobuoy is reporting an error running a plugin.
    // Is written into the ErrorsDir directory.
    DefaultErrFile = "error.json"

    // InfoFile contains data not that isn't strictly in another location
    // but still relevent to post-processing or understanding the run in some way.
    InfoFile = "info.json"
const (
    // UnknownVersion lets the consumer know if this client can detect the archive version or not.
    UnknownVersion = "v?.?"
    VersionEight   = "v0.8"
    VersionNine    = "v0.9"
    VersionTen     = "v0.10"
    VersionFifteen = "v0.15"

Versions corresponding to Kubernetes minor version values. We used to roughly version our results tarballs in sync with minor version patches and so checking the server version for one of these prefixes would be sufficient to inform the parser where certain files would be.

func ConfigFile Uses

func ConfigFile(version string) string

ConfigFile returns the path to the sonobuoy config file. This is not a method as it is used to determine the version of the archive.

func DiscoverVersion Uses

func DiscoverVersion(reader io.Reader) (string, error)

DiscoverVersion takes a Sonobuoy archive stream and extracts just the version of the archive.

func ExtractBytes Uses

func ExtractBytes(file string, path string, info os.FileInfo, buf *bytes.Buffer) error

ExtractBytes pulls out bytes into a buffer for any path matching file.

func ExtractConfig Uses

func ExtractConfig(path string, info os.FileInfo, conf *config.Config) error

ExtractConfig populates the config object regardless of version.

func ExtractFileIntoStruct Uses

func ExtractFileIntoStruct(file, path string, info os.FileInfo, object interface{}) error

ExtractFileIntoStruct is a helper for a common use case of extracting the contents of one file into the object.

func ExtractIntoStruct Uses

func ExtractIntoStruct(predicate func(string) bool, path string, info os.FileInfo, object interface{}) error

ExtractIntoStruct takes a predicate function and some file information and decodes the contents of the file that matches the predicate into the interface passed in (generally a pointer to a struct/slice).

func JUnitErrored Uses

func JUnitErrored(testCase JUnitTestCase) bool

JUnitErrored returns true if the test errored.

func JUnitFailed Uses

func JUnitFailed(testCase JUnitTestCase) bool

JUnitFailed returns true if the test failed.

func JUnitPassed Uses

func JUnitPassed(testCase JUnitTestCase) bool

JUnitPassed returns true if the test passed.

func JUnitSkipped Uses

func JUnitSkipped(testCase JUnitTestCase) bool

JUnitSkipped returns true if the test was skipped.

func SaveProcessedResults Uses

func SaveProcessedResults(pluginName, baseDir string, item Item) error

SaveProcessedResults saves the given item in the predefined location for the postprocessed results (the path base/plugins/plugin_name/sonobuoy_results)

type Item Uses

type Item struct {
    Name     string                 `json:"name" yaml:"name"`
    Status   string                 `json:"status" yaml:"status"`
    Metadata map[string]string      `json:"meta,omitempty" yaml:"meta,omitempty"`
    Details  map[string]interface{} `json:"details,omitempty" yaml:"details,omitempty"`
    Items    []Item                 `json:"items,omitempty" yaml:"items,omitempty"`

Item is the central format for plugin results. Various plugin types can be transformed into this simple format and set at a standard location in our results tarball for simplified processing by any consumer.

func PostProcessPlugin Uses

func PostProcessPlugin(p plugin.Interface, dir string) (Item, []error)

PostProcessPlugin will inspect the files in the given directory (representing the location of the results directory for a sonobuoy run, not the plugin specific results directory). Based on the type of plugin results, it will record what tests passed/failed (if junit) or record what files were produced (if raw) and return that information in an Item object. All errors encountered are returned.

func (Item) Empty Uses

func (i Item) Empty() bool

Empty returns true if the Item is empty.

func (*Item) GetSubTreeByName Uses

func (i *Item) GetSubTreeByName(root string) *Item

GetSubTreeByName traverses the tree and returns a reference to the subtree whose root has the given name.

type JUnitAlphabetizedTestCases Uses

type JUnitAlphabetizedTestCases []JUnitTestCase

JUnitAlphabetizedTestCases implements Sort over the list of testCases.

func (JUnitAlphabetizedTestCases) Len Uses

func (a JUnitAlphabetizedTestCases) Len() int

func (JUnitAlphabetizedTestCases) Less Uses

func (a JUnitAlphabetizedTestCases) Less(i, j int) bool

func (JUnitAlphabetizedTestCases) Swap Uses

func (a JUnitAlphabetizedTestCases) Swap(i, j int)

type JUnitErrorMessage Uses

type JUnitErrorMessage struct {
    Message  string `xml:"message,attr"`
    Type     string `xml:"type,attr"`
    Contents string `xml:",chardata"`

JUnitErrorMessage contains data related to a failed test.

type JUnitFailureMessage Uses

type JUnitFailureMessage struct {
    Message  string `xml:"message,attr"`
    Type     string `xml:"type,attr"`
    Contents string `xml:",chardata"`

JUnitFailureMessage contains data related to a failed test.

type JUnitProperty Uses

type JUnitProperty struct {
    Name  string `xml:"name,attr"`
    Value string `xml:"value,attr"`

JUnitProperty represents a key/value pair used to define properties.

type JUnitSkipMessage Uses

type JUnitSkipMessage struct {
    Message string `xml:"message,attr"`

JUnitSkipMessage contains the reason why a testcase was skipped.

type JUnitTestCase Uses

type JUnitTestCase struct {
    XMLName      xml.Name             `xml:"testcase"`
    Classname    string               `xml:"classname,attr"`
    Name         string               `xml:"name,attr"`
    Time         string               `xml:"time,attr"`
    SkipMessage  *JUnitSkipMessage    `xml:"skipped,omitempty"`
    Failure      *JUnitFailureMessage `xml:"failure,omitempty"`
    ErrorMessage *JUnitErrorMessage   `xml:"error,omitempty"`
    SystemOut    string               `xml:"system-out,omitempty"`
    SystemErr    string               `xml:"system-err,omitempty"`

JUnitTestCase is a single test case with its result.

func JUnitFilter Uses

func JUnitFilter(predicate func(testCase JUnitTestCase) bool, testSuite JUnitTestSuite) []JUnitTestCase

JUnitFilter keeps only the tests that match the predicate function.

type JUnitTestSuite Uses

type JUnitTestSuite struct {
    XMLName    xml.Name        `xml:"testsuite"`
    Tests      int             `xml:"tests,attr"`
    Failures   int             `xml:"failures,attr"`
    Time       float64         `xml:"time,attr"`
    Name       string          `xml:"name,attr"`
    Properties []JUnitProperty `xml:"properties>property,omitempty"`
    TestCases  []JUnitTestCase `xml:"testcase"`

JUnitTestSuite is a single JUnit test suite which may contain many testcases.

type JUnitTestSuites Uses

type JUnitTestSuites struct {
    XMLName xml.Name         `xml:"testsuites"`
    Suites  []JUnitTestSuite `xml:"testsuite"`

JUnitTestSuites is a collection of JUnit test suites.

type Reader Uses

type Reader struct {
    Version string

Reader holds a reader and a version. It uses the version to know where to find files within the archive.

func NewReaderFromBytes Uses

func NewReaderFromBytes(data []byte) (*Reader, error)

NewReaderFromBytes is a helper constructor that will discover the version of the archive and return a new Reader with the correct version already populated.


path := "testdata/results-0.8.tar.gz"
data, err := ioutil.ReadFile(path)
if err != nil {
results, err := results.NewReaderFromBytes(data)
if err != nil {



func NewReaderWithVersion Uses

func NewReaderWithVersion(reader io.Reader, version string) *Reader

NewReaderWithVersion creates a results.Reader that interprets a results archive of the version passed in. Useful if the reader can be read only once and if the version of the data to read is known.


path := "testdata/results-0.9.tar.gz"
f, err := os.Open(path)
if err != nil {
reader, err := gzip.NewReader(f)
if err != nil {
r := results.NewReaderWithVersion(reader, results.VersionNine)



func (*Reader) FileReader Uses

func (r *Reader) FileReader(filename string) (io.Reader, error)

FileReader returns a reader for a file in the archive.

func (*Reader) Metadata Uses

func (r *Reader) Metadata() string

Metadata is the location of the metadata directory in the results archive.

func (*Reader) NamespacedResources Uses

func (r *Reader) NamespacedResources() string

NamespacedResources returns the path to the directory that contains information about namespaced Kubernetes resources.

func (*Reader) NodesFile Uses

func (r *Reader) NodesFile() string

NodesFile returns the path to the file that lists the nodes of the Kubernetes cluster.

func (*Reader) NonNamespacedResources Uses

func (r *Reader) NonNamespacedResources() string

NonNamespacedResources returns the path to the non-namespaced directory.

func (*Reader) PluginResultsItem Uses

func (r *Reader) PluginResultsItem(plugin string) (*Item, error)

PluginResultsItem returns the results file from the given plugin if found, error otherwise.

func (*Reader) PluginResultsReader Uses

func (r *Reader) PluginResultsReader(plugin string) (io.Reader, error)

PluginResultsReader returns the results file from the given plugin if found, error otherwise.

func (*Reader) RunInfoFile Uses

func (r *Reader) RunInfoFile() string

RunInfoFile returns the path to the Sonobuoy RunInfo file which is extra metadata about the run. This was added in v0.16.1. The function will return the same string even for earlier versions where that file does not exist.

func (*Reader) ServerGroupsFile Uses

func (r *Reader) ServerGroupsFile() string

ServerGroupsFile returns the path to the groups the Kubernetes API supported at the time of the run.

func (*Reader) ServerVersionFile Uses

func (r *Reader) ServerVersionFile() string

ServerVersionFile is the location of the file that contains the Kubernetes version Sonobuoy ran on.

func (*Reader) WalkFiles Uses

func (r *Reader) WalkFiles(walkfn filepath.WalkFunc) error

WalkFiles walks all of the files in the archive. Processing stops at the first error. The error is returned except in the special case of errStopWalk which will stop processing but nil will be returned.


e2epackage e2e defines files and directories found in the e2e plugin results.

Package results imports 21 packages (graph) and is imported by 6 packages. Updated 2020-07-17. Refresh now. Tools for package owners.