inventory

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Add represents those tags that are freely promotable, without fear of an
	// overwrite (we are only adding tags).
	Add TagOp = iota
	// Move represents those tags that conflict with existing digests, and so
	// must be move to re-point to the digest that we want to promote as defined
	// in the manifest. It can be thought of a Delete followed by an Add.
	Move = iota
	// Delete represents those tags that are not in the manifest and should thus
	// be removed and deleted. This is a kind of "demotion".
	Delete = iota
)

Variables

This section is empty.

Functions

func GetDeleteCmd

func GetDeleteCmd(
	rc RegistryContext,
	useServiceAccount bool,
	img ImageName,
	digest Digest) []string

GetDeleteCmd generates the cloud command used to delete images (used for garbage collection).

func GetRegistryListTagsCmd

func GetRegistryListTagsCmd(
	rc RegistryContext,
	useServiceAccount bool,
	img string) []string

GetRegistryListTagsCmd generates the invocation for retrieving all digests (and tags on them) for a given image.

func GetRegistryListingCmd

func GetRegistryListingCmd(
	rc RegistryContext,
	useServiceAccount bool) []string

GetRegistryListingCmd generates the invocation for retrieving all images in a GCR.

func GetWriteCmd

func GetWriteCmd(
	dest RegistryContext,
	useServiceAccount bool,
	srcRegistry RegistryName,
	image ImageName,
	digest Digest,
	tag Tag,
	tp TagOp) []string

GetWriteCmd generates a gcloud command that is used to make modifications to a Docker Registry.

func MaybeUseServiceAccount

func MaybeUseServiceAccount(
	serviceAccount string,
	useServiceAccount bool,
	cmd []string) []string

MaybeUseServiceAccount injects a '--account=...' argument to the command with the given service account.

func ToFQIN

func ToFQIN(registryName RegistryName,
	imageName ImageName,
	digest Digest) string

ToFQIN combines a RegistryName, ImageName, and Digest to form a fully-qualified image name (FQIN).

func ToPQIN

func ToPQIN(registryName RegistryName, imageName ImageName, tag Tag) string

ToPQIN converts a RegistryName, ImageName, and Tag to form a partially-qualified image name (PQIN). It's less exact than a FQIN because the digest information is not used.

Types

type CapturedRequests

type CapturedRequests map[PromotionRequest]int

CapturedRequests holds a map of all PromotionRequests that were generated. It is used for both -dry-run and testing.

type Digest

type Digest string

Digest is a string that contains the SHA256 hash of a Docker container image.

type DigestTags

type DigestTags map[Digest]TagSlice

DigestTags is a map where each digest is associated with a TagSlice. It is associated with a TagSlice because an image digest can have more than 1 tag pointing to it, even within the same image name's namespace (tags are namespaced by the image name).

func (DigestTags) Overwrite

func (a DigestTags) Overwrite(b DigestTags)

Overwrite insert's b's values into a.

type DigestTagsContext

type DigestTagsContext struct {
	ImageName    ImageName
	RegistryName RegistryName
}

DigestTagsContext holds information about the request that was used to fetch the list of digests and associated tags for a particular image. It is used in ReadDigestsAndTags().

type Error

type Error struct {
	Context string
	Error   error
}

Error contains slightly more verbosity than a standard "error".

type Errors

type Errors []Error

Errors is a slice of Errors.

type Image

type Image struct {
	ImageName ImageName `yaml:"name"`
	Dmap      DigestTags
}

Image holds information about an image. It's like an "Object" in the OOP sense, and holds all the information relating to a particular image that we care about.

type ImageDigest

type ImageDigest struct {
	ImageName ImageName
	Digest    Digest
}

ImageDigest is a combination of the ImageName and Digest.

type ImageDigestTag

type ImageDigestTag struct {
	ImageName ImageName
	Digest    Digest
	Tag       Tag
}

ImageDigestTag is a flattened key used by RegInvFlat.

type ImageName

type ImageName string

The ImageName can be just the bare name itself (e.g., "addon-builder" in "gcr.io/k8s-image-staging/addon-builder") or the prefix + name ("foo/bar/baz/quux" in "gcr.io/hello/foo/bar/baz/quux").

type ImageTag

