prune

package
v3.7.0-rc.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2017 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package prune contains logic for pruning images and interoperating with the integrated Docker registry.

Index

Constants

View Source
const (
	// ReferencedImageEdgeKind defines a "strong" edge where the tail is an
	// ImageNode, with strong indicating that the ImageNode tail is not a
	// candidate for pruning.
	ReferencedImageEdgeKind = "ReferencedImage"
	// WeakReferencedImageEdgeKind defines a "weak" edge where the tail is
	// an ImageNode, with weak indicating that this particular edge does
	// not keep an ImageNode from being a candidate for pruning.
	WeakReferencedImageEdgeKind = "WeakReferencedImage"

	// ReferencedImageConfigEdgeKind defines an edge from an ImageStreamNode or an
	// ImageNode to an ImageComponentNode.
	ReferencedImageConfigEdgeKind = "ReferencedImageConfig"

	// ReferencedImageLayerEdgeKind defines an edge from an ImageStreamNode or an
	// ImageNode to an ImageComponentNode.
	ReferencedImageLayerEdgeKind = "ReferencedImageLayer"
)

TODO these edges should probably have an `Add***Edges` method in images/graph and be moved there

Variables

This section is empty.

Functions

func DetermineRegistryHost

func DetermineRegistryHost(images *imageapi.ImageList, imageStreams *imageapi.ImageStreamList) (string, error)

DetermineRegistryHost returns registry host embedded in a pull-spec of the latest unmanaged image or the latest imagestream from the provided lists. If no such pull-spec is found, error is returned.

func TryProtocolsWithRegistryURL

func TryProtocolsWithRegistryURL(registry string, allowInsecure bool, action func(registryURL url.URL) error) (*url.URL, error)

TryProtocolsWithRegistryURL runs given action with different protocols until no error is returned. The https protocol is the first attempt. If it fails and allowInsecure is true, http will be the next. Obtained errors will be concatenated and returned.

Types

type BlobDeleter added in v1.3.0

type BlobDeleter interface {
	// DeleteBlob uses registryClient to ask the registry at registryURL
	// to remove the blob.
	DeleteBlob(registryClient *http.Client, registryURL *url.URL, blob string) error
}

BlobDeleter knows how to delete a blob from the Docker registry.

func NewBlobDeleter added in v1.3.0

func NewBlobDeleter() BlobDeleter

NewBlobDeleter creates a new blobDeleter.

type DefaultRegistryPinger

type DefaultRegistryPinger struct {
	Client   *http.Client
	Insecure bool
}

DefaultRegistryPinger implements RegistryPinger.

func (*DefaultRegistryPinger) Ping

func (drp *DefaultRegistryPinger) Ping(registry string) (*url.URL, error)

Ping verifies that the integrated registry is ready, determines its transport protocol and returns its url or error.

type DryRunRegistryPinger

type DryRunRegistryPinger struct {
}

DryRunRegistryPinger implements RegistryPinger.

func (*DryRunRegistryPinger) Ping

func (*DryRunRegistryPinger) Ping(registry string) (*url.URL, error)

Ping implements Ping method.

type ImageDeleter added in v1.3.0

type ImageDeleter interface {
	// DeleteImage removes the image from OpenShift's storage.
	DeleteImage(image *imageapi.Image) error
}

ImageDeleter knows how to remove images from OpenShift.

func NewImageDeleter added in v1.3.0

func NewImageDeleter(images imageclient.ImagesGetter) ImageDeleter

NewImageDeleter creates a new imageDeleter.

type ImageStreamDeleter added in v1.3.0

type ImageStreamDeleter interface {
	// GetImageStream returns a fresh copy of an image stream.
	GetImageStream(stream *imageapi.ImageStream) (*imageapi.ImageStream, error)
	// UpdateImageStream removes all references to the image from the image
	// stream's status.tags. The updated image stream is returned.
	UpdateImageStream(stream *imageapi.ImageStream) (*imageapi.ImageStream, error)
	// NotifyImageStreamPrune shows notification about updated image stream.
	NotifyImageStreamPrune(stream *imageapi.ImageStream, updatedTags []string, deletedTags []string)
}

ImageStreamDeleter knows how to remove an image reference from an image stream.

func NewImageStreamDeleter added in v1.3.0

func NewImageStreamDeleter(streams imageclient.ImageStreamsGetter) ImageStreamDeleter

NewImageStreamDeleter creates a new imageStreamDeleter.

type LayerLinkDeleter added in v1.4.0

type LayerLinkDeleter interface {
	// DeleteLayerLink uses registryClient to ask the registry at registryURL to
	// delete the repository layer link.
	DeleteLayerLink(registryClient *http.Client, registryURL *url.URL, repo, linkName string) error
}

LayerLinkDeleter knows how to delete a repository layer link from the Docker registry.

func NewLayerLinkDeleter added in v1.4.0

func NewLayerLinkDeleter() LayerLinkDeleter

NewLayerLinkDeleter creates a new layerLinkDeleter.

