preflight

package
v0.196.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package preflight checks that this machine can reach what a scan would read: each repository at its revision, the paths a component is scoped to, each image, each endpoint. With the credentials and the network the scan would have, and before the scan is started.

Every check touches something outside the descriptor, a checkout, a registry, a network or a credential, which is why it lives in `doctor` rather than `validate`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailedCount

func FailedCount(checks []Check) int

FailedCount counts the checks that failed.

func LocalImage added in v0.170.0

func LocalImage(ctx context.Context, ref string) bool

LocalImage reports whether the local Docker daemon holds ref. No daemon, or no docker, is a no.

func LookInDaemon added in v0.188.0

func LookInDaemon(ctx context.Context, ref string) (held, reachable bool)

LookInDaemon asks the local Docker daemon whether it holds ref, and says whether any daemon answered. With docker on PATH the CLI asks, so its context and DOCKER_HOST apply. Without it the daemon's API is asked on its socket, the way Trivy reads an image from a daemon in a container with the socket mounted and no docker CLI installed.

reachable is false only when no daemon answered where one is looked for. A daemon that cannot be asked from here, such as one behind TLS with no docker CLI to hold its certificates, counts as reachable, so a refusal is never blamed on a daemon that may well be there.

Types

type Check

type Check struct {
	// Kind is what was checked: repository, paths, image, host, cluster or account.
	Kind string `json:"kind"`
	// Target names it, without credentials.
	Target string `json:"target"`
	Status Status `json:"status"`
	// Detail is the result in words: what resolved, or why it failed or was not checked.
	Detail string `json:"detail"`
}

Check is one target checked, and what came of it.

func Run

func Run(ctx context.Context, targets []plugin.Target, opts Options) []Check

Run checks every distinct target once, in the order they are first named. Components sharing a repository or an image share its check.

type Options

type Options struct {
	// Offline skips every check that needs the network, and reports each as not checked.
	Offline bool
	// Timeout bounds each target's checks. Zero means 20 seconds.
	Timeout time.Duration
	// Concurrency bounds how many targets are checked at once. Zero means 8.
	Concurrency int
	Probes      Probes
}

Options shape a run.

type Probes

type Probes struct {
	// Revision resolves a repository's revision to a commit.
	Revision func(ctx context.Context, url, revision string) (string, error)
	// Paths checks a repository's paths at a revision and returns the commit it read.
	Paths func(ctx context.Context, url, revision string, paths []string) (string, error)
	// Image checks that an image can be read, and says from where.
	Image func(ctx context.Context, ref string, offline bool) (string, error)
	// Host opens a connection to an endpoint and says what it established.
	Host func(ctx context.Context, rawURL string) (string, error)
	// Cluster resolves a kubeconfig context, "" for the current one, asks its API server for its
	// version, and says what answered.
	Cluster func(ctx context.Context, kubeContext string) (string, error)
	// Account asks a cloud whether the credentials in the environment can read an account, and
	// says what answered.
	Account func(ctx context.Context, provider, id string) (string, error)
}

Probes are the checks themselves. A nil field is the real probe; tests replace them.

type Status

type Status string

Status is how a check ended.

const (
	Passed     Status = "passed"
	Failed     Status = "failed"
	NotChecked Status = "not-checked"
)

The ways a check ends. NotChecked is neither of the others: a check that did not run has not passed, and it has not found anything wrong either.

Jump to

Keyboard shortcuts

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