component

package
v1.12.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package component holds the package-source machinery shared by the addon and module implementations: the Registry model and its data store, the readers that speak git, OSS and OCI, and the OCI chart helpers.

Index

Constants

View Source
const (
	// AddonGitRemedy is what a type: addon component can resolve instead.
	AddonGitRemedy = "use an OCI registry or a Helm repository"
	// ModuleGitRemedy is what a type: module component can resolve instead.
	// Modules have never read a Helm chart repository.
	ModuleGitRemedy = "use an OCI registry"
)

The remedy each component type offers when it refuses a Git registry. They differ because what the two can read differs.

View Source
const (
	// EOFError is error returned by xml parse
	EOFError string = "EOF"
	// MetadataFileName is the package metadata.yaml file name, which is how a
	// reader recognises a package directory in a flat listing.
	MetadataFileName string = "metadata.yaml"
	// DirType means a directory
	DirType = "dir"
	// FileType means a file
	FileType = "file"
	// BlobType means a blob
	BlobType = "blob"
	// TreeType means a tree
	TreeType = "tree"
)
View Source
const DefaultFailureTTL = time.Minute

DefaultFailureTTL is how long a failed read is remembered.

A read that failed at a revision fails the same way at that revision, and without remembering it the expensive part runs again on every reconcile: a module whose _module.cue does not compile, or an addon whose metadata cannot be parsed, crawls the whole registry, fails downstream of the crawl, and is requeued a second later by the workflow. The rate-limit gate does not help, because the registry is answering perfectly well. It is kept short so that fixing the cause does not need a push to the registry to take effect.

View Source
const DefaultRevisionCacheSize = 64

DefaultRevisionCacheSize is how many packages one cache keeps. A cluster reads a handful of modules and addons from a handful of registries, so this is a bound, not a target.

View Source
const DefaultRevisionTTL = 12 * time.Hour

DefaultRevisionTTL is a backstop, not the cache's working lifetime. Entries are normally kept or replaced by comparing revisions, which is exact; the TTL only bounds how long a package can be served when the registry has been unreachable for revision checks that whole time.

Variables

View Source
var (
	// ErrRateLimit means the source's API rate limit was exceeded.
	ErrRateLimit = NewError("exceed github access rate limit")

	// ErrRegistryNotExist means the named registry is not configured.
	ErrRegistryNotExist = NewError("registry does not exist")
)
View Source
var ErrGitSourceUnsupported = NewError("git registries are not supported for addon and module components")

ErrGitSourceUnsupported means a registry backed by Git was named by an Application component. The type: addon and type: module components resolve packages from an OCI registry or a Helm repository only.

This restricts the component path, not the registry format. A Git registry stays a valid record and `vela addon enable` keeps installing from it; only the declarative components refuse to resolve one.

View Source
var ErrPackageNotExist = NewError("package does not exist in registry")

ErrPackageNotExist means the named package is not in the registry. It is separate from ErrRegistryNotExist: the registry answered, and the answer was that it does not carry this package.

View Source
var ErrRevisionUnsupported = NewError("registry source cannot report a revision")

ErrRevisionUnsupported means this registry source cannot name its revision cheaply, so a caller has to read the package to know what it holds.

Functions

func AwaitOCICall

func AwaitOCICall[T any](ctx context.Context, op func() (T, error)) (T, error)

AwaitOCICall runs a blocking helm registry operation and returns as soon as ctx is done, so a cancelled caller is released even though the helm registry client itself takes no context. The operation keeps running in the background; its HTTP client timeout is what eventually reclaims it.

func GitFamilySource

func GitFamilySource(reg Registry) string

GitFamilySource names the Git flavour a registry is backed by -- "git", "gitee" or "gitlab" -- or "" for any other kind of entry.

Every place that refuses Git for a component goes through this rather than testing the three fields itself, so the admission check, the module resolver and the addon renderer cannot drift apart on what counts as Git.

func GitSourceUnsupportedDetail

func GitSourceUnsupportedDetail(kind, remedy string) string

GitSourceUnsupportedDetail is the one sentence that explains the refusal, for a caller that needs prose rather than an error -- an admission webhook builds a field.Invalid detail, which takes a string and cannot wrap.

