README

Manifestival

Manipulate unstructured Kubernetes resources loaded from a manifest

Build

dep ensure -v
go test -v
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(pathname string, recursive bool) ([]unstructured.Unstructured, error)

Parse parses YAML files into Unstructured objects.

It supports 5 cases today: 1. pathname = path to a file --> parses that file. 2. pathname = path to a directory, recursive = false --> parses all files in

that directory.

3. pathname = path to a directory, recursive = true --> parses all files in

that directory and it's descendants

4. pathname = url --> fetches the contents of that URL and parses them as YAML. 5. pathname = combination of all previous cases, the string can contain

multiple records (file, directory or url) separated by comma

func UpdateChanged

func UpdateChanged(src, tgt map[string]interface{}) bool

UpdateChanged recursively merges JSON-style values in `src` into `tgt`.

We need to preserve the top-level target keys, specifically 'metadata.resourceVersion', 'spec.clusterIP', and any existing entries in a ConfigMap's 'data' field. So we only overwrite fields set in our src resource. TODO: Use Patch instead

Types

type Manifest

type Manifest struct {
	Resources []unstructured.Unstructured
	// contains filtered or unexported fields
}

Manifest tracks a set of concrete resources which should be managed as a group using a Kubernetes client provided by `NewManifest`.

func NewManifest

func NewManifest(pathname string, recursive bool, client client.Client) (Manifest, error)

NewManifest creates a Manifest from a comma-separated set of yaml files or directories (and subdirectories if the `recursive` option is set). The Manifest will be evaluated using the supplied `client` against a particular Kubernetes apiserver.

func (*Manifest) Apply

func (f *Manifest) Apply(spec *unstructured.Unstructured) error

Apply updates or creates a particular resource, which does not need to be part of `Resources`, and will not be tracked.

func (*Manifest) ApplyAll

func (f *Manifest) ApplyAll() error

ApplyAll updates or creates all resources in the manifest.

func (*Manifest) Delete

func (f *Manifest) Delete(spec *unstructured.Unstructured, opts ...client.DeleteOption) error

Delete removes the specified objects, which do not need to be registered as `Resources` in the Manifest.

func (*Manifest) DeleteAll

func (f *Manifest) DeleteAll(opts ...client.DeleteOption) error

DeleteAll removes all tracked `Resources` in the Manifest.

func (*Manifest) Get

Get collects a full resource body (or `nil`) from a partial resource supplied in `spec`.

func (*Manifest) Transform

func (f *Manifest) Transform(fns ...Transformer) error

Transform applies an ordered set of Transformer functions to the `Resources` in this Manifest. If an error occurs, no resources are transformed.

type Manifestival

type Manifestival interface {
	// Either updates or creates all resources in the manifest
	ApplyAll() error
	// Updates or creates a particular resource
	Apply(*unstructured.Unstructured) error
	// Deletes all resources in the manifest
	DeleteAll(opts ...client.DeleteOption) error
	// Deletes a particular resource
	Delete(spec *unstructured.Unstructured, opts ...client.DeleteOption) error
	// Returns a copy of the resource from the api server, nil if not found
	Get(spec *unstructured.Unstructured) (*unstructured.Unstructured, error)
	// Transforms the resources within a Manifest
	Transform(fns ...Transformer) error
}

Manifestival allows group application of a set of Kubernetes resources (typically, a set of YAML files, aka a manifest) against a Kubernetes apiserver.

type Owner

type Owner interface {
	v1.Object
	schema.ObjectKind
}

Owner is a partial Kubernetes metadata schema.

type Transformer

type Transformer func(u *unstructured.Unstructured) error

Transformer transforms a resource from the manifest in place.

func InjectNamespace

func InjectNamespace(ns string) Transformer

InjectNamespace creates a Transformer which adds a namespace to existing resources if appropriate. We assume all resources in the manifest live in the same namespace.

func InjectOwner

func InjectOwner(owner Owner) Transformer

InjectOwner creates a Tranformer which adds an OwnerReference pointing to `owner` to namespace-scoped objects.