store

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

type CredentialProvider func(ctx context.Context) (user, password string, err error)

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

func (c *GitHubStore) FetchServiceCatalog(ctx context.Context) (*catalog.Catalog, error)

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

func (c *GitHubStore) FetchServiceCatalogSHA(ctx context.Context) (*catalog.Catalog, string, error)

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

func (c *GitHubStore) GetPreview(ctx context.Context, slug string) (*preview.Values, string, error)

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

func WithApplied(f func(lifecycle.Result)) Option

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

func WithMetrics(m Recorder) Option

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

func WithRepoURL(u string) Option

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

type Recorder interface {
	GitopsOp(op, result string, d time.Duration)
	PushConflict(op string)
}

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) Catalog

func (t *Tree) Catalog() (*catalog.Catalog, error)

Catalog returns the service catalog of the tree's badil.yaml.

func (*Tree) DeletePreview

func (t *Tree) DeletePreview(slug string)

DeletePreview deletes previews/<slug>/values.yaml, recorded as "delete". The preview must exist.

func (*Tree) GetPreview

func (t *Tree) GetPreview(slug string) (*preview.Values, error)

GetPreview returns the parsed previews/<slug>/values.yaml, lifecycle.ErrNotFound when it does not exist.

func (*Tree) GitopsRepoURL added in v0.30.0

func (t *Tree) GitopsRepoURL() string

GitopsRepoURL returns the gitops repo URL the tree's previews are projected with: the gitopsRepoURL of their files.

func (*Tree) ListPreviews

func (t *Tree) ListPreviews() ([]string, error)

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

func (t *Tree) PutPreview(slug string, vals preview.Values) error

PutPreview puts vals at previews/<slug>/values.yaml. It records nothing.

func (*Tree) Record added in v0.30.0

func (t *Tree) Record(slug, change string)

Record adds change to the commit body lines of the preview slug.

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.

Jump to

Keyboard shortcuts

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