type ImageTag struct {
	ImageName ImageName
	Tag       Tag
}

ImageTag is a combination of the ImageName and Tag.

type Manifest

type Manifest struct {
	// Registries contains the source and destination (Src/Dest) registry names.
	// It is possible that in the future, we support promoting to multiple
	// registries, in which case we would have more than just Src/Dest.
	Registries []RegistryContext
	// Src contains the RegistryName which will be set as the source registry.
	// All other registries in Registries will be treated as destination
	// registries.
	//
	// TODO: check that RegistryName is present in a RegistryContext in
	// Registries.
	SrcRegistry RegistryName `yaml:"src-registry"`
	Images      []Image      `yaml:"images,omitempty"`
}

Manifest stores the information in a manifest file (describing the desired state of a Docker Registry).

func ParseManifest

func ParseManifest(bytes []byte) (Manifest, error)

ParseManifest parses a Manifest from a byteslice. This function is separate from ParseManifestFromFile() so that it can be tested independently.

func ParseManifestFromFile

func ParseManifestFromFile(filePath string) (Manifest, error)

ParseManifestFromFile parses a Manifest from a filepath.

func (Manifest) ToRegInvImageDigest

func (m Manifest) ToRegInvImageDigest() RegInvImageDigest

ToRegInvImageDigest converts a Manifest to a RegInvImageDigest.

func (Manifest) ToRegInvImageTag

func (m Manifest) ToRegInvImageTag() RegInvImageTag

ToRegInvImageTag converts a Manifest to a RegInvImageTag.

func (Manifest) Validate

func (m Manifest) Validate() error

Validate checks for semantic errors in the yaml fields (the structure of the yaml is checked during unmarshaling).

type MasterInventory

type MasterInventory map[RegistryName]RegInvImage

MasterInventory stores multiple RegInvImage elements, keyed by RegistryName.

func (*MasterInventory) PrettyValue

func (mi *MasterInventory) PrettyValue() string

PrettyValue creates a prettified string representation of MasterInventory.

type PopulateRequests

type PopulateRequests func(*SyncContext, chan<- stream.ExternalRequest)

PopulateRequests is a function that can generate requests used to fetch information about a Docker Registry, or to promote images. It basically generates the set of "gcloud ..." commands used to manipulate Docker Registries.

type ProcessRequest

type ProcessRequest func(
	*SyncContext,
	<-chan stream.ExternalRequest,
	chan<- RequestResult,
	*sync.WaitGroup,
	*sync.Mutex)

ProcessRequest is the counterpart to PopulateRequests. It is a function that can take a request (generated by PopulateRequests) and process it. In the ictual implementation (e.g. in ReadDigestsAndTags()) it closes over some other local variables to record the change of state in the Docker Registry that was touched by processing the request.

func MkRequestCapturer

func MkRequestCapturer(captured *CapturedRequests) ProcessRequest

MkRequestCapturer returns a function that simply records requests as they are captured (slured out from the reqs channel).

type PromotionRequest

type PromotionRequest struct {
	TagOp          TagOp
	RegistrySrc    RegistryName
	RegistryDest   RegistryName
	ServiceAccount string
	ImageName      ImageName
	Digest         Digest
	DigestOld      Digest // Only for tag moves.
	Tag            Tag
}

PromotionRequest contains all the information required for any type of promotion (or demotion!) (involving any TagOp).

func (*PromotionRequest) PrettyValue

func (pr *PromotionRequest) PrettyValue() string

PrettyValue is a prettified string representation of a PromotionRequest.

type RegInvFlat

type RegInvFlat map[ImageDigestTag]interface{}

RegInvFlat is a flattened view of a Docker Registry, where the keys contain all 3 attributes --- the image name, digest, and tag.

func (RegInvFlat) ToSet

func (a RegInvFlat) ToSet() container.Set

ToSet converts a RegInvFlat to a Set.

type RegInvImage

type RegInvImage map[ImageName]DigestTags

A RegInvImage is a map containing all of the image names, and their associated digest-to-tags mappings. It is the simplest view of a Docker Registry, because the keys are just the ImageNames (where each ImageName does *not* include the registry name, because we already key this by the RegistryName in MasterInventory).

func (RegInvImage) Minus

func (a RegInvImage) Minus(b RegInvImage) RegInvImage

