storage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultFileMode is the permission mode applied to files inside an artifact archive.
	DefaultFileMode int64 = 0o600
	// DefaultDirMode is the permission mode applied to all directories inside an artifact archive.
	DefaultDirMode int64 = 0o750
	// DefaultExeFileMode is the permission mode applied to executable files inside an artifact archive.
	DefaultExeFileMode int64 = 0o700
)
View Source
const GarbageCountLimit = 1000

Variables

This section is empty.

Functions

func ArtifactDir

func ArtifactDir(kind, namespace, name string) string

ArtifactDir returns the artifact dir path in the form of '<kind>/<namespace>/<name>'.

func ArtifactPath

func ArtifactPath(kind, namespace, name, filename string) string

ArtifactPath returns the artifact path in the form of '<kind>/<namespace>/name>/<filename>'.

Types

type ArchiveFileFilter

type ArchiveFileFilter func(p string, fi os.FileInfo) bool

ArchiveFileFilter must return true if a file should not be included in the archive after inspecting the given path and/or os.FileInfo.

func SourceIgnoreFilter

func SourceIgnoreFilter(ps []gitignore.Pattern, domain []string) ArchiveFileFilter

SourceIgnoreFilter returns an ArchiveFileFilter that filters out files matching sourceignore.VCSPatterns and any of the provided patterns. If an empty gitignore.Pattern slice is given, the matcher is set to sourceignore.NewDefaultMatcher.

type Storage

type Storage struct {
	// BasePath is the local directory path where the source artifacts are stored.
	BasePath string `json:"basePath"`

	// Hostname is the file server host name used to compose the artifacts URIs.
	Hostname string `json:"hostname"`

	// ArtifactRetentionTTL is the duration of time that artifacts will be kept
	// in storage before being garbage collected.
	ArtifactRetentionTTL time.Duration `json:"artifactRetentionTTL"`

	// ArtifactRetentionRecords is the maximum number of artifacts to be kept in
	// storage after a garbage collection.
	ArtifactRetentionRecords int `json:"artifactRetentionRecords"`
}

Storage manages meta.Artifact tarballs on the local filesystem. It provides methods for creating, verifying, and garbage collecting artifacts.

func New

func New(opts *config.Options) (*Storage, error)

New creates the storage helper using the provided configuration options.

func (Storage) Archive

func (s Storage) Archive(artifact *meta.Artifact, dir string, filter ArchiveFileFilter) (err error)

Archive atomically archives the given directory as a tarball to the given meta.Artifact path, excluding directories and any ArchiveFileFilter matches. While archiving, any environment specific data (for example, the user and group name) is stripped from file headers. If successful, it sets the digest and last update time on the artifact.

func (Storage) ArtifactExist

func (s Storage) ArtifactExist(artifact meta.Artifact) bool

ArtifactExist returns a boolean indicating whether the meta.Artifact exists in storage and is a regular file.

func (Storage) AtomicWriteFile

func (s Storage) AtomicWriteFile(artifact *meta.Artifact, reader io.Reader, mode os.FileMode) (err error)

AtomicWriteFile atomically writes the io.Reader contents to the meta.Artifact path. If successful, it sets the digest and last update time on the artifact.

func (Storage) Copy

func (s Storage) Copy(artifact *meta.Artifact, reader io.Reader) (err error)

Copy atomically copies the io.Reader contents to the meta.Artifact path. If successful, it sets the digest and last update time on the artifact.

func (Storage) CopyFromPath

func (s Storage) CopyFromPath(artifact *meta.Artifact, path string) (err error)

CopyFromPath atomically copies the contents of the given path to the path of the meta.Artifact. If successful, the digest and last update time on the artifact is set.

func (Storage) CopyToPath

func (s Storage) CopyToPath(artifact *meta.Artifact, subPath, toPath string) error

CopyToPath copies the contents in the (sub)path of the given artifact to the given path.

func (Storage) GarbageCollect

func (s Storage) GarbageCollect(ctx context.Context, artifact meta.Artifact, timeout time.Duration) ([]string, error)

GarbageCollect removes all garbage files in the artifact dir according to the provided retention options.

func (Storage) GetGarbageFiles

func (s Storage) GetGarbageFiles(artifact meta.Artifact,
	totalCountLimit, maxItemsToBeRetained int,
	ttl time.Duration) (garbageFiles []string, _ error)

GetGarbageFiles returns all files that need to be garbage collected for the given artifact. Garbage files are determined based on the below flow: 1. collect all artifact files with an expired ttl 2. if we satisfy maxItemsToBeRetained, then return 3. else, collect all artifact files till the latest n files remain, where n=maxItemsToBeRetained

func (Storage) LocalPath

func (s Storage) LocalPath(artifact meta.Artifact) string

LocalPath returns the secure local path of the given artifact (that is: relative to the Storage.BasePath).

func (Storage) Lock

func (s Storage) Lock(artifact meta.Artifact) (unlock func(), err error)

Lock creates a file lock for the given meta.Artifact.

func (Storage) MkdirAll

func (s Storage) MkdirAll(artifact meta.Artifact) error

MkdirAll calls os.MkdirAll for the given meta.Artifact base dir.

func (Storage) NewArtifactFor

func (s Storage) NewArtifactFor(kind string, metadata metav1.Object, revision, fileName string) meta.Artifact

NewArtifactFor returns a new meta.Artifact.

func (Storage) Remove

func (s Storage) Remove(artifact meta.Artifact) error

Remove calls os.Remove for the given meta.Artifact path.

func (Storage) RemoveAll

func (s Storage) RemoveAll(artifact meta.Artifact) (string, error)

RemoveAll calls os.RemoveAll for the given meta.Artifact base dir.

func (Storage) RemoveAllButCurrent

func (s Storage) RemoveAllButCurrent(artifact meta.Artifact) ([]string, error)

RemoveAllButCurrent removes all files for the given meta.Artifact base dir, excluding the current one.

func (Storage) SetArtifactURL

func (s Storage) SetArtifactURL(artifact *meta.Artifact)

SetArtifactURL sets the URL on the given meta.Artifact.

func (Storage) SetHostname

func (s Storage) SetHostname(URL string) string

SetHostname sets the hostname of the given URL string to the current Storage.Hostname and returns the result.

func (s Storage) Symlink(artifact meta.Artifact, linkName string) (string, error)

Symlink creates or updates a symbolic link for the given meta.Artifact and returns the URL for the symlink.

func (Storage) VerifyArtifact

func (s Storage) VerifyArtifact(artifact meta.Artifact) error

VerifyArtifact verifies if the Digest of the meta.Artifact matches the digest of the file in Storage. It returns an error if the digests don't match, or if it can't be verified.

Jump to

Keyboard shortcuts

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