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
- Variables
- func Apply(baseDir string, opts ApplyOpts) error
- func Delete(baseDir string, opts DeleteOpts) error
- func Diff(baseDir string, opts DiffOpts) (*string, error)
- func Eval(path string, opts Opts) (interface{}, error)
- func ExportEnvironments(envs []*v1alpha1.Environment, to string, opts *ExportEnvOpts) error
- func FindEnvs(path string, opts FindOpts) ([]*v1alpha1.Environment, error)
- func Format(filename string, content string) (string, error)
- func FormatFiles(fds []string, opts *FormatOpts) ([]string, error)
- func List(path string, opts Opts) ([]*v1alpha1.Environment, error)
- func LoadEnvironment(path string, opts Opts) (*v1alpha1.Environment, error)
- func Peek(path string, opts Opts) (*v1alpha1.Environment, error)
- func Prune(baseDir string, opts PruneOpts) error
- func Show(baseDir string, opts Opts) (manifest.List, error)
- type ApplyOpts
- type DeleteOpts
- type DiffOpts
- type ErrMultipleEnvs
- type ErrNoEnv
- type ErrParallel
- type ExportEnvOpts
- type FindOpts
- type FormatOpts
- type Info
- type InlineLoader
- func (i *InlineLoader) Eval(path string, opts LoaderOpts) (interface{}, error)
- func (i *InlineLoader) List(path string, opts LoaderOpts) ([]*v1alpha1.Environment, error)
- func (i *InlineLoader) Load(path string, opts LoaderOpts) (*v1alpha1.Environment, error)
- func (i *InlineLoader) Peek(path string, opts LoaderOpts) (*v1alpha1.Environment, error)
- type JsonnetOpts
- type LoadResult
- type Loader
- type LoaderOpts
- type Opts
- type OutFn
- type PruneOpts
- type StaticLoader
- func (s *StaticLoader) Eval(path string, opts LoaderOpts) (interface{}, error)
- func (s StaticLoader) List(path string, opts LoaderOpts) ([]*v1alpha1.Environment, error)
- func (s StaticLoader) Load(path string, opts LoaderOpts) (*v1alpha1.Environment, error)
- func (s StaticLoader) Peek(path string, opts LoaderOpts) (*v1alpha1.Environment, error)
Constants ¶
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.
const DEFAULT_DEV_VERSION = "dev"
DEFAULT_DEV_VERSION is the placeholder version used when no actual semver is provided using ldflags
const MetadataEvalScript = `` /* 546-byte string literal not displayed */
MetadataEvalScript finds the Environment object (without its .data object)
const MetadataSingleEnvEvalScript = `` /* 593-byte string literal not displayed */
MetadataSingleEnvEvalScript returns a Single Environment object
const PatternEvalScript = "main.%s"
const SingleEnvEvalScript = `` /* 508-byte string literal not displayed */
SingleEnvEvalScript returns a Single Environment object
Variables ¶
var CURRENT_VERSION = DEFAULT_DEV_VERSION
CURRENT_VERSION is the current version of the running Tanka code
Functions ¶
func Apply ¶
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 ¶
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 created using `diffstat(1)` is returned instead. The cluster information is retrieved from the environments `spec.json`. NOTE: This function requires on `diff(1)`, `kubectl(1)` and perhaps `diffstat(1)`
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
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 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
Types ¶
type ApplyOpts ¶ added in v0.12.0
type ApplyOpts struct { Opts // AutoApprove skips the interactive approval AutoApprove bool // DiffStrategy to use for printing the diff before approval DiffStrategy string // Force ignores any warnings kubectl might have Force bool // Validate set to false ignores invalid Kubernetes schemas Validate bool }
ApplyOpts specify additional properties for the Apply action
type DeleteOpts ¶ added in v0.12.0
type DeleteOpts struct { Opts // AutoApprove skips the interactive approval AutoApprove bool // Force ignores any warnings kubectl might have Force bool // Validate set to false ignores invalid Kubernetes schemas Validate bool }
DeleteOpts specify additional properties for the Delete operation
type DiffOpts ¶ added in v0.12.0
type DiffOpts struct { Opts // Strategy must be one of "native", "validate", or "subset" 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
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 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 // merge export with existing directory Merge bool // 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 }
ExportEnvOpts specify options on how to export environments
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 ¶
Info holds information about a particular environment, including its Config, the individual resources of the desired state and also the status of the client.
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 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
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
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 { Opts // AutoApprove skips the interactive approval AutoApprove bool // Force ignores any warnings kubectl might have Force bool }
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
func (s StaticLoader) Peek(path string, opts LoaderOpts) (*v1alpha1.Environment, error)