Minus is a set operation.

func (RegInvImage) ToRegInvImageDigest

func (ri RegInvImage) ToRegInvImageDigest() RegInvImageDigest

ToRegInvImageDigest takes a RegInvImage and converts it to a RegInvImageDigest.

func (RegInvImage) ToRegInvImageTag

func (ri RegInvImage) ToRegInvImageTag() RegInvImageTag

ToRegInvImageTag converts a RegInvImage to a RegInvImageTag.

func (RegInvImage) ToSet

func (a RegInvImage) ToSet() container.Set

ToSet converts a RegInvImage to a Set.

func (RegInvImage) Union

func (a RegInvImage) Union(b RegInvImage) RegInvImage

Union is a set operation.

type RegInvImageDigest

type RegInvImageDigest map[ImageDigest]TagSlice

RegInvImageDigest is a view of a Docker Reqistry, keyed by ImageDigest.

func (RegInvImageDigest) Intersection

Intersection is a set operation.

func (RegInvImageDigest) Minus

Minus is a set operation.

func (*RegInvImageDigest) PrettyValue

func (riid *RegInvImageDigest) PrettyValue() string

PrettyValue converts a RegInvImageDigest to a prettified string representation.

func (RegInvImageDigest) ToRegInvImageTag

func (riid RegInvImageDigest) ToRegInvImageTag() RegInvImageTag

ToRegInvImageTag converts a RegInvImageDigest to a RegInvImageTag.

func (RegInvImageDigest) ToSet

func (a RegInvImageDigest) ToSet() container.Set

ToSet converts a RegInvFlat to a Set.

type RegInvImageTag

type RegInvImageTag map[ImageTag]Digest

RegInvImageTag is keyed by a ImageTag.

func (RegInvImageTag) Intersection

func (a RegInvImageTag) Intersection(b RegInvImageTag) RegInvImageTag

Intersection is a set operation.

func (RegInvImageTag) Minus

Minus is a set operation.

func (RegInvImageTag) ToSet

func (a RegInvImageTag) ToSet() container.Set

ToSet converts a RegInvImageTag to a Set.

type Registry

type Registry struct {
	RegistryName      string
	RegistryNameLong  RegistryName
	RegInvImageDigest RegInvImageDigest
}

Registry is another way to look at a Docker Registry; it is used during Promotion.

func (*Registry) PrettyValue

func (r *Registry) PrettyValue() string

PrettyValue converts a Registry to a prettified string representation.

type RegistryContext

type RegistryContext struct {
	Name           RegistryName
	ServiceAccount string `yaml:"service-account,omitempty"`
}

RegistryContext holds information about a registry, to be written in a manifest file.

type RegistryName

type RegistryName string

RegistryName is the leading part of an image name that includes the domain; it is everything that is not the actual image name itself. E.g., "gcr.io/google-containers".

type RequestResult

type RequestResult struct {
	Context stream.ExternalRequest
	Errors  Errors
}

RequestResult contains information about the result of running a request (e.g., a "gcloud" command, or perhaps in the future, a REST call).

type SyncContext

type SyncContext struct {
	ManifestPath      string
	Verbosity         int
	Threads           int
	DeleteExtraTags   bool
	DryRun            bool
	UseServiceAccount bool
	Inv               MasterInventory
	RegistryContexts  []RegistryContext
}

SyncContext is the main data structure for performing the promotion.

func MakeSyncContext

func MakeSyncContext(
	manifestPath string,
	mi MasterInventory,
	verbosity, threads int,
	deleteExtraTags, dryRun, useSvcAcc bool,
	rcs []RegistryContext) SyncContext

MakeSyncContext creates a SyncContext.

func (*SyncContext) Error

func (sc *SyncContext) Error(v ...interface{})

Error logs at ERROR level.

func (*SyncContext) Errorf

func (sc *SyncContext) Errorf(s string, v ...interface{})

Errorf logs at ERROR level.

func (*SyncContext) ExecRequests

func (sc *SyncContext) ExecRequests(
	populateRequests PopulateRequests,
	processRequest ProcessRequest)

ExecRequests uses the Worker Pool pattern, where MaxConcurrentRequests determines the number of workers to spawn.

func (*SyncContext) Fatal

