storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const GarbageCountLimit = 1000

Variables

This section is empty.

Functions

func ArtifactURLBase

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

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

func HasDigest

func HasDigest(in *v1.Artifact, digest string) bool

HasDigest returns if the given digest matches the current Digest of the Artifact.

func HasRevision

func HasRevision(artifact *v1.Artifact, revision string) bool

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 Collectable

type Collectable interface {
	client.Object

	GetDeletionTimestamp() *metav1.Time
	GetObjectMeta() *metav1.ObjectMeta
	GetKind() string
}

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"`
	// contains filtered or unexported fields
}

Storage manages artifacts

func NewStorage

func NewStorage(client client.Client, scheme *runtime.Scheme, basePath string, hostname string, artifactRetentionTTL time.Duration, artifactRetentionRecords int) (*Storage, error)

NewStorage creates the storage helper for a given path and hostname.

func (*Storage) Archive

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

Archive atomically archives the given directory as a tarball to the given v1.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 *v1.Artifact) bool

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

func (*Storage) AtomicWriteFile

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

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

func (*Storage) Copy

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

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

func (*Storage) CopyFromPath

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

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

func (*Storage) CopyToPath

func (s *Storage) CopyToPath(artifact *v1.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 *v1.Artifact, timeout time.Duration) ([]string, error)

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

func (*Storage) LocalPath

func (s *Storage) LocalPath(artifact *v1.Artifact) string

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

func (*Storage) LocalPathFromURL

func (s *Storage) LocalPathFromURL(artifact *v1.Artifact) string

LocalPathFromURL returns the local path on the file-system given the URL of the artifact.

func (*Storage) Lock

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

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

func (*Storage) MkdirAll

func (s *Storage) MkdirAll(artifact *v1.Artifact) error

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

func (*Storage) NewArtifactFor

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

NewArtifactFor returns a new v1.Artifact.

func (*Storage) ReconcileArtifact

func (s *Storage) ReconcileArtifact(ctx context.Context, obj Collectable, revision, dir, filename string, archiveFunc func(*v1.Artifact, string) error) error

func (*Storage) ReconcileStorage

func (s *Storage) ReconcileStorage(ctx context.Context, obj Collectable) error

ReconcileStorage will do the following actions: - garbage collect old files - verify digest if the artifact does exist ( remove it if the digest doesn't match ) - set the url of the artifact.

func (*Storage) Remove

func (s *Storage) Remove(artifact *v1.Artifact) error

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

func (*Storage) RemoveAll

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

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

func (*Storage) RemoveAllButCurrent

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

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

func (*Storage) SetArtifactURL

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

SetArtifactURL sets the URL on the given v1.Artifact. URL needs to include the location of the file.

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 *v1.Artifact, linkName string) (string, error)

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

func (*Storage) VerifyArtifact

func (s *Storage) VerifyArtifact(artifact *v1.Artifact) error

VerifyArtifact verifies if the Digest of the v1.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.

type Storer

type Storer interface {
	// ReconcileStorage is responsible for setting up Storage data like URLs.
	ReconcileStorage(ctx context.Context, obj Collectable) error
	ReconcileArtifact(ctx context.Context, obj Collectable, revision, dir, hash string, archiveFunc func(*v1.Artifact, string) error) error
}

Jump to

Keyboard shortcuts

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