Documentation
¶
Index ¶
- Constants
- Variables
- type ArchiveExtractor
- type Database
- func (db *Database) Close() error
- func (db *Database) GetLibraryForVolume(volumeID string) (string, error)
- func (db *Database) GetVolumeCount(libraryID string) (int, error)
- func (db *Database) LinkVolume(libraryID string, volumeID string) error
- func (db *Database) UnlinkVolume(libraryID string, volumeID string) error
- type Downloader
- type ImageCache
- type Library
- type LibraryManager
- type LibraryManagerOption
- type Locker
- type Store
Constants ¶
const ( // DatabaseFileName is the name of the database file created by bbolt. DatabaseFileName = "datadog-csi-driver.db" // LibraryMappingBucket is the name of the bucket to map libraries. Conceptually, the key structure is as follows: // /library-mappings/{{ library_id }}/{{ volume_id }} LibraryMappingBucket = "library-mappings" // VolumeMappingBucket is the bucket to map volumes. Conceptually, the key structure is as follows: // /volume-mappings/{{ volume_id }}/{{ library_id }} VolumeMappingBucket = "volume-mappings" )
const ( // StoreDirectory is the subdirectory where active libraries are stored. StoreDirectory = "store" // DatabaseDirectory is the subdirectory where the databse file will be stored. DatabaseDirectory = "db" // ScratchDirectory is the subdirectory used for scratch download space for libraries. ScratchDirectory = "scratch" // DefaultImageCacheTTL is the max amount of time before we fetch a new image digest. DefaultImageCacheTTL = 1 * time.Hour )
Variables ¶
var ErrItemNotFound = errors.New("item not found in store")
Functions ¶
This section is empty.
Types ¶
type ArchiveExtractor ¶
type ArchiveExtractor struct {
// contains filtered or unexported fields
}
ArchiveExtractor extracts directories from a tar archive.
func NewArchiveExtractor ¶
NewArchiveExtractor initializes a new archive extractor.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is a wrapper around bbolt with business logic for the library manager.
Transaction Consistency Guarantees ¶
bbolt provides serializable isolation, the highest level of transaction isolation:
- Write transactions are mutually exclusive (only one can run at a time)
- Read transactions see a consistent snapshot of the database at the time they started
- All operations within a single transaction are atomic (all-or-nothing)
The defer tx.Rollback() pattern is safe: if Commit() was already called, Rollback() is a no-op.
External Locking Requirements ¶
While individual database transactions are atomic, operations that span multiple transactions or combine database operations with filesystem operations (e.g., LinkVolume + store.Add) require external synchronization. The LibraryManager uses a Locker to coordinate these compound operations on a per-library basis.
func NewDatabase ¶
NewDatabase initializes a new database. If a database file exists, it will re-use the existing file. Call close when you are done.
func (*Database) GetLibraryForVolume ¶
GetLibraryForVolume returns the library mapped to a volume. A volume should only ever have one library mapped to it.
func (*Database) GetVolumeCount ¶
GetVolumeCount returns the number of volumes linked to a library.
func (*Database) LinkVolume ¶
LinkVolume creates a bidrectional mapping between the library and volume.
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader enables downloading and extracting directories from container images.
func NewDownloader ¶
func NewDownloader() *Downloader
NewDownloader creates a new downloader with the default settings.
func NewDownloaderWithRoundTripper ¶
func NewDownloaderWithRoundTripper(roundTripper http.RoundTripper) *Downloader
NewDownloaderWithRoundTripper creates a new downloader with the provided round tripper.
func (*Downloader) Download ¶
func (d *Downloader) Download(ctx context.Context, afs afero.Afero, image string, src string, dst string) error
Download will stream a container image and extract the source directory from inside of the image to the destination directory on disk.
func (*Downloader) FetchDigest ¶
FetchDigest will fetch a sha256 sum of the image and return it.
type ImageCache ¶
type ImageCache struct {
// contains filtered or unexported fields
}
ImageCache provides an in memory cache of container image digests so we don't have to resolve a container tag to sha256sum each time.
func NewImageCache ¶
func NewImageCache(d *Downloader, ttl time.Duration) *ImageCache
NewImageChace initializes a new, empty image cache.
func (*ImageCache) FetchDigest ¶
FetchDigest returns the sha256 digest for a container image, using the cache when possible.
The image parameter must be a valid container image reference as accepted by crane (https://pkg.go.dev/github.com/google/go-containerregistry/pkg/crane). Examples:
- "gcr.io/datadoghq/dd-lib-java-init:v1.2.3"
- "gcr.io/datadoghq/dd-lib-java-init@sha256:abc123..."
- "nginx:latest" (defaults to docker.io registry)
If the image already contains a digest (@sha256:...), this function will still resolve the full digest from the registry to ensure it exists and is valid.
If pull is true, the cache is bypassed and a fresh digest is always fetched from the registry. If pull is false, the cache is checked first and a remote call is only made on cache miss.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library represents a Datadog package to download and mount as part of a DatadogLibrary volume request.
func NewLibrary ¶
func NewLibrary(name string, registry string, version string, path string, pull bool) (*Library, error)
NewLibrary instatiates a new library from the provided fields and ensures they are valid.
type LibraryManager ¶
type LibraryManager struct {
// contains filtered or unexported fields
}
LibraryManager is a high level object to manage fetching libraries for volumes. It will download, extract, store, and track libraries and how they map to a volume.
func NewLibraryManager ¶
func NewLibraryManager(basePath string, opts ...LibraryManagerOption) (*LibraryManager, error)
NewLibraryManager creates a new library manager with all of the required dependencies. The basePath is required as an absolute path (rather than using afero.NewBasePathFs) because bind mounts need absolute paths.
func (*LibraryManager) GetLibraryForVolume ¶
func (lm *LibraryManager) GetLibraryForVolume(ctx context.Context, volumeID string, lib *Library) (string, error)
GetLibraryForVolume fetches the remote library if it doesn't exist, records its usage, and returns the path on disk that can be mounted for the volume.
func (*LibraryManager) RemoveVolume ¶
func (lm *LibraryManager) RemoveVolume(ctx context.Context, volumeID string) error
RemoveVolume removes the link between the LibraryID and the VolumeID in the database. If there are no more uses of the library, it is also removed from disk.
func (*LibraryManager) Stop ¶
func (lm *LibraryManager) Stop() error
Stop ensures all dependencies are stopped correctly.
type LibraryManagerOption ¶
type LibraryManagerOption func(*LibraryManager)
LibraryManagerOption is a functional option for configuring a LibraryManager.
func WithDownloader ¶
func WithDownloader(d *Downloader) LibraryManagerOption
WithDownloader sets the downloader to use. Useful for testing.
func WithFilesystem ¶
func WithFilesystem(fs afero.Afero) LibraryManagerOption
WithFilesystem sets the filesystem to use. Useful for testing.
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker is a sharded mutex to be able to perform concurrent operations on unrelated keys.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides a file based storage solution for packages. It is not thread safe and it is up to the caller to manage concurrency.
func (*Store) Add ¶
Add will move a source directory into the store. This is intended to be used with a downloader and scratch space. If a package already exists at the provided ID, it will not be re-added.