func (sc *SyncContext) Fatal(v ...interface{})

Fatal logs at FATAL level.

func (*SyncContext) Fatalf

func (sc *SyncContext) Fatalf(s string, v ...interface{})

Fatalf logs at FATAL level.

func (*SyncContext) GarbageCollect

func (sc *SyncContext) GarbageCollect(
	mfest Manifest,
	mkProducer func(RegistryContext, ImageName, Digest) stream.Producer,
	customProcessRequest *ProcessRequest)

GarbageCollect deletes all images that are not referenced by Docker tags. nolint[gocyclo]

func (*SyncContext) GetLostImages added in v1.0.1

func (sc *SyncContext) GetLostImages(mfest Manifest) RegInvImageDigest

GetLostImages gets all images in Manifest which are missing from src, and also logs them in the process.

func (*SyncContext) GetPromotionCandidatesIT

func (sc *SyncContext) GetPromotionCandidatesIT(
	mfest Manifest) RegInvImageTag

GetPromotionCandidatesIT returns those images that are due for promotion.

func (*SyncContext) Info

func (sc *SyncContext) Info(v ...interface{})

Info logs at INFO level.

func (*SyncContext) Infof

func (sc *SyncContext) Infof(s string, v ...interface{})

Infof logs at INFO level.

func (*SyncContext) PrintCapturedRequests

func (sc *SyncContext) PrintCapturedRequests(capReqs *CapturedRequests)

PrintCapturedRequests pretty-prints all given PromotionRequests.

func (*SyncContext) Promote

func (sc *SyncContext) Promote(
	mfest Manifest,
	mkProducer func(
		RegistryName,
		RegistryContext,
		ImageName,
		Digest,
		Tag,
		TagOp) stream.Producer,
	customProcessRequest *ProcessRequest) int

Promote perferms container image promotion by realizing the intent in the Manifest.

func (*SyncContext) ReadDigestsAndTags

func (sc *SyncContext) ReadDigestsAndTags(
	mkProducer func(RegistryContext, ImageName) stream.Producer)

ReadDigestsAndTags runs `gcloud container images list-tags gcr.io/louhi-gke-k8s/etcd --format=json` For each image name, retrieve all digests and corresponding tags (if any).

func (*SyncContext) ReadImageNames

func (sc *SyncContext) ReadImageNames(
	mkProducer func(RegistryContext) stream.Producer)

ReadImageNames only works for streams that interpret json.

func (*SyncContext) Warn

func (sc *SyncContext) Warn(v ...interface{})

Warn logs at WARN level.

func (*SyncContext) Warnf

func (sc *SyncContext) Warnf(s string, v ...interface{})

Warnf logs at WARN level.

type Tag

type Tag string

Tag is a Docker tag.

type TagOp

type TagOp int

TagOp is an enum that describes the various types of tag-modifying operations. These actions are a bit more low-level, and currently support 3 operations: adding, moving, and deleting.

func (*TagOp) PrettyValue

func (op *TagOp) PrettyValue() string

PrettyValue is a prettified string representation of a TagOp.

type TagSet

type TagSet map[Tag]interface{}

TagSet is a set of Tags.

func (TagSet) Intersection

func (a TagSet) Intersection(b TagSet) TagSet

Intersection is a set operation.

func (TagSet) Minus

func (a TagSet) Minus(b TagSet) TagSet

Minus is a set operation.

func (TagSet) ToSet

func (a TagSet) ToSet() container.Set

ToSet converts a TagSet to a Set.

func (TagSet) Union

func (a TagSet) Union(b TagSet) TagSet

Union is a set operation.

type TagSlice

type TagSlice []Tag

TagSlice is a slice of Tags.

func (TagSlice) Intersection

func (a TagSlice) Intersection(b TagSlice) TagSet

Intersection is a set operation.

func (TagSlice) Minus

func (a TagSlice) Minus(b TagSlice) TagSet

Minus is a set operation.

func (TagSlice) ToTagSet

func (a TagSlice) ToTagSet() TagSet

ToTagSet converts a TagSlice to a TagSet.

func (TagSlice) Union

func (a TagSlice) Union(b TagSlice) TagSet

Union is a set operation.

Jump to

Keyboard shortcuts

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