utils

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset added in v0.8.0

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir added in v0.8.0

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo added in v0.8.0

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames added in v0.8.0

func AssetNames() []string

AssetNames returns the names of the assets.

func ClientForResource added in v0.5.0

func ClientForResource(pool dynamic.ClientPool, disco discovery.DiscoveryInterface, obj runtime.Object, defNs string) (dynamic.ResourceInterface, error)

ClientForResource returns the ResourceClient for a given object

func DependencyOrder added in v0.2.0

func DependencyOrder(disco ServerResourcesOpenAPISchema, list []*unstructured.Unstructured) (sort.Interface, error)

DependencyOrder is a `sort.Interface` that *best-effort* sorts the objects so that known dependencies appear earlier in the list. The idea is to prevent *some* of the "crash-restart" loops when creating inter-dependent resources.

func FlattenToV1

func FlattenToV1(objs []runtime.Object) []*unstructured.Unstructured

FlattenToV1 expands any List-type objects into their members, and cooerces everything to v1.Unstructured. Panics if coercion encounters an unexpected object type.

func FqName added in v0.5.0

func FqName(o metav1.Object) string

FqName returns "namespace.name"

func MakeUniversalImporter added in v0.8.0

func MakeUniversalImporter(searchUrls []*url.URL) jsonnet.Importer

MakeUniversalImporter creates an importer that handles resolving imports from the filesystem and http/s.

In addition to the standard importer, supports:

  • URLs in import statements
  • URLs in library search paths

A real-world example:

func MustAsset added in v0.8.0

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewMemcachedDiscoveryClient

func NewMemcachedDiscoveryClient(cl discovery.DiscoveryInterface) discovery.CachedDiscoveryInterface

NewMemcachedDiscoveryClient creates a new DiscoveryClient that caches results in memory

func Read

func Read(vm *jsonnet.VM, path string) ([]runtime.Object, error)

Read fetches and decodes K8s objects by path. TODO: Replace this with something supporting more sophisticated content negotiation.

func RegisterNativeFuncs added in v0.3.0

func RegisterNativeFuncs(vm *jsonnet.VM, resolver Resolver)

RegisterNativeFuncs adds kubecfg's native jsonnet functions to provided VM

func ResourceNameFor added in v0.5.0

func ResourceNameFor(disco discovery.ServerResourcesInterface, o runtime.Object) string

ResourceNameFor returns a lowercase plural form of a type, for human messages. Returns lowercased kind if discovery lookup fails.

func RestoreAsset added in v0.8.0

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets added in v0.8.0

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SetMetaDataAnnotation added in v0.5.0

func SetMetaDataAnnotation(obj metav1.Object, key, value string)

SetMetaDataAnnotation sets an annotation value

func SetMetaDataLabel added in v0.9.0

func SetMetaDataLabel(obj metav1.Object, key, value string)

SetMetaDataLabel sets an annotation value

Types

type AlphabeticalOrder added in v0.2.0

type AlphabeticalOrder []*unstructured.Unstructured

AlphabeticalOrder is a `sort.Interface` that sorts the objects by namespace/name/kind alphabetical order

func (AlphabeticalOrder) Len added in v0.2.0

func (l AlphabeticalOrder) Len() int

func (AlphabeticalOrder) Less added in v0.2.0

func (l AlphabeticalOrder) Less(i, j int) bool

func (AlphabeticalOrder) Swap added in v0.2.0

func (l AlphabeticalOrder) Swap(i, j int)

type ImageName added in v0.3.0

type ImageName struct {
	// eg: "myregistryhost:5000/fedora/httpd:version1.0"
	Registry   string // "myregistryhost:5000"
	Repository string // "fedora"
	Name       string // "httpd"
	Tag        string // "version1.0"
	Digest     string
}

ImageName represents the parts of a docker image name

func ParseImageName added in v0.3.0

func ParseImageName(image string) (ImageName, error)

ParseImageName parses a docker image into an ImageName struct.

func (ImageName) RegistryRepoName added in v0.3.0

func (n ImageName) RegistryRepoName() string

RegistryRepoName returns the "repository" as used in the registry URL

func (ImageName) RegistryURL added in v0.3.0

func (n ImageName) RegistryURL() string

RegistryURL returns the deduced base URL of the registry for this image

func (ImageName) String added in v0.3.0

func (n ImageName) String() string

String implements the Stringer interface

type OpenAPISchema added in v0.9.0

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

OpenAPISchema represents an OpenAPI schema for a given GroupVersionKind.

func NewOpenAPISchemaFor added in v0.9.0

func NewOpenAPISchemaFor(delegate discovery.OpenAPISchemaInterface, gvk schema.GroupVersionKind) (*OpenAPISchema, error)

NewOpenAPISchemaFor returns the OpenAPISchema object ready to validate objects of given GroupVersion

func (*OpenAPISchema) Validate added in v0.9.0

func (s *OpenAPISchema) Validate(obj *unstructured.Unstructured) []error

Validate is the primary entrypoint into this class

type Resolver added in v0.3.0

type Resolver interface {
	Resolve(image *ImageName) error
}

Resolver is able to resolve docker image names into more specific forms

func NewIdentityResolver added in v0.3.0

func NewIdentityResolver() Resolver

NewIdentityResolver returns a resolver that does only trivial :latest canonicalisation

func NewRegistryResolver added in v0.3.0

func NewRegistryResolver(opt registry.Opt) Resolver

NewRegistryResolver returns a resolver that looks up a docker registry to resolve digests

type ServerResourcesOpenAPISchema added in v0.9.0

type ServerResourcesOpenAPISchema interface {
	discovery.ServerResourcesInterface
	discovery.OpenAPISchemaInterface
}

A subset of discovery.DiscoveryInterface

type ServerVersion added in v0.4.0

type ServerVersion struct {
	Major int
	Minor int
}

ServerVersion captures k8s major.minor version in a parsed form

func FetchVersion added in v0.4.0

func FetchVersion(v discovery.ServerVersionInterface) (ret ServerVersion, err error)

FetchVersion fetches version information from discovery client, and parses

func GetDefaultVersion added in v0.9.0

func GetDefaultVersion() ServerVersion

GetDefaultVersion returns a default server version. This value will be updated periodically to match a current/popular version corresponding to the age of this code Current default version: 1.8

func ParseVersion added in v0.4.0

func ParseVersion(v *version.Info) (ServerVersion, error)

ParseVersion parses version.Info into a ServerVersion struct

func (ServerVersion) Compare added in v0.4.0

func (v ServerVersion) Compare(major, minor int) int

Compare returns -1/0/+1 iff v is less than / equal / greater than major.minor

func (ServerVersion) String added in v0.4.0

func (v ServerVersion) String() string

Jump to

Keyboard shortcuts

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