kind comes from GitFamilySource; callers have already established it is non-empty. remedy is the caller's, because the answer differs: an addon component can resolve from an OCI registry or a Helm repository, a module component from an OCI registry only. Baking one remedy in here would tell module users to reach for a source modules cannot read.

Every refusal goes through this or through GitSourceUnsupportedError below, so the wording cannot drift between what admission says and what the resolve reports.

func GitSourceUnsupportedError

func GitSourceUnsupportedError(name, kind, remedy string) error

GitSourceUnsupportedError reports that registry name is Git backed, naming the flavour so the reader knows which field to look at, and wrapping ErrGitSourceUnsupported so callers can classify it with errors.Is.

func IsDockerHubHost

func IsDockerHubHost(host string) bool

IsDockerHubHost reports whether host is a known Docker Hub registry alias. Mirrors the alias list in pkg/cue/cuex/providers/helm/auth.go's normalizeDockerHubAliases; kept here rather than imported because that package is a different, heavier dependency (CUE #Helm chart-fetch auth) that the registry code does not otherwise need.

It lives with the generic OCI primitives rather than in pkg/addon because which hosts are Docker Hub is a property of the registry, not of addons: the module publish and fetch paths reach the same registries.

func IsOCIRepositoryAbsentError

func IsOCIRepositoryAbsentError(err error) bool

IsOCIRepositoryAbsentError reports whether err is a registry answer confirming "this repository does not exist", as opposed to "this repository could not be read". Only the first lets the caller publish a catalog, because there is nothing to preserve; misreading the second rebuilds the catalog from an empty list and drops every addon already published.

The test is the NAME_UNKNOWN error code, not the 404 status. A bare 404 is ambiguous -- a proxy, a gateway, or a registry that does not serve the tag-list route answers the same way for a repository that does exist -- so it stays on the conservative branch.

The code has to be read out of the message: oras-go v1.2.5 builds these errors with fmt.Errorf and keeps its error types in the unexported pkg/registry/remote/internal/errutil. A miss is safe in the same direction -- callers refuse to rewrite the catalog.

func IsOCIRepositoryNotFound

func IsOCIRepositoryNotFound(err error) bool

IsOCIRepositoryNotFound reports whether err is a registry's "this repository does not exist" answer. ECR reports RepositoryNotFoundException; the distribution API reports NAME_UNKNOWN. On a push, ECR answers the blob upload for a missing repository with a bare 404 and no error body, so a 404 on the upload endpoint is the only sign there is.

func IsOCITagImmutable

func IsOCITagImmutable(err error) bool

IsOCITagImmutable reports whether err is the registry refusing to move an existing tag. On ECR this is the repository's IMMUTABLE tag mutability setting, which no client flag can override.

func IsOCIThrottledError

func IsOCIThrottledError(err error) bool

IsOCIThrottledError reports whether the registry refused because the caller is asking too often, rather than because of what it asked for.

func IsOCIURL

func IsOCIURL(rawURL string) bool

IsOCIURL reports whether a repository URL addresses an OCI registry rather than an indexed HTTP Helm repository. The scheme is the whole signal: it decides which transport reads the chart, which credential field carries the password, and whether the credential is moved into a Secret.

It parses rather than matching a prefix, so a repository merely hosted at oci.example.com over https is not mistaken for an OCI registry, and a URL that cannot be parsed classifies as not-OCI instead of guessing.

func IsPackageName

func IsPackageName(name string) bool

IsPackageName reports whether name is usable as a single directory under a registry's configured path.

A scoped listing joins the name onto that path to build a request, so an unchecked name escapes the registry's declared subtree: path.Join cleans "../.." away, turning a three-segment path into a one-segment one and listing a directory the platform team never exposed. Names come straight off an Application spec -- nothing between the CUE provider and here validates them -- so this is the boundary.

func ListOCITags

func ListOCITags(ctx context.Context, repoRef, host, username, password string) ([]string, error)

ListOCITags lists the repository's semver tags (highest first) via the Helm registry client, which filters non-semver tags and sorts descending.

