repository

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoChartIndex = errors.New("no chart index")

Functions

func NormalizeURL

func NormalizeURL(repositoryURL string) string

NormalizeURL normalizes a ChartRepository URL by its scheme.

func ValidateDepURL added in v0.25.10

func ValidateDepURL(repositoryURL string) error

ValidateDepURL returns an error if the given depended repository URL declaration is not supported The reason for this is that the dependency manager will not be able to resolve the alias declaration e.g. repository: "@fantastic-charts"

Types

type ChartRepository

type ChartRepository struct {
	// URL the ChartRepository's index.yaml can be found at,
	// without the index.yaml suffix.
	URL string
	// Client to use while downloading the Index or a chart from the URL.
	Client getter.Getter
	// Options to configure the Client with while downloading the Index
	// or a chart from the URL.
	Options []getter.Option
	// CachePath is the path of a cached index.yaml for read-only operations.
	CachePath string
	// Cached indicates if the ChartRepository index.yaml has been cached
	// to CachePath.
	Cached bool
	// Index contains a loaded chart repository index if not nil.
	Index *repo.IndexFile
	// Checksum contains the SHA256 checksum of the loaded chart repository
	// index bytes. This is different from the checksum of the CachePath, which
	// may contain unordered entries.
	Checksum string

	*sync.RWMutex
	// contains filtered or unexported fields
}

ChartRepository represents a Helm chart repository, and the configuration required to download the chart index and charts from the repository. All methods are thread safe unless defined otherwise.

func NewChartRepository

func NewChartRepository(repositoryURL, cachePath string, providers getter.Providers, tlsConfig *tls.Config, getterOpts []getter.Option, chartRepoOpts ...ChartRepositoryOption) (*ChartRepository, error)

NewChartRepository constructs and returns a new ChartRepository with the ChartRepository.Client configured to the getter.Getter for the repository URL scheme. It returns an error on URL parsing failures, or if there is no getter available for the scheme.

func (*ChartRepository) CacheIndex

func (r *ChartRepository) CacheIndex() (string, error)

CacheIndex attempts to write the index from the remote into a new temporary file using DownloadIndex, and sets CachePath and Cached. It returns the SHA256 checksum of the downloaded index bytes, or an error. The caller is expected to handle the garbage collection of CachePath, and to load the Index separately using LoadFromCache if required.

func (*ChartRepository) CacheIndexInMemory added in v0.24.0

func (r *ChartRepository) CacheIndexInMemory() error

CacheIndexInMemory attempts to cache the index in memory. It returns an error if it fails. The cache key have to be safe in multi-tenancy environments, as otherwise it could be used as a vector to bypass the helm repository's authentication.

func (*ChartRepository) Clear added in v0.26.0

func (r *ChartRepository) Clear() error

Clear caches the index in memory before unloading it. It cleans up temporary files and directories created by the repository.

func (*ChartRepository) DownloadChart

func (r *ChartRepository) DownloadChart(chart *repo.ChartVersion) (*bytes.Buffer, error)

DownloadChart confirms the given repo.ChartVersion has a downloadable URL, and then attempts to download the chart using the Client and Options of the ChartRepository. It returns a bytes.Buffer containing the chart data.

func (*ChartRepository) DownloadIndex

func (r *ChartRepository) DownloadIndex(w io.Writer) (err error)

DownloadIndex attempts to download the chart repository index using the Client and set Options, and writes the index to the given io.Writer. It returns an url.Error if the URL failed to parse.

func (*ChartRepository) GetChartVersion added in v0.26.0

func (r *ChartRepository) GetChartVersion(name, ver string) (*repo.ChartVersion, error)

GetChartVersion returns the repo.ChartVersion for the given name, the version is expected to be a semver.Constraints compatible string. If version is empty, the latest stable version will be returned and prerelease versions will be ignored.

func (*ChartRepository) HasCacheFile

func (r *ChartRepository) HasCacheFile() bool

HasCacheFile returns true if CachePath is not empty.

func (*ChartRepository) HasIndex

func (r *ChartRepository) HasIndex() bool

HasIndex returns true if the Index is not nil.

func (*ChartRepository) LoadFromCache

func (r *ChartRepository) LoadFromCache() error

LoadFromCache attempts to load the Index from the configured CachePath. It returns an error if no CachePath is set, or if the load failed.

func (*ChartRepository) LoadFromFile

func (r *ChartRepository) LoadFromFile(path string) error

LoadFromFile reads the file at the given path and loads it into Index.

func (*ChartRepository) LoadFromMemCache added in v0.24.0

func (r *ChartRepository) LoadFromMemCache() bool

LoadFromMemCache attempts to load the Index from the provided cache. It returns true if the Index was found in the cache, and false otherwise.

func (*ChartRepository) LoadIndexFromBytes

func (r *ChartRepository) LoadIndexFromBytes(b []byte) error

LoadIndexFromBytes loads Index from the given bytes. It returns a repo.ErrNoAPIVersion error if the API version is not set

func (*ChartRepository) RemoveCache

func (r *ChartRepository) RemoveCache() error

RemoveCache removes the CachePath if Cached.

func (*ChartRepository) SetMemCache added in v0.24.0

func (r *ChartRepository) SetMemCache(key string, c *cache.Cache, ttl time.Duration, rec RecordMetricsFunc)

SetMemCache sets the cache to use for this repository.

func (*ChartRepository) StrategicallyLoadIndex

func (r *ChartRepository) StrategicallyLoadIndex() (err error)

StrategicallyLoadIndex lazy-loads the Index first from Indexcache, then from CachePath using oadFromCache if it does not HasIndex. If not HasCacheFile, a cache attempt is made using CacheIndex before continuing to load.

func (*ChartRepository) Unload

func (r *ChartRepository) Unload()

