sonobuoy: github.com/vmware-tanzu/sonobuoy/pkg/plugin/aggregation Index | Files

package aggregation

import "github.com/vmware-tanzu/sonobuoy/pkg/plugin/aggregation"

Package aggregation is responsible for hosting an HTTP server which aggregates results from all of the nodes that are running sonobuoy agent. It is not responsible for dispatching the nodes (see pkg/dispatch), only expecting their results.

Index

Package Files

aggregator.go handler.go run.go status.go update.go

Constants

const (

    // PathResultsByNode is the path for node-specific results to be PUT to. Callers should
    // add two path elements as a suffix to this to specify the node and plugin (e.g. `<path>/node/plugin`)
    PathResultsByNode = "/api/v1/results/by-node"

    // PathResultsGlobal is the path for global (non-node-specific) results to be PUT to. Callers should
    // add one path element as a suffix to this to specify the plugin name (e.g. `<path>/plugin`)
    PathResultsGlobal = "/api/v1/results/global"

    // PathProgressByNode is the path for node-specific progress updates to be POSTed to. Callers should
    // add two path elements as a suffix to this to specify the node and plugin (e.g. `<path>/node/plugin`)
    PathProgressByNode = "api/v1/progress/by-node"

    // PathProgressGlobal is the path for progress updates to be POSTed to for global (non node-specific) plugins.
    // Callers should add one path element as a suffix to this to specify the plugin name (e.g. `<path>/plugin`)
    PathProgressGlobal = "/api/v1/progress/global"
)
const (
    // RunningStatus means the sonobuoy run is still in progress.
    RunningStatus string = "running"
    // CompleteStatus means the sonobuoy run is complete.
    CompleteStatus string = "complete"
    // PostProcessingStatus means the plugins are complete. The state is not
    // put in the more finalized, complete, status until any postprocessing is
    // done.
    PostProcessingStatus string = "post-processing"
    // FailedStatus means one or more plugins has failed and the run will not complete successfully.
    FailedStatus string = "failed"
)
const (
    StatusAnnotationName = "sonobuoy.hept.io/status"
    DefaultStatusPodName = "sonobuoy"
)

func Cleanup Uses

func Cleanup(client kubernetes.Interface, plugins []plugin.Interface)

Cleanup calls cleanup on all plugins

func GetAggregatorPod Uses

func GetAggregatorPod(client kubernetes.Interface, namespace string) (*v1.Pod, error)

GetAggregatorPod gets the sonobuoy aggregator pod based on its label. It returns NoPodWithLabelError in the case where a pod with sonobuoy aggregator label could not be found.

func GetAggregatorPodName Uses

func GetAggregatorPodName(client kubernetes.Interface, namespace string) (string, error)

GetAggregatorPodName gets the sonobuoy aggregator pod name. It returns the default pod name if the pod cannot be found.

func GetPatch Uses

func GetPatch(annotation string) map[string]interface{}

GetPatch takes a json encoded string and creates a map which can be used as a patch to indicate the Sonobuoy status.

func GlobalResultURL Uses

func GlobalResultURL(baseURL, pluginName string) (string, error)

GlobalResultURL is the URL that results that are not node-specific. Takes the baseURL (http[s]://hostname:port/, with trailing slash) pluginName, and an optional extension. If multiple extensions are provided, only the first one is used.

func NewHandler Uses

func NewHandler(
    resultsCallback func(*plugin.Result, http.ResponseWriter),
    progressCallback func(plugin.ProgressUpdate, http.ResponseWriter),
) http.Handler

NewHandler constructs a new aggregation handler which will handler results and pass them to the given results callback.

func NodeResultURL Uses

func NodeResultURL(baseURL, nodeName, pluginName string) (string, error)

NodeResultURL is the URL for results for a given node result. Takes the baseURL (http[s]://hostname:port/, with trailing slash) nodeName, pluginName, and an optional extension. If multiple extensions are provided, only the first one is used.

func Run Uses

func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.AggregationConfig, progressPort, namespace, outdir string) error

Run runs an aggregation server and gathers results, in accordance with the given sonobuoy configuration.

Basic workflow:

1. Create the aggregator object (`aggr`) to keep track of results 2. Launch the HTTP server with the aggr's HandleHTTPResult function as the

callback

3. Run all the aggregation plugins, monitoring each one in a goroutine,

configuring them to send failure results through a shared channel

4. Hook the shared monitoring channel up to aggr's IngestResults() function 5. Block until aggr shows all results accounted for (results come in through

the HTTP callback), stopping the HTTP server on completion

type Aggregator Uses