func ListOCITagsWithPlainHTTP

func ListOCITagsWithPlainHTTP(ctx context.Context, repoRef, host, username, password string) ([]string, error)

func ListOCITagsWithTransport

func ListOCITagsWithTransport(repoRef, host, username, password string, plainHTTP bool) ([]string, error)

func ListRegistryGitKinds

func ListRegistryGitKinds(ctx context.Context, cli client.Client) (map[string]string, error)

ListRegistryGitKinds reports which configured addon registries are Git backed, as the GitFamilySource value keyed by registry name. A registry on any other source is absent, so an empty map means nothing configured is Git.

It reads the registry ConfigMap and no token Secret. That is what makes it usable from admission: a registry's source kind is in the ConfigMap, and resolving the package it points at is the part admission must not do.

func ListRegistryGitKindsIn

func ListRegistryGitKindsIn(ctx context.Context, cli client.Client, cmName string) (map[string]string, error)

ListRegistryGitKindsIn is ListRegistryGitKinds over a named ConfigMap, so the module registry can be inspected the same way. Module registries live in their own ConfigMap but share the record format, and therefore the question.

func ListRegistrySources

func ListRegistrySources(ctx context.Context, cli client.Client) (names []string, gitKinds map[string]string, err error)

ListRegistrySources reports the configured addon registries: every name in sorted order, and the Git kinds as ListRegistryGitKinds returns them.

Prefer ListRegistryGitKinds when the names are not needed: this one also builds and sorts a slice.

func ListRegistrySourcesIn

func ListRegistrySourcesIn(ctx context.Context, cli client.Client, cmName string) (names []string, gitKinds map[string]string, err error)

ListRegistrySourcesIn is ListRegistrySources over a named ConfigMap, so the module registry can be inspected the same way. Module registries live in their own ConfigMap but share the record format, and therefore the question.

Both answers come from one read, because they have to agree. Read separately, a registry created between the calls appears in names but not in gitKinds, and a caller would treat it as non-Git.

func NewError

func NewError(msg string) error

NewError returns a sentinel error carrying msg.

func NewOCIClientWithPlainHTTP

func NewOCIClientWithPlainHTTP(host, username, password string, plainHTTP bool) (*registry.Client, error)

func OCIChartRef

func OCIChartRef(reg Registry, name, tag string) (string, error)

OCIChartRef returns the full OCI reference a module chart publishes to, "<host>[/<prefix>]/<name>:<tag>". It is exported so a caller can print the target before pushing.

func OCIChartTagExists

func OCIChartTagExists(ctx context.Context, reg Registry, name, tag string) (bool, error)

OCIChartTagExists reports whether tag is already published for name in reg. A repository that does not exist yet is reported as "no such tag" rather than an error: the first publish of a module is exactly that case.

func OCIManifestDigest

func OCIManifestDigest(ctx context.Context, repoRef, host, username, password, tag, lastKnown string, plainHTTP bool) (string, error)

OCIManifestDigest returns the digest that tag currently resolves to in the repository, without pulling the artifact.

lastKnown is the digest the caller already holds, or empty. When it is still current the registry answers 304 and lastKnown is returned unchanged, which costs no bandwidth and, on registries that meter by pull, nothing at all.

func OCIRegistryLocation

func OCIRegistryLocation(rawURL string) (host, prefix string)

OCIRegistryLocation returns the registry host and repository prefix. Any of the schemes a registry URL is written with is stripped first: without that, an "http://" URL splits at the scheme's own slash and yields the host "http:".

func OCIRepoRef

func OCIRepoRef(url, name string) (repoRef, host string)

OCIRepoRef builds the OCI repository reference (no tag) and host from a registry URL and addon name. The URL may carry an "oci://" scheme and/or a trailing slash. The host is the registry authority (everything before the first path separator), used for login.

func PullOCIChart

func PullOCIChart(ctx context.Context, ref, host, username, password string) ([]byte, error)

PullOCIChart is the production puller: it logs in (when credentials are set) and pulls the chart layer from the OCI registry via the Helm registry client.

func PullOCIChartFiles

