tanka

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 28 Imported by: 2

Documentation

Overview

Package tanka allows to use most of Tanka's features available on the command line programmatically as a Golang library. Keep in mind that the API is still experimental and may change without and signs of warnings while Tanka is still in alpha. Nevertheless, we try to avoid breaking changes.

Index

Constants

View Source
const BelRune = string(rune(7))

BelRune is a string of the Ascii character BEL which made computers ring in ancient times We use it as "magic" char for the subfolder creation as it is a non printable character and thereby will never be in a valid filepath by accident. Only when we include it.

View Source
const MetadataEvalScript = `` /* 546-byte string literal not displayed */

MetadataEvalScript finds the Environment object (without its .data object)

View Source
const MetadataSingleEnvEvalScript = `` /* 593-byte string literal not displayed */

MetadataSingleEnvEvalScript returns a Single Environment object

View Source
const SingleEnvEvalScript = `` /* 518-byte string literal not displayed */

SingleEnvEvalScript returns a Single Environment object

Variables

View Source
var CurrentVersion = defaultDevVersion

CurrentVersion is the current version of the running Tanka code

Functions

func Apply

func Apply(baseDir string, opts ApplyOpts) error

Apply parses the environment at the given directory (a `baseDir`) and applies the evaluated jsonnet to the Kubernetes cluster defined in the environments `spec.json`.

func Delete added in v0.11.0

func Delete(baseDir string, opts DeleteOpts) error

Delete parses the environment at the given directory (a `baseDir`) and deletes the generated objects from the Kubernetes cluster defined in the environment's `spec.json`.

func Diff

func Diff(baseDir string, opts DiffOpts) (*string, error)

Diff parses the environment at the given directory (a `baseDir`) and returns the differences from the live cluster state in `diff(1)` format. If the `WithDiffSummarize` modifier is used, a histogram is returned instead. The cluster information is retrieved from the environments `spec.json`. NOTE: This function requires on `diff(1)` and `kubectl(1)`

func Eval added in v0.7.0

func Eval(path string, opts Opts) (interface{}, error)

Eval returns the raw evaluated Jsonnet

func ExportEnvironments added in v0.14.0

func ExportEnvironments(envs []*v1alpha1.Environment, to string, opts *ExportEnvOpts) error

func FindEnvs added in v0.14.0

func FindEnvs(path string, opts FindOpts) ([]*v1alpha1.Environment, error)

FindEnvs returns metadata of all environments recursively found in 'path'. Each directory is tested and included if it is a valid environment, either static or inline. If a directory is a valid environment, its subdirectories are not checked.

func Format added in v0.9.0

func Format(filename string, content string) (string, error)

Format takes a file's name and contents and returns them in properly formatted. The file does not have to exist on disk.

func FormatFiles added in v0.9.0

func FormatFiles(fds []string, opts *FormatOpts) ([]string, error)

FormatFiles takes a list of files and directories, processes them and returns which files were formatted and perhaps an error.

func List added in v0.14.0

func List(path string, opts Opts) ([]*v1alpha1.Environment, error)

List finds metadata of all environments at path that could possibly be loaded. List can be used to deal with multiple inline environments, by first listing them, choosing the right one and then only loading that one

func LoadEnvironment added in v0.14.0

func LoadEnvironment(path string, opts Opts) (*v1alpha1.Environment, error)

func PatternEvalScript added in v0.14.0

func PatternEvalScript(expr string) string

func Peek added in v0.14.0

func Peek(path string, opts Opts) (*v1alpha1.Environment, error)

Peek loads the metadata of the environment at path. To get resources as well, use Load

func Prune added in v0.10.0

func Prune(baseDir string, opts PruneOpts) error

Prune deletes all resources from the cluster, that are no longer present in Jsonnet. It uses the `tanka.dev/environment` label to identify those.

func Show

func Show(baseDir string, opts Opts) (manifest.List, error)

Show parses the environment at the given directory (a `baseDir`) and returns the list of Kubernetes objects. Tip: use the `String()` function on the returned list to get the familiar yaml stream

Types

type ApplyBaseOpts added in v0.23.0

type ApplyBaseOpts struct {
	Opts
	DiffBaseOpts

	// AutoApprove skips the interactive approval
	AutoApprove AutoApproveSetting
	// DryRun string passed to kubectl as --dry-run=<DryRun>
	DryRun string
	// Force ignores any warnings kubectl might have
	Force bool
}

