Documentation
¶
Overview ¶
Package store reads and writes the gitops repository: badil.yaml and the preview values files. It reads a git clone of the default branch and writes by pushing one commit per operation (GitHubStore.Apply).
Index ¶
- type CloneConfig
- type CommitIdentity
- type CredentialProvider
- type GitHubStore
- func (c *GitHubStore) Apply(ctx context.Context, op lifecycle.Op) (lifecycle.Result, error)
- func (c *GitHubStore) Close() error
- func (c *GitHubStore) FetchServiceCatalog(ctx context.Context) (*catalog.Catalog, error)
- func (c *GitHubStore) FetchServiceCatalogSHA(ctx context.Context) (*catalog.Catalog, string, error)
- func (c *GitHubStore) FullName() string
- func (c *GitHubStore) GetPreview(ctx context.Context, slug string) (*preview.Values, string, error)
- func (c *GitHubStore) Invalidate()
- func (c *GitHubStore) ListPreviewFiles(ctx context.Context) ([]string, error)
- func (c *GitHubStore) ListPreviews(ctx context.Context) ([]string, error)
- type Option
- type Recorder
- type Tree
- func (t *Tree) Catalog() (*catalog.Catalog, error)
- func (t *Tree) DeletePreview(slug string)
- func (t *Tree) GetPreview(slug string) (*preview.Values, error)
- func (t *Tree) GitopsRepoURL() string
- func (t *Tree) ListPreviews() ([]string, error)
- func (t *Tree) PutPreview(slug string, vals preview.Values) error
- func (t *Tree) Record(slug, change string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloneConfig ¶
type CloneConfig struct {
// URL is the gitops repo's remote URL.
URL string
// Dir is the clone directory, removed and cloned again on start. When it
// is "", the store clones into its own os.MkdirTemp directory, which
// Close removes.
Dir string
// Credentials authenticates the git calls; nil makes them without auth.
Credentials CredentialProvider
}
CloneConfig is where and how the store clones the gitops repo.
type CommitIdentity ¶
type CommitIdentity struct {
Name, Email string
}
CommitIdentity is the author and committer of the commits Apply pushes.
type CredentialProvider ¶
CredentialProvider returns the user and password of HTTPS basic auth to the gitops remote. It is called before every clone, ls-remote, fetch and push.
type GitHubStore ¶
type GitHubStore struct {
// contains filtered or unexported fields
}
GitHubStore is the gitops repo, read from a git clone and written by pushing commits to it (Apply).
func Open ¶
func Open(ctx context.Context, clone CloneConfig, identity CommitIdentity, opts ...Option) (*GitHubStore, error)
Open clones the gitops repo at clone.URL, which is required, as clone says. Names derive from clone.URL unless WithRepoURL is set; a URL without a repository path of two segments is an error. Apply commits as identity, whose Name and Email must be set. The clone is timed as the clone operation; a failed clone is an error, lifecycle.ErrUnauthorized when the remote or the credential provider refused it.
func (*GitHubStore) Apply ¶
Apply runs op on the gitops repo as one commit. Operations are serialised in the process. Each attempt fetches the default branch, runs op.Change on the tree of the fetched head and, unless it changed nothing, commits the change on that head as the store's identity, unsigned, and pushes it without force. A push that fails while the remote head moved since the fetch is a conflict: it is counted, and the next attempt starts again from a new fetch, after a backoff, up to maxAttempts attempts. Any other push failure is returned, as lifecycle.ErrUnauthorized when the remote refused the credentials. Its duration, retries included, is observed as op.Kind. Once a push landed, Apply calls the store's WithApplied callback with its result.
An Apply waiting for the one before it gives up when ctx is done, with ctx's error and nothing run, observed as a failed op.Kind.
func (*GitHubStore) Close ¶
func (c *GitHubStore) Close() error
Close removes the clone directory when the store created it (an unset CloneConfig.Dir).
func (*GitHubStore) FetchServiceCatalog ¶
FetchServiceCatalog reads badil.yaml from the gitops clone and returns its validated service catalog (the keys of its services mapping, with each service's repo and branch) and `preview` block. A malformed file is an error.
func (*GitHubStore) FetchServiceCatalogSHA ¶
FetchServiceCatalogSHA is FetchServiceCatalog, plus the blob SHA of the badil.yaml it read on the default branch. When the file was read but its content can't be parsed, the SHA is returned with the error; it is "" when the file could not be read.
func (*GitHubStore) FullName ¶
func (c *GitHubStore) FullName() string
FullName returns the gitops repo's repository path, owner/repo on GitHub.
func (*GitHubStore) GetPreview ¶
GetPreview reads previews/<slug>/values.yaml from the gitops clone and returns the parsed values plus the file's blob SHA. Returns lifecycle.ErrNotFound when the file does not exist.
func (*GitHubStore) Invalidate ¶
func (c *GitHubStore) Invalidate()
Invalidate makes the next read check the gitops remote at once, whatever the time since the last check: after a push to the gitops repo.
func (*GitHubStore) ListPreviewFiles ¶
func (c *GitHubStore) ListPreviewFiles(ctx context.Context) ([]string, error)
ListPreviewFiles returns the sorted slugs of the previews whose previews/<slug>/values.yaml is in the gitops clone.
func (*GitHubStore) ListPreviews ¶
func (c *GitHubStore) ListPreviews(ctx context.Context) ([]string, error)
ListPreviews returns the sorted names of the directories under previews/, all of them. A missing previews/ directory yields an empty slice.
type Option ¶
type Option func(*GitHubStore)
Option configures a GitHubStore built by Open.
func WithApplied ¶
WithApplied calls f with the result of every Apply whose push landed, whichever caller ran it; not after a no-op or a failed Apply. f runs on Apply's goroutine before Apply returns: it must not block.
func WithHeadMoved ¶
func WithHeadMoved(f func()) Option
WithHeadMoved calls f after every fetch of the clone that moved the remote-tracking ref of the default branch, Apply's fetches included. f runs on the fetching goroutine, after the clone's locks are released: it must not block.
func WithMetrics ¶
WithMetrics times Apply, as its operation kind, and the clone's git clone, ls-remote and fetch in m, and counts Apply's push conflicts. A nil m leaves the default, which records nothing.
func WithRepoURL ¶ added in v0.27.0
WithRepoURL makes the full name, the commit links and the preview files' gitopsRepoURL derive from u instead of CloneConfig.URL: for a store that clones a mirror of the repo at u.
type Recorder ¶ added in v0.30.0
Recorder records the gitops operations of a GitHubStore. *metrics.Metrics implements it.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is what an operation of Apply reads and changes: the gitops repo at the fetched remote head, plus the preview files the operation put or deleted so far. Its reads see those changes. It records, per preview, the changes of the commit body.
func (*Tree) DeletePreview ¶
DeletePreview deletes previews/<slug>/values.yaml, recorded as "delete". The preview must exist.
func (*Tree) GetPreview ¶
GetPreview returns the parsed previews/<slug>/values.yaml, lifecycle.ErrNotFound when it does not exist.
func (*Tree) GitopsRepoURL ¶ added in v0.30.0
GitopsRepoURL returns the gitops repo URL the tree's previews are projected with: the gitopsRepoURL of their files.
func (*Tree) ListPreviews ¶
ListPreviews returns the sorted names of the directories under previews/, with the operation's changes: a preview whose last file was deleted is gone, one whose file was put is there.
func (*Tree) PutPreview ¶ added in v0.30.0
PutPreview puts vals at previews/<slug>/values.yaml. It records nothing.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package storetest provides bare gitops repositories for tests of the store and of its callers: remotes a store clones, fetches from and pushes to, in-process, with no git binary.
|
Package storetest provides bare gitops repositories for tests of the store and of its callers: remotes a store clones, fetches from and pushes to, in-process, with no git binary. |