func PullOCIChartFiles(ctx context.Context, reg Registry, name, version string) ([]*loader.BufferedFile, error)

PullOCIChartFiles pulls the Helm-chart artifact for name[:version] (an empty version resolves the highest semver tag) and returns its files, paths prefixed by the chart name.

func PullOCIChartWithPlainHTTP

func PullOCIChartWithPlainHTTP(ctx context.Context, ref, host, username, password string) ([]byte, error)

func PullOCIChartWithTransport

func PullOCIChartWithTransport(ref, host, username, password string, plainHTTP bool) ([]byte, error)

func PushOCIChart

func PushOCIChart(ctx context.Context, reg Registry, name, version string, archive []byte) error

PushOCIChart pushes a packaged Helm chart archive to reg as name:version. It is the push counterpart of PullOCIChartFiles and uses the same reference construction and the same authenticated Helm registry client, so a module published here is pulled by the module fetch unchanged.

func RegisterGitReaderBuilder

func RegisterGitReaderBuilder(b GitReaderBuilder)

RegisterGitReaderBuilder installs the Git-family reader builder. Call it from an init.

func ResetOCIClientCache

func ResetOCIClientCache()

ResetOCIClientCache empties the logged-in client cache. It exists for tests in packages that drive the OCI transport from outside this one: the cache is process-wide, so a test that builds clients would otherwise leak them into whichever test ran next.

func ResetRateLimitGate

func ResetRateLimitGate()

ResetRateLimitGate forgets every recorded rate limit. It exists for tests, which would otherwise leak a hold from one case into the next.

Types

type AsyncReader

type AsyncReader interface {
	// ListAddonMeta will return directory tree contain addon metadata only
	ListAddonMeta() (addonCandidates map[string]SourceMeta, err error)

	// ReadFile should accept relative path to github repo/path or OSS bucket, and report the file content
	ReadFile(path string) (content string, err error)

	// RelativePath return a relative path to GitHub repo/path or OSS bucket/path
	RelativePath(item Item) string
}

AsyncReader helps async read files of addon

func NewAsyncReader

func NewAsyncReader(baseURL, bucket, repo, subPath, token string, rdType ReaderType, opts ...ReaderOption) (AsyncReader, error)

NewAsyncReader builds a reader for one source. OSS is served here; the Git family is delegated to the builder pkg/addon registers.

type File

type File struct {
	Name         string    `xml:"Key"`
	Size         int       `xml:"Size"`
	LastModified time.Time `xml:"LastModified"`
	Type         string    `xml:"Type"`
	StorageClass string    `xml:"StorageClass"`
}

File is for oss xml parse

type GitAddonSource

type GitAddonSource struct {
	URL            string `json:"url,omitempty" validate:"required"`
	Path           string `json:"path,omitempty"`
	Token          string `json:"token,omitempty"`
	TokenSecretRef string `json:"tokenSecretRef,omitempty"`
}

GitAddonSource defines the information about the Git as addon source

func (*GitAddonSource) GetToken

func (g *GitAddonSource) GetToken() string

GetToken returns the token of the source

func (*GitAddonSource) GetTokenSecretRef

func (g *GitAddonSource) GetTokenSecretRef() string

GetTokenSecretRef return the token secret ref of the source

func (*GitAddonSource) SafeCopy

func (g *GitAddonSource) SafeCopy() *GitAddonSource

SafeCopy hides field Token

func (*GitAddonSource) SetToken

func (g *GitAddonSource) SetToken(token string)

SetToken set the token of the source

func (*GitAddonSource) SetTokenSecretRef

func (g *GitAddonSource) SetTokenSecretRef(secretName string)

SetTokenSecretRef set the token secret ref to the source

type GitReaderBuilder

type GitReaderBuilder func(baseURL, repo, subPath, token string, rdType ReaderType, ref string) (AsyncReader, error)

GitReaderBuilder builds an AsyncReader over one of the Git-family sources. The parameters are NewAsyncReader's, minus the ones no Git source uses.

type GiteeAddonSource

type GiteeAddonSource struct {
	URL            string `json:"url,omitempty" validate:"required"`
	Path           string `json:"path,omitempty"`
	Token          string `json:"token,omitempty"`
	TokenSecretRef string `json:"tokenSecretRef,omitempty"`
}