type ApplyOpts added in v0.12.0

type ApplyOpts struct {
	ApplyBaseOpts

	// DiffStrategy to use for printing the diff before approval
	DiffStrategy string
	// ApplyStrategy decides how kubectl will apply the manifest
	ApplyStrategy string
	// Validate set to false ignores invalid Kubernetes schemas
	Validate bool

	// ServerSide bool passed to kubectl as --server-side
	ServerSide bool
}

ApplyOpts specify additional properties for the Apply action

type AutoApproveSetting added in v0.23.0

type AutoApproveSetting string
const (
	// AutoApproveNever disables auto-approval
	AutoApproveNever AutoApproveSetting = "never"
	// AutoApproveAlways enables auto-approval
	AutoApproveAlways AutoApproveSetting = "always"
	// AutoApproveNoChanges enables auto-approval if there were no changes found in the diff
	AutoApproveNoChanges AutoApproveSetting = "if-no-changes"

	ApplyStrategyServer = "server"
	ApplyStrategyClient = "client"
)

type DeleteOpts added in v0.12.0

type DeleteOpts struct {
	ApplyBaseOpts
}

DeleteOpts specify additional properties for the Delete operation

type DiffBaseOpts added in v0.24.0

type DiffBaseOpts struct {
	// Color controls color output
	Color string
}

type DiffOpts added in v0.12.0

type DiffOpts struct {
	DiffBaseOpts
	Opts

	// Strategy must be one of "native", "validate", "subset" or "server"
	Strategy string
	// Summarize prints a summary, instead of the actual diff
	Summarize bool
	// WithPrune includes objects to be deleted by prune command in the diff
	WithPrune bool
	// Exit with 0 even when differences are found
	ExitZero bool
}

DiffOpts specify additional properties for the Diff action

type ErrMultipleEnvs added in v0.13.0

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

ErrMultipleEnvs means that the given jsonnet has multiple Environment objects

func (ErrMultipleEnvs) Error added in v0.13.0

func (e ErrMultipleEnvs) Error() string

type ErrNoEnv added in v0.13.0

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

ErrNoEnv means that the given jsonnet has no Environment object This must not be fatal, some operations work without

func (ErrNoEnv) Error added in v0.13.0

func (e ErrNoEnv) Error() string

type ErrParallel added in v0.14.0

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

ErrParallel is an array of errors collected while processing in parallel

func (ErrParallel) Error added in v0.14.0

func (e ErrParallel) Error() string

type ErrorApplyStrategyUnknown added in v0.21.0

type ErrorApplyStrategyUnknown struct {
	Requested string
}

ErrorApplyStrategyUnknown occurs when an apply-strategy is requested that does not exist. Unlike ErrorDiffStrategyUnknown, this needs to be used before things reach the `kube.Apply` function.

func (ErrorApplyStrategyUnknown) Error added in v0.21.0

type ExportEnvOpts added in v0.14.0

type ExportEnvOpts struct {
	// formatting the filename based on the exported Kubernetes manifest
	Format string
	// extension of the filename
	Extension string
	// optional: options to parse Jsonnet
	Opts Opts
	// optional: filter environments based on labels
	Selector labels.Selector
	// optional: number of environments to process in parallel
	Parallelism int

	// What to do when exporting to an existing directory
	// - none: fail when directory is not empty
	// - fail-on-conflicts: fail when an exported file already exists
	// - replace-envs: delete files previously exported by the targeted envs and re-export them
	MergeStrategy ExportMergeStrategy
	// Environments (main.jsonnet files) that have been deleted since the last export.
	// This is used when using a merge strategy to delete the files of these deleted environments.
	MergeDeletedEnvs []string
}

ExportEnvOpts specify options on how to export environments

type ExportMergeStrategy added in v0.23.0

type ExportMergeStrategy string
const (
	ExportMergeStrategyNone          ExportMergeStrategy = ""
	ExportMergeStrategyFailConflicts ExportMergeStrategy = "fail-on-conflicts"
	ExportMergeStrategyReplaceEnvs   ExportMergeStrategy = "replace-envs"
)

type FindOpts added in v0.14.0

type FindOpts struct {
	JsonnetOpts
	Selector labels.Selector
}

FindOpts are optional arguments for FindEnvs

type FormatOpts added in v0.9.0

