Documentation ¶
Overview ¶
Package storage provides helper functions for creating and managing CRI pod sandboxes and containers and metadata associated with them in the format that crio understands. The API it provides should be considered to be unstable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // NameRegexp is the format for the name component of references. The // regexp has capturing groups for the domain and name part omitting // the separating forward slash from either. NameRegexp = expression( optional(domainRegexp, literal(`/`)), nameComponentRegexp, optional(repeated(literal(`/`), nameComponentRegexp))) // IdentifierRegexp is the format for string identifier used as a // content addressable identifier using sha256. These identifiers // are like digests without the algorithm, since sha256 is used. IdentifierRegexp = match(`([a-f0-9]{64})`) // ShortIdentifierRegexp is the format used to represent a prefix // of an identifier. A prefix may be used to match a sha256 identifier // within a list of trusted identifiers. ShortIdentifierRegexp = match(`([a-f0-9]{6,64})`) )
var ( // ErrInvalidPodName is returned when a pod name specified to a // function call is found to be invalid (most often, because it's // empty). ErrInvalidPodName = errors.New("invalid pod name") // ErrInvalidImageName is returned when an image name specified to a // function call is found to be invalid (most often, because it's // empty). ErrInvalidImageName = errors.New("invalid image name") // ErrInvalidContainerName is returned when a container name specified // to a function call is found to be invalid (most often, because it's // empty). ErrInvalidContainerName = errors.New("invalid container name") // ErrInvalidSandboxID is returned when a sandbox ID specified to a // function call is found to be invalid (because it's either // empty or doesn't match a valid sandbox). ErrInvalidSandboxID = errors.New("invalid sandbox ID") // ErrInvalidContainerID is returned when a container ID specified to a // function call is found to be invalid (because it's either // empty or doesn't match a valid container). ErrInvalidContainerID = errors.New("invalid container ID") )
Functions ¶
This section is empty.
Types ¶
type ContainerInfo ¶
ContainerInfo wraps a subset of information about a container: its ID and the locations of its nonvolatile and volatile per-container directories, along with a copy of the configuration blob from the image that was used to create the container, if the image had a configuration.
type ImageResult ¶
type ImageResult struct { ID string Names []string Size *uint64 // TODO(runcom): this is an hack for https://github.com/kubernetes-incubator/cri-o/pull/1136 // drop this when we have proper image IDs (as in, image IDs should be just // the config blog digest which is stable across same images). ConfigDigest digest.Digest }
ImageResult wraps a subset of information about an image: its ID, its names, and the size, if known, or nil if it isn't.
type ImageServer ¶
type ImageServer interface { // ListImages returns list of all images which match the filter. ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error) // ImageStatus returns status of an image which matches the filter. ImageStatus(systemContext *types.SystemContext, filter string) (*ImageResult, error) // PrepareImage returns an Image where the config digest can be grabbed // for further analysis. Call Close() on the resulting image. PrepareImage(systemContext *types.SystemContext, imageName string, options *copy.Options) (types.Image, error) // PullImage imports an image from the specified location. PullImage(systemContext *types.SystemContext, imageName string, options *copy.Options) (types.ImageReference, error) // RemoveImage deletes the specified image. RemoveImage(systemContext *types.SystemContext, imageName string) error // GetStore returns the reference to the storage library Store which // the image server uses to hold images, and is the destination used // when it's asked to pull an image. GetStore() storage.Store // CanPull preliminary checks whether we're allowed to pull an image CanPull(imageName string, options *copy.Options) (bool, error) // ResolveNames takes an image reference and if it's unqualified (w/o hostname), // it uses crio's default registries to qualify it. ResolveNames(imageName string) ([]string, error) }
ImageServer wraps up various CRI-related activities into a reusable implementation.
func GetImageService ¶
func GetImageService(store storage.Store, defaultTransport string, insecureRegistries []string, registries []string) (ImageServer, error)
GetImageService returns an ImageServer that uses the passed-in store, and which will prepend the passed-in defaultTransport value to an image name if a name that's passed to its PullImage() method can't be resolved to an image in the store and can't be resolved to a source on its own.
type RuntimeContainerMetadata ¶
type RuntimeContainerMetadata struct { // Pod is true if this is the pod's infrastructure container. Pod bool `json:"pod,omitempty"` // Applicable to both PodSandboxes and Containers // The pod's name and ID, kept for use by upper layers in determining // which containers belong to which pods. PodName string `json:"pod-name"` // Applicable to both PodSandboxes and Containers, mandatory PodID string `json:"pod-id"` // Applicable to both PodSandboxes and Containers, mandatory // The provided name and the ID of the image that was used to // instantiate the container. ImageName string `json:"image-name"` // Applicable to both PodSandboxes and Containers ImageID string `json:"image-id"` // Applicable to both PodSandboxes and Containers // The container's name, which for an infrastructure container is usually PodName + "-infra". ContainerName string `json:"name"` // Applicable to both PodSandboxes and Containers, mandatory // The name as originally specified in PodSandbox or Container CRI metadata. MetadataName string `json:"metadata-name"` // Applicable to both PodSandboxes and Containers, mandatory UID string `json:"uid,omitempty"` // Only applicable to pods Namespace string `json:"namespace,omitempty"` // Only applicable to pods Attempt uint32 `json:"attempt,omitempty"` // Applicable to both PodSandboxes and Containers CreatedAt int64 `json:"created-at"` // Applicable to both PodSandboxes and Containers MountLabel string `json:"mountlabel,omitempty"` // Applicable to both PodSandboxes and Containers }
RuntimeContainerMetadata is the structure that we encode as JSON and store in the metadata field of storage.Container objects. It is used for specifying attributes of pod sandboxes and containers when they are being created, and allows a container's MountLabel, and possibly other values, to be modified in one read/write cycle via calls to RuntimeServer.ContainerMetadata, RuntimeContainerMetadata.SetMountLabel, and RuntimeServer.SetContainerMetadata.
func (*RuntimeContainerMetadata) SetMountLabel ¶
func (metadata *RuntimeContainerMetadata) SetMountLabel(mountLabel string)
SetMountLabel updates the mount label held by a RuntimeContainerMetadata object.
type RuntimeServer ¶
type RuntimeServer interface { // CreatePodSandbox creates a pod infrastructure container, using the // specified PodID for the infrastructure container's ID. In the CRI // view of things, a sandbox is distinct from its containers, including // its infrastructure container, but at this level the sandbox is // essentially the same as its infrastructure container, with a // container's membership in a pod being signified by it listing the // same pod ID in its metadata that the pod's other members do, and // with the pod's infrastructure container having the same value for // both its pod's ID and its container ID. // Pointer arguments can be nil. Either the image name or ID can be // omitted, but not both. All other arguments are required. CreatePodSandbox(systemContext *types.SystemContext, podName, podID, imageName, imageID, containerName, metadataName, uid, namespace string, attempt uint32, copyOptions *copy.Options) (ContainerInfo, error) // RemovePodSandbox deletes a pod sandbox's infrastructure container. // The CRI expects that a sandbox can't be removed unless its only // container is its infrastructure container, but we don't enforce that // here, since we're just keeping track of it for higher level APIs. RemovePodSandbox(idOrName string) error // GetContainerMetadata returns the metadata we've stored for a container. GetContainerMetadata(idOrName string) (RuntimeContainerMetadata, error) // SetContainerMetadata updates the metadata we've stored for a container. SetContainerMetadata(idOrName string, metadata RuntimeContainerMetadata) error // CreateContainer creates a container with the specified ID. // Pointer arguments can be nil. Either the image name or ID can be // omitted, but not both. All other arguments are required. CreateContainer(systemContext *types.SystemContext, podName, podID, imageName, imageID, containerName, containerID, metadataName string, attempt uint32, mountLabel string, copyOptions *copy.Options) (ContainerInfo, error) // DeleteContainer deletes a container, unmounting it first if need be. DeleteContainer(idOrName string) error // StartContainer makes sure a container's filesystem is mounted, and // returns the location of its root filesystem, which is not guaranteed // by lower-level drivers to never change. StartContainer(idOrName string) (string, error) // StopContainer attempts to unmount a container's root filesystem, // freeing up any kernel resources which may be limited. StopContainer(idOrName string) error // GetWorkDir returns the path of a nonvolatile directory on the // filesystem (somewhere under the Store's Root directory) which can be // used to store arbitrary data that is specific to the container. It // will be removed automatically when the container is deleted. GetWorkDir(id string) (string, error) // GetRunDir returns the path of a volatile directory (does not survive // the host rebooting, somewhere under the Store's RunRoot directory) // on the filesystem which can be used to store arbitrary data that is // specific to the container. It will be removed automatically when // the container is deleted. GetRunDir(id string) (string, error) }
RuntimeServer wraps up various CRI-related activities into a reusable implementation.
func GetRuntimeService ¶
func GetRuntimeService(storageImageServer ImageServer, pauseImage string) RuntimeServer
GetRuntimeService returns a RuntimeServer that uses the passed-in image service to pull and manage images, and its store to manage containers based on those images.