GiteeAddonSource defines the information about the Gitee as addon source

func (*GiteeAddonSource) GetToken

func (g *GiteeAddonSource) GetToken() string

GetToken return the token of the source

func (*GiteeAddonSource) GetTokenSecretRef

func (g *GiteeAddonSource) GetTokenSecretRef() string

GetTokenSecretRef return the token secret ref of the source

func (*GiteeAddonSource) SafeCopy

func (g *GiteeAddonSource) SafeCopy() *GiteeAddonSource

SafeCopy hides field Token

func (*GiteeAddonSource) SetToken

func (g *GiteeAddonSource) SetToken(token string)

SetToken set the token of the source

func (*GiteeAddonSource) SetTokenSecretRef

func (g *GiteeAddonSource) SetTokenSecretRef(secretName string)

SetTokenSecretRef set the token secret ref to the source

type GitlabAddonSource

type GitlabAddonSource struct {
	URL            string `json:"url,omitempty" validate:"required"`
	Repo           string `json:"repo,omitempty" validate:"required"`
	Path           string `json:"path,omitempty"`
	Token          string `json:"token,omitempty"`
	TokenSecretRef string `json:"tokenSecretRef,omitempty"`
}

GitlabAddonSource defines the information about Gitlab as an addon source

func (*GitlabAddonSource) GetToken

func (g *GitlabAddonSource) GetToken() string

GetToken return the token of the source

func (*GitlabAddonSource) GetTokenSecretRef

func (g *GitlabAddonSource) GetTokenSecretRef() string

GetTokenSecretRef return the token secret ref of the source

func (*GitlabAddonSource) SafeCopy

func (g *GitlabAddonSource) SafeCopy() *GitlabAddonSource

SafeCopy hides field Token

func (*GitlabAddonSource) SetToken

func (g *GitlabAddonSource) SetToken(token string)

SetToken set the token of the source

func (*GitlabAddonSource) SetTokenSecretRef

func (g *GitlabAddonSource) SetTokenSecretRef(secretName string)

SetTokenSecretRef set the token secret ref to the source

type HelmSource

type HelmSource struct {
	URL             string `json:"url,omitempty" validate:"required"`
	InsecureSkipTLS bool   `json:"insecureSkipTLS,omitempty"`
	Username        string `json:"username,omitempty"`
	// Password authenticates an http(s):// Helm repository.
	Password string `json:"password,omitempty"`
	// Token authenticates an oci:// registry. For ECR the Username is "AWS" and
	// the Token is the output of `aws ecr get-login-password`.
	Token string `json:"token,omitempty"`
	// TokenSecretRef names the Secret holding Token once it has been moved out
	// of the ConfigMap.
	TokenSecretRef string `json:"tokenSecretRef,omitempty"`
}

HelmSource defines the information about a Helm chart repository as an addon source. The URL scheme decides the transport: an http(s):// URL is an indexed Helm repository, an oci:// URL is an OCI registry holding the addon as a Helm chart (pushed via `helm push oci://...`).

The two transports authenticate through different fields. An http(s):// URL uses Password, which stays in the registry ConfigMap. An oci:// URL uses Token, which is moved into a Secret and referenced by TokenSecretRef. Setting the field belonging to the other scheme is a misconfiguration rather than a fallback, because it would otherwise reach the registry as anonymous access and fail as an opaque 401.

func (*HelmSource) Credential

func (h *HelmSource) Credential() (username, secret string)

Credential returns the username and secret the transport should authenticate with, chosen by URL scheme. Callers read credentials through this rather than reaching for Password or Token directly, so neither backend has to know which field the other one uses.

func (*HelmSource) GetToken

func (h *HelmSource) GetToken() string

GetToken returns the token of the source

func (*HelmSource) GetTokenSecretRef

func (h *HelmSource) GetTokenSecretRef() string

GetTokenSecretRef returns the token secret ref of the source

func (*HelmSource) SafeCopy

func (h *HelmSource) SafeCopy() *HelmSource