type FormatOpts struct {
	// Excludes are a list of globs to exclude files while searching for Jsonnet
	// files
	Excludes []glob.Glob

	// OutFn receives the formatted file and it's name. If left nil, the file
	// will be formatted in place.
	OutFn OutFn

	// PrintNames causes all filenames to be printed
	PrintNames bool
}

FormatOpts modify the behaviour of Format

type Info

type Info struct {
	Env       *v1alpha1.Environment
	Resources manifest.List
	Client    client.Info
}

Info holds information about a particular environment, including its Config, the individual resources of the desired state and also the status of the client.

func Status

func Status(baseDir string, opts Opts) (*Info, error)

Status returns information about the particular environment

type InlineLoader added in v0.14.0

type InlineLoader struct{}

InlineLoader loads an environment that is specified inline from within Jsonnet. The Jsonnet output is expected to hold a tanka.dev/Environment type, Kubernetes resources are expected at the `data` key of this very type

func (*InlineLoader) Eval added in v0.14.0

func (i *InlineLoader) Eval(path string, opts LoaderOpts) (interface{}, error)

func (*InlineLoader) List added in v0.14.0

func (i *InlineLoader) List(path string, opts LoaderOpts) ([]*v1alpha1.Environment, error)

func (*InlineLoader) Load added in v0.14.0

func (i *InlineLoader) Load(path string, opts LoaderOpts) (*v1alpha1.Environment, error)

func (*InlineLoader) Peek added in v0.14.0

func (i *InlineLoader) Peek(path string, opts LoaderOpts) (*v1alpha1.Environment, error)

type JsonnetOpts added in v0.12.0

type JsonnetOpts = jsonnet.Opts

type LoadResult added in v0.14.0

type LoadResult struct {
	Env       *v1alpha1.Environment
	Resources manifest.List
}

func Load added in v0.14.0

func Load(path string, opts Opts) (*LoadResult, error)

Load loads the Environment at `path`. It automatically detects whether to load inline or statically

func LoadManifests added in v0.14.0

func LoadManifests(env *v1alpha1.Environment, filters process.Matchers) (*LoadResult, error)

func (LoadResult) Connect added in v0.14.0

func (l LoadResult) Connect() (*kubernetes.Kubernetes, error)

type Loader added in v0.14.0

type Loader interface {
	// Load a single environment at path
	Load(path string, opts LoaderOpts) (*v1alpha1.Environment, error)

	// Peek only loads metadata and omits the actual resources
	Peek(path string, opts LoaderOpts) (*v1alpha1.Environment, error)

	// List returns metadata of all possible environments at path that can be
	// loaded
	List(path string, opts LoaderOpts) ([]*v1alpha1.Environment, error)

	// Eval returns the raw evaluated Jsonnet
	Eval(path string, opts LoaderOpts) (interface{}, error)
}

Loader is an abstraction over the process of loading Environments

func DetectLoader added in v0.14.0

func DetectLoader(path string) (Loader, error)

DetectLoader detects whether the environment is inline or static and picks the approriate loader

type LoaderOpts added in v0.14.0

type LoaderOpts struct {
	JsonnetOpts
	Name string
}

type Opts added in v0.12.0

type Opts struct {
	JsonnetOpts

	// Filters are used to optionally select a subset of the resources
	Filters process.Matchers

	// Name is used to extract a single environment from multiple environments
	Name string
}

Opts specify general, optional properties that apply to all actions

type OutFn added in v0.9.0

type OutFn func(name, content string) error

OutFn is a function that receives the formatted file for further action, like persisting to disc

type PruneOpts added in v0.12.0

type PruneOpts struct {
	ApplyBaseOpts
}

PruneOpts specify additional properties for the Prune action

type StaticLoader added in v0.14.0

type StaticLoader struct{}

StaticLoader loads an environment from a static file called `spec.json`. Jsonnet is evaluated as normal

func (*StaticLoader) Eval added in v0.14.0

func (s *StaticLoader) Eval(path string, opts LoaderOpts) (interface{}, error)

func (StaticLoader) List added in v0.14.0

func (s StaticLoader) List(path string, opts LoaderOpts) ([]*v1alpha1.Environment, error)

func (StaticLoader) Load added in v0.14.0

func (s StaticLoader) Load(path string, opts LoaderOpts) (*v1alpha1.Environment, error)

func (StaticLoader) Peek added in v0.14.0

Jump to

Keyboard shortcuts

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