type ManifestDeleter added in v1.3.0

type ManifestDeleter interface {
	// DeleteManifest uses registryClient to ask the registry at registryURL to
	// delete the repository's image manifest data.
	DeleteManifest(registryClient *http.Client, registryURL *url.URL, repo, manifest string) error
}

ManifestDeleter knows how to delete image manifest data for a repository from the Docker registry.

func NewManifestDeleter added in v1.3.0

func NewManifestDeleter() ManifestDeleter

NewManifestDeleter creates a new manifestDeleter.

type Pruner added in v1.3.0

type Pruner interface {
	// Prune uses imagePruner, streamPruner, layerLinkPruner, blobPruner, and
	// manifestPruner to remove images that have been identified as candidates
	// for pruning based on the Pruner's internal pruning algorithm.
	// Please see NewPruner for details on the algorithm.
	Prune(imagePruner ImageDeleter, streamPruner ImageStreamDeleter, layerLinkPruner LayerLinkDeleter, blobPruner BlobDeleter, manifestPruner ManifestDeleter) error
}

Pruner knows how to prune istags, images, layers and image configs.

func NewPruner added in v1.3.0

func NewPruner(options PrunerOptions) (Pruner, error)

NewPruner creates a Pruner.

Images younger than keepYoungerThan and images referenced by image streams and/or pods younger than keepYoungerThan are preserved. All other images are candidates for pruning. For example, if keepYoungerThan is 60m, and an ImageStream is only 59 minutes old, none of the images it references are eligible for pruning.

keepTagRevisions is the number of revisions per tag in an image stream's status.tags that are preserved and ineligible for pruning. Any revision older than keepTagRevisions is eligible for pruning.

pruneOverSizeLimit is a boolean flag speyfing that all images exceeding limits defined in their namespace will be considered for pruning. Important to note is the fact that this flag does not work in any combination with the keep* flags.

images, streams, pods, rcs, bcs, builds, and dcs are the resources used to run the pruning algorithm. These should be the full list for each type from the cluster; otherwise, the pruning algorithm might result in incorrect calculations and premature pruning.

The ImageDeleter performs the following logic:

remove any image that was created at least *n* minutes ago and is *not* currently referenced by:

- any pod created less than *n* minutes ago - any image stream created less than *n* minutes ago - any running pods - any pending pods - any replication controllers - any deployment configs - any build configs - any builds - the n most recent tag revisions in an image stream's status.tags

including only images with the annotation openshift.io/image.managed=true unless allImages is true.

When removing an image, remove all references to the image from all ImageStreams having a reference to the image in `status.tags`.

Also automatically remove any image layer that is no longer referenced by any images.

type PrunerOptions added in v1.3.0

type PrunerOptions struct {
	// KeepYoungerThan indicates the minimum age an Image must be to be a
	// candidate for pruning.
	KeepYoungerThan *time.Duration
	// KeepTagRevisions is the minimum number of tag revisions to preserve;
	// revisions older than this value are candidates for pruning.
	KeepTagRevisions *int
	// PruneOverSizeLimit indicates that images exceeding defined limits (openshift.io/Image)
	// will be considered as candidates for pruning.
	PruneOverSizeLimit *bool
	// AllImages considers all images for pruning, not just those pushed directly to the registry.
	AllImages *bool
	// Namespace to be pruned, if specified it should never remove Images.
	Namespace string
	// Images is the entire list of images in OpenShift. An image must be in this
	// list to be a candidate for pruning.
	Images *imageapi.ImageList
	// Streams is the entire list of image streams across all namespaces in the
	// cluster.
	Streams *imageapi.ImageStreamList
	// Pods is the entire list of pods across all namespaces in the cluster.
	Pods *kapi.PodList
	// RCs is the entire list of replication controllers across all namespaces in
	// the cluster.
	RCs *kapi.ReplicationControllerList
	// BCs is the entire list of build configs across all namespaces in the
	// cluster.
	BCs *buildapi.BuildConfigList
	// Builds is the entire list of builds across all namespaces in the cluster.
	Builds *buildapi.BuildList
	// DCs is the entire list of deployment configs across all namespaces in the
	// cluster.
	DCs *deployapi.DeploymentConfigList
	// LimitRanges is a map of LimitRanges across namespaces, being keys in this map.
	LimitRanges map[string][]*kapi.LimitRange
	// DryRun indicates that no changes will be made to the cluster and nothing
	// will be removed.
	DryRun bool
	// RegistryClient is the http.Client to use when contacting the registry.
	RegistryClient *http.Client
	// RegistryURL is the URL of the integrated Docker registry.
	RegistryURL *url.URL
}

PrunerOptions contains the fields used to initialize a new Pruner.

type RegistryPinger

type RegistryPinger interface {
	// Ping performs a health check against registry. It returns registry url qualified with schema unless an
	// error occurs.
	Ping(registry string) (*url.URL, error)
}

RegistryPinger performs a health check against a registry.

Jump to

Keyboard shortcuts

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