type Aggregator struct {
    // OutputDir is the directory to write the node results
    OutputDir string

    // Results stores a map of check-in results the server has seen
    Results map[string]*plugin.Result

    // ExpectedResults stores a map of results the server should expect
    ExpectedResults map[string]*plugin.ExpectedResult

    // LatestProgressUpdates is the map that saves the most recent progress update sent by
    // each plugin.
    LatestProgressUpdates map[string]*plugin.ProgressUpdate

    // FailedResults is a map to track which plugin results were received
    // but returned errors during processing. This enables us to retry results
    // that failed to process if the client tries, as opposed to rejecting
    // them as duplicates. Important if connection resets or network issues
    // are common.
    FailedResults map[string]time.Time
    // contains filtered or unexported fields
}

Aggregator is responsible for taking results from an HTTP server (configured elsewhere), saving them to the filesystem, and keeping track of what has been seen so far, so that we can return when all expected results are present and accounted for.

func NewAggregator Uses

func NewAggregator(outputDir string, expected []plugin.ExpectedResult) *Aggregator

NewAggregator constructs a new Aggregator object to write the given result set out to the given output directory.

func (*Aggregator) HandleHTTPProgressUpdate Uses

func (a *Aggregator) HandleHTTPProgressUpdate(progress plugin.ProgressUpdate, w http.ResponseWriter)

HandleHTTPProgressUpdate wraps the aggregators processProgressUpdate method in such a way as to respond with appropriate logging and HTTP codes.

func (*Aggregator) HandleHTTPResult Uses

func (a *Aggregator) HandleHTTPResult(result *plugin.Result, w http.ResponseWriter)

HandleHTTPResult is called every time the HTTP server gets a well-formed request with results. This method is responsible for returning with things like a 409 conflict if a node has checked in twice (or a 403 forbidden if a node isn't expected), as well as actually calling handleResult to write the results to OutputDir.

func (*Aggregator) IngestResults Uses

func (a *Aggregator) IngestResults(ctx context.Context, resultsCh <-chan *plugin.Result)

IngestResults takes a channel of results and handles them as they come in. Since most plugins submit over HTTP, this method is currently only used to consume an error stream from each plugin's Monitor() function.

If we support plugins that are just simple commands that the Sonobuoy aggregator runs, those plugins can submit results through the same channel.

func (*Aggregator) RunAndMonitorPlugin Uses

func (a *Aggregator) RunAndMonitorPlugin(ctx context.Context, timeout time.Duration, p plugin.Interface, client kubernetes.Interface, nodes []corev1.Node, address string, cert *tls.Certificate, aggregatorPod *corev1.Pod, progressPort string)

RunAndMonitorPlugin will start a plugin then monitor it for errors starting/running. Errors detected will be handled by saving an error result in the aggregator.Results.

func (*Aggregator) Wait Uses

func (a *Aggregator) Wait(stop chan bool)

Wait blocks until all expected results have come in.

type Handler Uses

type Handler struct {
    mux.Router

    // ResultsCallback is the function that is called when a result is checked in.
    ResultsCallback func(*plugin.Result, http.ResponseWriter)

    // ProgressCallback is the function that is called when a progress update is checked in.
    ProgressCallback func(plugin.ProgressUpdate, http.ResponseWriter)
}

Handler is a net/http Handler that can handle API requests for aggregation of results from nodes, calling the provided callback with the results

type NoPodWithLabelError Uses

type NoPodWithLabelError string

NoPodWithLabelError represents an error encountered when a pod with a given label can't be found

func (NoPodWithLabelError) Error Uses

func (n NoPodWithLabelError) Error() string

type PluginStatus Uses

type PluginStatus struct {
    Plugin string `json:"plugin"`
    Node   string `json:"node"`
    Status string `json:"status"`

    ResultStatus       string         `json:"result-status"`
    ResultStatusCounts map[string]int `json:"result-counts"`

    Progress *plugin.ProgressUpdate `json:"progress,omitempty"`
}

PluginStatus represents the current status of an individual plugin.

func (PluginStatus) Key Uses

func (p PluginStatus) Key() string

Key returns a unique identifier for the plugin that these status values correspond to.

type Status Uses

type Status struct {
    Plugins []PluginStatus `json:"plugins"`
    Status  string         `json:"status"`
    Tarball TarInfo        `json:"tar-info,omitempty"`
}

Status represents the current status of a Sonobuoy run. TODO(EKF): Find a better name for this struct/package.

func GetStatus Uses

func GetStatus(client kubernetes.Interface, namespace string) (*Status, error)

GetStatus returns the current status status on the sonobuoy pod. If the pod does not exist, is not running, or is missing the status annotation, an error is returned.

type TarInfo Uses

type TarInfo struct {
    Name      string    `json:"name"`
    CreatedAt time.Time `json:"created"`
    SHA256    string    `json:"sha256"`
    Size      int64     `json:"size"`
}

TarInfo is the type that contains information regarding the tarball that a user would get after running `sonobuoy retrieve`.

Package aggregation imports 26 packages (graph) and is imported by 6 packages. Updated 2020-07-10. Refresh now. Tools for package owners.