SafeCopy hides field Username, Password

This keeps only the URL, which is narrower than the OCI source it replaces: that one also carried Username and TokenSecretRef. Widening it would change released behaviour that TestSafeCopy pins, and no caller needs the identity fields, so the narrower contract stands. The push path builds its own source explicitly instead (see ociPushSource in push.go).

func (*HelmSource) SetToken

func (h *HelmSource) SetToken(token string)

SetToken sets the token of the source and clears any secret ref

func (*HelmSource) SetTokenSecretRef

func (h *HelmSource) SetTokenSecretRef(secretName string)

SetTokenSecretRef sets the token secret ref and clears the inline token

func (*HelmSource) ValidateCredential

func (h *HelmSource) ValidateCredential() error

ValidateCredential rejects a source whose credential fields do not match its URL scheme, and options the scheme cannot honour. Without this the mismatch surfaces far from its cause: the transport reads the field it knows about, finds it empty, and authenticates anonymously.

type Item

type Item interface {
	// GetType return "dir" or "file"
	GetType() string
	GetPath() string
	GetName() string
}

Item is a partial interface for github.RepositoryContent

type ListBucketResult

type ListBucketResult struct {
	Files []File `xml:"Contents"`
	Count int    `xml:"KeyCount"`
}

ListBucketResult describe a file list from OSS

type LocalReader

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

func NewLocalReader

func NewLocalReader(dir, name string) LocalReader

NewLocalReader builds a reader over a package directory on disk.

func (LocalReader) ListAddonMeta

func (l LocalReader) ListAddonMeta() (map[string]SourceMeta, error)

func (LocalReader) Name

func (l LocalReader) Name() string

Name returns the package name the reader was built for.

func (LocalReader) ReadFile

func (l LocalReader) ReadFile(path string) (string, error)

func (LocalReader) RelativePath

func (l LocalReader) RelativePath(item Item) string

type MemoryReader

type MemoryReader struct {
	Name  string
	Files []*loader.BufferedFile
	// contains filtered or unexported fields
}

MemoryReader is async reader for memory data

func (*MemoryReader) ListAddonMeta

func (l *MemoryReader) ListAddonMeta() (map[string]SourceMeta, error)

ListAddonMeta list all metadata of helm repo registry

func (*MemoryReader) ReadFile

func (l *MemoryReader) ReadFile(path string) (string, error)

ReadFile ready file from memory

func (*MemoryReader) RelativePath

func (l *MemoryReader) RelativePath(item Item) string

RelativePath calculate the relative path of one file

type OSSAddonSource

type OSSAddonSource struct {
	Endpoint string `json:"end_point" validate:"required"`
	Bucket   string `json:"bucket"`
	Path     string `json:"path"`
}

OSSAddonSource is UIData source from alibaba cloud OSS style source

type OSSItem

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

OSSItem is Item implement for OSS

func NewOSSItem

func NewOSSItem(tp, path, name string) *OSSItem

NewOSSItem builds an OSS listing item of the given type, path and name.

func (OSSItem) GetName

func (i OSSItem) GetName() string

GetName from OSSItem

func (OSSItem) GetPath

func (i OSSItem) GetPath() string

GetPath from OSSItem

func (OSSItem) GetType

func (i OSSItem) GetType() string

GetType from OSSItem

type RateLimitedError

type RateLimitedError struct {
	// Source identifies what refused, as owner/repo or registry host.
	Source string
	// Until is when the source said its limit resets. Zero if it did not say.
	Until time.Time
}

RateLimitedError says a source refused the request for rate limiting, and when it is worth asking again. The reset time is the part that matters: a reconcile loop that retries every second otherwise spends a request each time to be told the same thing, which keeps the limit exhausted through its own reset and turns a transient refusal into a permanent one.

func (*RateLimitedError) Error

func (e *RateLimitedError) Error() string

func (*RateLimitedError) RetryAfter

func (e *RateLimitedError) RetryAfter() time.Duration

RetryAfter is how long to wait before asking the source again, or zero if it is worth asking now.

func (*RateLimitedError) Unwrap

func (e *RateLimitedError) Unwrap() error

