aggregation

package
v0.56.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: Apache-2.0 Imports: 28 Imported by: 2

Documentation

Overview

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

Constants

View Source
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"
)
View Source
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 the aggregator itself has failed and results may not be available at all.
	// It does not indicate success or failure of any/all plugins.
	FailedStatus string = "failed"
)
View Source
const (
	StatusAnnotationName = "sonobuoy.hept.io/status"
	DefaultStatusPodName = "sonobuoy"
)

Variables

This section is empty.

Functions

func Cleanup

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

Cleanup calls cleanup on all plugins

func GetAggregatorPod added in v0.15.2

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 added in v0.15.2

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 added in v0.14.0

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 added in v0.11.0

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 added in v0.11.0

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 added in v0.11.0

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

func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.AggregationConfig, progressPort, pluginResultsDir, 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

Types

type Aggregator

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

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 added in v0.15.4

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

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

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 added in v0.14.3

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, pluginResultDir 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

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

Wait blocks until all expected results have come in.

type Handler added in v0.11.0

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 added in v0.15.2

type NoPodWithLabelError string

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

func (NoPodWithLabelError) Error added in v0.15.2

func (n NoPodWithLabelError) Error() string

type PluginStatus added in v0.11.0

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 added in v0.15.4

func (p PluginStatus) Key() string

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

type Status added in v0.11.0

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 added in v0.14.0

func GetStatus(client kubernetes.Interface, namespace string) (*Status, *corev1.Pod, 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 added in v0.15.2

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`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL