Documentation ¶
Index ¶
- Constants
- func CheckPersistentVolumeClaimModeBlock(pvc *corev1.PersistentVolumeClaim) bool
- func MakeNestedMountpoints(name, baseDir string, pod corev1.Pod) error
- func VisitContainers(podSpec *corev1.PodSpec, mask ContainerType, visitor ContainerVisitor) bool
- type AtomicWriter
- type ContainerType
- type ContainerVisitor
- type FileProjection
Constants ¶
const AllContainers = InitContainers | Containers | EphemeralContainers
AllContainers specifies that all containers be visited
Variables ¶
This section is empty.
Functions ¶
func CheckPersistentVolumeClaimModeBlock ¶
func CheckPersistentVolumeClaimModeBlock(pvc *corev1.PersistentVolumeClaim) bool
CheckPersistentVolumeClaimModeBlock checks VolumeMode. If the mode is Block, return true otherwise return false.
func MakeNestedMountpoints ¶
MakeNestedMountpoints creates mount points in baseDir for volumes mounted beneath name
func VisitContainers ¶
func VisitContainers(podSpec *corev1.PodSpec, mask ContainerType, visitor ContainerVisitor) bool
VisitContainers invokes the visitor function with a pointer to every container spec in the given pod spec with type set in mask. If visitor returns false, visiting is short-circuited. VisitContainers returns true if visiting completes, false if visiting was short-circuited.
Types ¶
type AtomicWriter ¶
type AtomicWriter struct {
// contains filtered or unexported fields
}
AtomicWriter handles atomically projecting content for a set of files into a target directory.
Note:
- AtomicWriter reserves the set of pathnames starting with `..`.
- AtomicWriter offers no concurrency guarantees and must be synchronized by the caller.
The visible files in this volume are symlinks to files in the writer's data directory. Actual files are stored in a hidden timestamped directory which is symlinked to by the data directory. The timestamped directory and data directory symlink are created in the writer's target dir. This scheme allows the files to be atomically updated by changing the target of the data directory symlink.
Consumers of the target directory can monitor the ..data symlink using inotify or fanotify to receive events when the content in the volume is updated.
func NewAtomicWriter ¶
func NewAtomicWriter(targetDir string, logContext string) (*AtomicWriter, error)
NewAtomicWriter creates a new AtomicWriter configured to write to the given target directory, or returns an error if the target directory does not exist.
func (*AtomicWriter) Write ¶
func (w *AtomicWriter) Write(payload map[string]FileProjection) error
Write does an atomic projection of the given payload into the writer's target directory. Input paths must not begin with '..'.
The Write algorithm is:
The payload is validated; if the payload is invalid, the function returns
The current timestamped directory is detected by reading the data directory symlink
The old version of the volume is walked to determine whether any portion of the payload was deleted and is still present on disk.
The data in the current timestamped directory is compared to the projected data to determine if an update is required.
A new timestamped dir is created
The payload is written to the new timestamped directory
A symlink to the new timestamped directory ..data_tmp is created that will become the new data directory
The new data directory symlink is renamed to the data directory; rename is atomic
Symlinks and directory for new user-visible files are created (if needed).
For example, consider the files: <target-dir>/podName <target-dir>/user/labels <target-dir>/k8s/annotations
The user visible files are symbolic links into the internal data directory: <target-dir>/podName -> ..data/podName <target-dir>/usr -> ..data/usr <target-dir>/k8s -> ..data/k8s
The data directory itself is a link to a timestamped directory with the real data: <target-dir>/..data -> ..2016_02_01_15_04_05.12345678/ NOTE(claudiub): We need to create these symlinks AFTER we've finished creating and linking everything else. On Windows, if a target does not exist, the created symlink will not work properly if the target ends up being a directory.
10. Old paths are removed from the user-visible portion of the target directory 11. The previous timestamped directory is removed, if it exists
type ContainerType ¶
type ContainerType int
ContainerType signifies container type
const ( // Containers is for normal containers Containers ContainerType = 1 << iota // InitContainers is for init containers InitContainers // EphemeralContainers is for ephemeral containers EphemeralContainers )
func AllFeatureEnabledContainers ¶
func AllFeatureEnabledContainers() ContainerType
AllFeatureEnabledContainers returns a ContainerType mask which includes all container types except for the ones guarded by feature gate.
type ContainerVisitor ¶
type ContainerVisitor func(container *corev1.Container, containerType ContainerType) (shouldContinue bool)
ContainerVisitor is called with each container spec, and returns true if visiting should continue.
type FileProjection ¶
FileProjection contains file Data and access Mode