Unwrap reports ErrRateLimit so that every existing errors.Is test for the sentinel keeps matching now that the concrete error carries the reset time.

type ReaderOption

type ReaderOption func(*readerConfig)

ReaderOption adjusts how a reader resolves content.

func WithRef

func WithRef(ref string) ReaderOption

WithRef reads at a specific branch, tag or commit instead of whatever the registry URL pinned.

type ReaderType

type ReaderType string

ReaderType marks where to read addon files

const (
	// GitType reads from a GitHub repository.
	GitType ReaderType = "git"
	// OSSType reads from an object-storage bucket.
	OSSType ReaderType = "oss"
	// GiteeType reads from a Gitee repository.
	GiteeType ReaderType = "gitee"
	// GitlabType reads from a GitLab repository.
	GitlabType ReaderType = "gitlab"
)

type Registry

type Registry struct {
	Name string `json:"name"`

	Helm   *HelmSource        `json:"helm,omitempty"`
	Git    *GitAddonSource    `json:"git,omitempty"`
	OSS    *OSSAddonSource    `json:"oss,omitempty"`
	Gitee  *GiteeAddonSource  `json:"gitee,omitempty"`
	Gitlab *GitlabAddonSource `json:"gitlab,omitempty"`
	// contains filtered or unexported fields
}

Registry represent a addon registry model

func (Registry) AtRevision

func (r Registry) AtRevision(revision string) Registry

AtRevision returns a copy of the registry whose reads are pinned to revision, as PackageRevision reported it.

Pinning closes a window that would otherwise cache the wrong bytes permanently. A caller checks the revision, then reads; between those two the source can move, and GitHub's contents API is eventually consistent with its commits API, so the read can return the pre-push tree while the probe already reported the post-push commit. The result would be stored under the new revision, so every later check would match it and serve that stale content until the next commit -- possibly days. Reading at the revision that was checked makes the two agree by construction.

An empty revision returns the registry unchanged, so a source that cannot name a revision keeps reading whatever is current.

func (*Registry) BuildReader

func (r *Registry) BuildReader(opts ...ReaderOption) (AsyncReader, error)

BuildReader will build a AsyncReader from registry, AsyncReader are needed to read addon files

func (*Registry) GetTokenSource

func (r *Registry) GetTokenSource() TokenSource

GetTokenSource return the token source of the registry

func (*Registry) ListAddonMeta

func (r *Registry) ListAddonMeta() (map[string]SourceMeta, error)

ListAddonMeta list addon file meta(path and name) from a registry

func (*Registry) ListPackageMeta

func (r *Registry) ListPackageMeta(name string) (SourceMeta, error)

ListPackageMeta lists one package's files by listing the registry and picking the one entry out.

func (*Registry) OCIChartSource

func (r *Registry) OCIChartSource() *HelmSource

OCIChartSource returns the chart source for a registry the module chart pull/push path can talk to, or nil for every other kind of entry. It widens OCISource by the two spellings that path has always accepted:

  • http://host/prefix, an OCI registry served without TLS (a local or port-forwarded test registry). IsOCIURL rejects that because for an addon registry http(s):// means a ChartMuseum repository, but modules never supported ChartMuseum, so the spelling is free here.
  • a bare host such as an ECR endpoint, the form `vela module publish` documents. OCIRegistryLocation parses it the same either way.

https:// is still not OCI: that one really does address a chart repository, and treating it as a registry would misroute a hand-edited helm entry that ResolveRegistry is supposed to reject.

func (*Registry) OCISource

func (r *Registry) OCISource() *HelmSource

OCISource returns the registry's chart source when it addresses an OCI registry, or nil for every other kind of entry. An OCI registry is a Helm source whose URL carries the oci:// scheme -- there is no separate field for it -- so callers that need to tell the two apart go through this rather than repeating the scheme test.

func (*Registry) PackageRevision

func (r *Registry) PackageRevision(ctx context.Context, name, version, lastKnown string) (string, error)

PackageRevision names what the registry currently holds for one package, without reading the package. Two callers of this in a row cost one small request between them, or none at all when the source can revalidate conditionally.

