Help us shape the future of Go! Take the 2026 Go Developer Survey

gitops

package
v8.156.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package gitops gives the reservation commands one way to find the GitOps repo: a checkout on disk, fast-forwarded to origin/main before any command logic runs. The tip of main is the only source of truth; no command reads or writes a cluster.

Index

Constants

View Source
const (
	FlagRepo   = "gitops-repo"
	FlagDir    = "gitops-dir"
	FlagDryRun = "dry-run"
	FlagOutput = "output"

	OutputTable = "table"
	OutputJSON  = "json"

	// EnvTargetDir is the umbrella checkout directory; the GitOps repo lives in
	// its cmc/<repo> subdirectory.
	EnvTargetDir = "UMBRELLA_TARGET_DIR"

	// DefaultRepo holds the configuration of every Giant Swarm management
	// cluster.
	DefaultRepo = reservation.DefaultGitOpsRepository
)
View Source
const CheckoutHelp = `The command works on a checkout of the GitOps repository: --gitops-dir,
or $` + EnvTargetDir + `/cmc/<repo> when that is empty, where <repo> is the
name part of --gitops-repo. It never clones. First it fast-forwards the
checkout to origin/main. It stops when the checkout is not on main, has changes
to tracked files, or has local commits that are not on origin/main. It leaves
untracked files alone. Git uses the checkout's own credentials.`

CheckoutHelp is the paragraph every reservation command's long help carries about the GitOps checkout.

Variables

This section is empty.

Functions

func IsInvalidFlag

func IsInvalidFlag(err error) bool

IsInvalidFlag asserts invalidFlagError.

func IsPushFailed

func IsPushFailed(err error) bool

IsPushFailed asserts pushFailedError.

func IsSync

func IsSync(err error) bool

IsSync asserts syncError.

func Sync

func Sync(ctx context.Context, dir string, stderr io.Writer) error

Sync brings dir to the tip of origin/main, or stops with the reason it cannot do that safely.

func User

func User(ctx context.Context, user string, stderr io.Writer) (string, error)

User returns user when it is set, and otherwise the login of the GitHub token devctl acts with. A GitHub App installation token has no login, so a caller that acts with one passes --user.

func UserHelp

func UserHelp(what string) string

UserHelp is the --user help text shared by every reservation command.

func WriteJSON

func WriteJSON(w io.Writer, v any) error

WriteJSON prints v as indented JSON.

Types

type Checkout

type Checkout struct {
	Dir string
	// contains filtered or unexported fields
}

Checkout is a GitOps checkout that has been synced to origin/main.

func (*Checkout) Explain

func (c *Checkout) Explain(err error) error

Explain turns the errors the user can act on into messages that say so: a directory that is not a GitOps repo names what selected it, and a push that gave up says the change is not in effect and how to clear the local commit. Any other error comes back as it is.

func (*Checkout) Finish

func (c *Checkout) Finish(ctx context.Context, stderr io.Writer, err error) error

Finish ends the command. After a dry run it shows the commits the command made on stderr and resets the checkout to origin/main, even when err is set. Open left the checkout clean on origin/main, so the reset drops only what the command wrote. It returns err, or the reset's error when err is nil.

func (*Checkout) Wrote

func (c *Checkout) Wrote(stderr io.Writer)

Wrote tells the user that a pushed change still has to be applied by Flux. A dry run pushed nothing, so it says nothing.

type Flags

type Flags struct {
	Repo   string
	Dir    string
	DryRun bool
	Output string
}

Flags select the GitOps repo and where its checkout is, and the flags every reservation command shares: how to print the result and, for a command that pushes, whether to push.

func (*Flags) Init

func (f *Flags) Init(cmd *cobra.Command)

func (*Flags) InitDryRun

func (f *Flags) InitDryRun(cmd *cobra.Command)

InitDryRun adds --dry-run, for a command that pushes.

func (*Flags) JSON

func (f *Flags) JSON() bool

JSON reports whether --output asks for JSON.

func (*Flags) Open

func (f *Flags) Open(ctx context.Context, stderr io.Writer) (*Checkout, error)

Open resolves the checkout and syncs it to origin/main. It runs before any command logic, list included. Git uses the checkout's own credentials.

func (*Flags) Resolve

func (f *Flags) Resolve() (dir, source string, err error)

Resolve returns the checkout directory and a description of what selected it. --gitops-dir wins, then $UMBRELLA_TARGET_DIR/cmc/<repo>; there is no fallback clone.

func (*Flags) Validate

func (f *Flags) Validate() error

Jump to

Keyboard shortcuts

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