Unload can be used to signal the Go garbage collector the Index can be freed from memory if the ChartRepository object is expected to continue to exist in the stack for some time.

type ChartRepositoryOption added in v0.24.0

type ChartRepositoryOption func(*ChartRepository) error

ChartRepositoryOption is a function that can be passed to NewChartRepository to configure a ChartRepository.

func WithMemoryCache added in v0.24.0

func WithMemoryCache(key string, c *cache.Cache, ttl time.Duration, rec RecordMetricsFunc) ChartRepositoryOption

WithMemoryCache returns a ChartRepositoryOptions that will enable the ChartRepository to cache the index.yaml file in memory. The cache key have to be safe in multi-tenancy environments, as otherwise it could be used as a vector to bypass the helm repository's authentication.

type Downloader added in v0.26.0

type Downloader interface {
	// GetChartVersion returns the repo.ChartVersion for the given name and version
	// from the remote Helm repository or OCI Helm repository.
	GetChartVersion(name, version string) (*repo.ChartVersion, error)
	// DownloadChart downloads a chart from the remote Helm repository or OCI Helm repository.
	DownloadChart(chart *repo.ChartVersion) (*bytes.Buffer, error)
	// Clear removes all temporary files created by the downloader, caching the files if the cache is configured,
	// and calling garbage collector to remove unused files.
	Clear() error
}

Downloader is used to download a chart from a remote Helm repository or OCI Helm repository.

type OCIChartRepository added in v0.25.0

type OCIChartRepository struct {
	// URL is the location of the repository.
	URL url.URL
	// Client to use while accessing the repository's contents.
	Client getter.Getter
	// Options to configure the Client with while downloading tags
	// or a chart from the URL.
	Options []getter.Option

	// RegistryClient is a client to use while downloading tags or charts from a registry.
	RegistryClient RegistryClient
	// contains filtered or unexported fields
}

OCIChartRepository represents a Helm chart repository, and the configuration required to download the repository tags and charts from the repository. All methods are thread safe unless defined otherwise.

func NewOCIChartRepository added in v0.25.0

func NewOCIChartRepository(repositoryURL string, chartRepoOpts ...OCIChartRepositoryOption) (*OCIChartRepository, error)

NewOCIChartRepository constructs and returns a new ChartRepository with the ChartRepository.Client configured to the getter.Getter for the repository URL scheme. It returns an error on URL parsing failures. It assumes that the url scheme has been validated to be an OCI scheme.

func (*OCIChartRepository) Clear added in v0.26.0

func (r *OCIChartRepository) Clear() error

Clear deletes the OCI registry credentials file.

func (*OCIChartRepository) DownloadChart added in v0.25.0

func (r *OCIChartRepository) DownloadChart(chart *repo.ChartVersion) (*bytes.Buffer, error)

DownloadChart confirms the given repo.ChartVersion has a downloadable URL, and then attempts to download the chart using the Client and Options of the ChartRepository. It returns a bytes.Buffer containing the chart data. In case of an OCI hosted chart, this function assumes that the chartVersion url is valid.

func (*OCIChartRepository) GetChartVersion added in v0.26.0

func (r *OCIChartRepository) GetChartVersion(name, ver string) (*repo.ChartVersion, error)

GetChartVersion returns the repo.ChartVersion for the given name, the version is expected to be a semver.Constraints compatible string. If version is empty, the latest stable version will be returned and prerelease versions will be ignored. adapted from https://github.com/helm/helm/blob/49819b4ef782e80b0c7f78c30bd76b51ebb56dc8/pkg/downloader/chart_downloader.go#L162

func (*OCIChartRepository) HasCredentials added in v0.26.0

func (r *OCIChartRepository) HasCredentials() bool

HasCredentials returns true if the OCIChartRepository has credentials.

func (*OCIChartRepository) Login added in v0.25.0

func (r *OCIChartRepository) Login(opts ...registry.LoginOption) error

Login attempts to login to the OCI registry. It returns an error on failure.

func (*OCIChartRepository) Logout added in v0.25.0

func (r *OCIChartRepository) Logout() error

Logout attempts to logout from the OCI registry. It returns an error on failure.

type OCIChartRepositoryOption added in v0.25.0

type OCIChartRepositoryOption func(*OCIChartRepository) error

OCIChartRepositoryOption is a function that can be passed to NewOCIChartRepository to configure an OCIChartRepository.

func WithCredentialsFile added in v0.26.0

func WithCredentialsFile(credentialsFile string) OCIChartRepositoryOption

WithCredentialsFile returns a ChartRepositoryOption that will set the credentials file

func WithOCIGetter added in v0.25.0

func WithOCIGetter(providers getter.Providers) OCIChartRepositoryOption

WithOCIGetter returns a ChartRepositoryOption that will set the getter.Getter

func WithOCIGetterOptions added in v0.25.0

func WithOCIGetterOptions(getterOpts []getter.Option) OCIChartRepositoryOption

WithOCIGetterOptions returns a ChartRepositoryOption that will set the getter.Options

func WithOCIRegistryClient added in v0.25.0

func WithOCIRegistryClient(client RegistryClient) OCIChartRepositoryOption

WithOCIRegistryClient returns a ChartRepositoryOption that will set the registry client

type RecordMetricsFunc added in v0.24.0

type RecordMetricsFunc func(event string)

RecordMetricsFunc is a function that records metrics.

type RegistryClient added in v0.25.0

type RegistryClient interface {
	Login(host string, opts ...registry.LoginOption) error
	Logout(host string, opts ...registry.LogoutOption) error
	Tags(url string) ([]string, error)
}

RegistryClient is an interface for interacting with OCI registries It is used by the OCIChartRepository to retrieve chart versions from OCI registries

Jump to

Keyboard shortcuts

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