lastKnown is the revision the caller holds, or empty. When it is still current it is returned unchanged.

The returned string is opaque and only ever compared for equality. It is not a version: a git registry reports a commit, an OCI registry a tag and the digest behind it, and neither is ordered.

type RegistryDataStore

type RegistryDataStore interface {
	ListRegistries(context.Context) ([]Registry, error)
	AddRegistry(context.Context, Registry) error
	DeleteRegistry(context.Context, string) error
	UpdateRegistry(context.Context, Registry) error
	GetRegistry(context.Context, string) (Registry, error)
}

RegistryDataStore CRUD addon registry data in configmap

func NewRegistryDataStore

func NewRegistryDataStore(cli client.Client) RegistryDataStore

NewRegistryDataStore get RegistryDataStore operation interface

func NewRegistryDataStoreFor

func NewRegistryDataStoreFor(cli client.Client, cmName, secretNamePrefix string) RegistryDataStore

NewRegistryDataStoreFor returns a RegistryDataStore backed by the ConfigMap named cmName, storing registry tokens in secrets named secretNamePrefix + registry name. The module registry store uses this so its entries and credentials stay separate from the addon registry store.

type RevisionCache

type RevisionCache[T any] struct {
	// contains filtered or unexported fields
}

RevisionCache holds what a registry yielded for a package, keyed by the revision it was read at, so a reconcile that finds the revision unchanged spends nothing reading it again.

This is the whole point of the type. Reading one module from a git registry costs one API request per directory in the registry plus one per file of the module, every time, and the render path runs on every reconcile of every Application that names it. Several applications retrying on failure once a second is enough to spend a 5000-request hour in minutes, and once the hour is spent every render fails, which makes every Application retry, which spends the next hour too.

func NewRevisionCache

func NewRevisionCache[T any](size int) *RevisionCache[T]

NewRevisionCache returns a cache bounded to size entries, holding each for at most ttl. A size or ttl below one gets the package default.

The sweeper that expires entries runs for the life of the process, which is the life of this cache: one is built per package-level variable at startup, not per request.

func (*RevisionCache[T]) Load

func (c *RevisionCache[T]) Load(key string, revision func(lastKnown string) (string, error), read func(revision string) (T, error)) (T, error)

Load returns the package stored under key, reading it through read only when the source says its revision has moved.

revision is given the revision the cache holds so the source can revalidate conditionally, which for GitHub means a 304 that does not count against the rate limit at all, and for an OCI registry a manifest HEAD instead of a pull. A source that cannot report a revision returns ErrRevisionUnsupported and every call reads.

read is handed the revision it must read at, empty when there is none to pin to. Reading at the checked revision is what keeps the entry honest: the source can move between the check and the read, and a read that returned older content than the revision it is filed under would be served for as long as that revision stayed current.

When the revision probe itself fails and the cache holds a value, that value is served and the failure logged. This is deliberate. The cached value is what the registry served, not a guess, and refusing to use it is how one exhausted rate limit takes down every Application that was running fine. A caller that must not serve an unrevalidated package should probe the revision itself rather than going through the cache.

func (*RevisionCache[T]) Reset

func (c *RevisionCache[T]) Reset()

Reset empties the cache. It exists for tests, which would otherwise carry a package from one case into the next.

type SafeCopier

type SafeCopier interface {
	SafeCopy() interface{}
}

SafeCopier is an interface to copy struct without sensitive fields, such as Token, Username, Password

type SourceMeta

type SourceMeta struct {
	Name  string
	Items []Item
}

SourceMeta record the whole metadata of an addon

func ListPackageMeta

func ListPackageMeta(reader AsyncReader, name string) (SourceMeta, error)

ListPackageMeta lists one package from a reader.

type TokenSource

type TokenSource interface {
	// GetToken return the token of the source
	GetToken() string
	// SetToken set the token of the source
	SetToken(string)
	// SetTokenSecretRef set the token secret ref to the source
	SetTokenSecretRef(string)
	// GetTokenSecretRef return the token secret ref of the source
	GetTokenSecretRef() string
}

TokenSource is an interface for addon source that has token

Jump to

Keyboard shortcuts

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