fileutil

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fileutil includes helpers for dealing with CSI mount paths and reading/writing files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMountedFiles

func GetMountedFiles(targetPath string) (map[string]string, error)

GetMountedFiles returns all the mounted files mapping their path relative to targetPath to the absolute paths.

This will filter out files by atomic_writer (which reserves file prefixed `..` and follows the symlinks created by atomic_writer).

func GetPodUIDFromTargetPath added in v0.0.17

func GetPodUIDFromTargetPath(targetPath string) string

GetPodUIDFromTargetPath returns podUID from targetPath

func GetVolumeNameFromTargetPath added in v0.0.17

func GetVolumeNameFromTargetPath(targetPath string) string

GetVolumeNameFromTargetPath returns volumeName from targetPath

func Validate added in v0.0.21

func Validate(payloads []*v1alpha1.File) error

Validate ensures the payload file paths are well formatted.

func WritePayloads added in v0.0.21

func WritePayloads(path string, payloads []*v1alpha1.File) error

WritePayloads writes the files to target directory. This helper builds the atomic writer and converts the v1alpha1.File proto to the FileProjection type used by the atomic writer.

Types

type AtomicWriter added in v0.0.22

type AtomicWriter struct {
	// contains filtered or unexported fields
}

AtomicWriter handles atomically projecting content for a set of files into a target directory.

Note:

  1. AtomicWriter reserves the set of pathnames starting with `..`.
  2. 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 added in v0.0.22

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 added in v0.0.22

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:

  1. The payload is validated; if the payload is invalid, the function returns

  2. The current timestamped directory is detected by reading the data directory symlink

  3. The old version of the volume is walked to determine whether any portion of the payload was deleted and is still present on disk.

  4. The data in the current timestamped directory is compared to the projected data to determine if an update is required.

  5. A new timestamped dir is created

  6. The payload is written to the new timestamped directory

  7. 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/

  8. A symlink to the new timestamped directory ..data_tmp is created that will become the new data directory

  9. The new data directory symlink is renamed to the data directory; rename is atomic

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 FileProjection added in v0.0.22

type FileProjection struct {
	Data   []byte
	Mode   int32
	FsUser *int64
}

FileProjection contains file Data and access Mode

Jump to

Keyboard shortcuts

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