kubernetes

package
v0.0.0-...-9c10a09 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKeyNotStringError

func NewKeyNotStringError(key interface{}) error

func NewRequiredKeyNotFoundError

func NewRequiredKeyNotFoundError(key string, path []string) error

NewRequiredKeyNotFoundError returns a new RequiredKeyNotFoundError

func NewUnknownFormatError

func NewUnknownFormatError(format string) error

func NewUnknownKeyError

func NewUnknownKeyError(key string) error

func NewUnknownSchemaError

func NewUnknownSchemaError(key string) error

NewUnknownSchemaError returns an UnknownSchemaError.

func NewUnknownTypeError

func NewUnknownTypeError(t interface{}) error

NewUnknownTypeError returns a new UnknownTypeError

func NewWrongTypeError

func NewWrongTypeError(k, expectedType string, v interface{}) error

func NewYamlPathError

func NewYamlPathError(path []string, value interface{}, err error) error

Types

type APIKeyer

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

APIKeyer can look up a schema key given the apiVersion and the kind.

func NewAPIKeyer

func NewAPIKeyer(ns, suffix string) *APIKeyer

NewAPIKeyer returns an APIKeyer that finds keys with a common prefix.

func (*APIKeyer) APIKey

func (g *APIKeyer) APIKey(apiVersion, kind string) string

APIKey returns the key of the API object as listed in the swagger definition.

type AdditionalProperties

type AdditionalProperties struct {
	// Type will almost always be a string
	Type string
}

AdditionalProperties define the type found in objects. Kubernetes only uses string:string dicts, but this might break on more advanced use cases.

type GroupVersionKind

type GroupVersionKind struct {
	// Group is the group such as v1, apps, etc.
	Group string
	// Kind is the type of object such as Deployment or Pod.
	Kind string
	// Version is the API version such as v1, v1alpha3, v1beta2.
	Version string
}

GroupVersionKind is the gvk of kubernetes schema.

type Initializers

type Initializers struct {
	// Description is a description of the initializers.
	Description string
	// Type is the type of initializers, this is always an array.
	Type string
	// Items are the actual list of initializers.
	Items *Items
	// TODO(chuckha) Can probably remove these two
	PatchMergeKey string `json:"x-kubernetes-patch-merge-key"`
	PatchStrategy string `json:"x-kubernetes-patch-strategy"`
}

Initializers are things that will run before a pod can start running. This is only used in two places, the object metadata and the initializersConfiguration object. See: https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#how-are-initializers-triggered

type Input

type Input struct {
	Kind       string
	APIVersion string
	Data       map[interface{}]interface{}
}

Input is the top level YAML document the system receives.

type Items

type Items struct {
	// Description is a description of the array of items.
	Description string
	// Type is the type of item in the array.
	Type string
	// Reference is the reference to the schema type of items stored in this array.
	Reference string `json:"$ref"`
	// Items can be an array of arrays of arrays of ...
	Items *Items
}

Items are the array of items when the type is "array".

type KeyNotStringError

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

func (*KeyNotStringError) Error

func (k *KeyNotStringError) Error() string

type Kind

type Kind struct {
	// Description describes what kind is, it's an resource in the API.
	Description string
	// Type is always a string in the Kind object.
	Type string
}

Kind is the kind we all know and love from ObjectMeta.

type Loader

type Loader struct{}

Loader defines a struct that can read data from a stream into an internal type.

func NewLoader

func NewLoader() *Loader

NewLoader returns a Loader.

func (*Loader) Load

func (l *Loader) Load(reader io.Reader) (*Input, error)

Load reads the input and returns the internal type representing the top level document that is properly cleaned.

type Metadata

type Metadata struct {
	// Description descries what metadata is.
	Description string
	// Reference is the key to the metadata schema.
	Reference string `json:"$ref"`
}

Metadata is a reference to the shared metadata schema.

type Property

type Property struct {
	// Description is the description of the property being defined.
	Description string
	// Type is a basic type like string, object, integer or array.
	Type string
	// Format is a sub type, such as string could be `byte` or integer could be `int64`.
	Format string
	// Items is required for array types. This tells us what types are inside the array.
	Items *Items
	// AdditionalProperties is an optional field for object types defining what kind of key/value pairs will be found on the object.
	// TODO(chuckha) make this a pointer type
	AdditionalProperties AdditionalProperties
	// Reference is a reference to another schema in our list of definitions.
	Reference string `json:"$ref"`
}

Property is a single property, or field, of a schema.

func (*Property) String

func (p *Property) String() string

String implements the Stringer interface and gives us a nice human readable output.

type RequiredKeyNotFoundError

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

RequiredKeyNotFoundError is an error representing a required schema key that is missing

func (*RequiredKeyNotFoundError) Error

func (r *RequiredKeyNotFoundError) Error() string

Error implements the error interface

func (*RequiredKeyNotFoundError) MarshalJSON

func (r *RequiredKeyNotFoundError) MarshalJSON() ([]byte, error)

MarshalJSON extracts the error since error is an interface

type Resolver

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

Resolver looks up a schema based on the schema key.

func NewResolver

func NewResolver(version string) (*Resolver, error)

NewResolver loads a swagger file, keeps track of the version and returns an instantiated resolver.

func (*Resolver) Resolve

func (r *Resolver) Resolve(schemaKey string) (*Schema, error)

func (*Resolver) Version

func (r *Resolver) Version() string

type Schema

type Schema struct {
	// Description is the description of the object that conforms to this schema.
	Description string
	// Required lists the required fields of this object.
	Required []string
	// Properties
	Properties map[string]*Property
	// Initializers are optional. TODO(chuckha) what are these actually?
	Initializers *Initializers
	// Kind is an optional field that describes the kind of object inside a list type
	Kind *Kind
	// Metadata is an optional field that contains a reference to some other schema.
	Metadata *Metadata
	// GVK is the GroupVersionKind from kubernetes.
	GVK []*GroupVersionKind `json:"x-kubernetes-group-version-kind"`
	// Type is when the object is actually a type rename  of a builtin (type X string)
	Type string
	// Format is the format of the type when Type is "string"
	Format string
}

Schema is a swagger schema. I'm sure there's a real definition somewhere but this gets everything this program needs.

type Swagger

type Swagger struct {
	Definitions map[string]*Schema
}

Swagger is a map of schema keys to schema objects loaded in from a swagger file.

type UnknownFormatError

type UnknownFormatError struct {
	Format string
}

func (*UnknownFormatError) Error

func (u *UnknownFormatError) Error() string

type UnknownKeyError

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

func (*UnknownKeyError) Error

func (u *UnknownKeyError) Error() string

type UnknownSchemaError

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

UnknownSchemaError means the resolver could not find the requested schema.

func (*UnknownSchemaError) Error

func (u *UnknownSchemaError) Error() string

Error implements error interface.

func (*UnknownSchemaError) MarshalJSON

func (u *UnknownSchemaError) MarshalJSON() ([]byte, error)

MarshalJSON is used for the json.Marshal call.

type UnknownTypeError

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

UnknownTypeError represents an unknown type in a value. Examples are when the schema expects a string but gets an integer.

func (*UnknownTypeError) Error

func (u *UnknownTypeError) Error() string

Error implements the error interface

type Validator

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

Validator knows enough to be able to validate a YAML document.

func NewValidator

func NewValidator(resolver resolver) *Validator

NewValidator returns an instantiated validator.

func (*Validator) Resolve

func (v *Validator) Resolve(schemaKey string) (*Schema, error)

Resolve wraps the internal resolver's resolve method.

func (*Validator) Validate

func (v *Validator) Validate(incoming map[interface{}]interface{}, schema *Schema) []error

Validate sees incoming data and validates it against the known schemas. This is recursive so it does a depth first search of all key/values. TODO(chuckha) turn this into a stack-based dfs search.

func (*Validator) Version

func (v *Validator) Version() string

Version wraps the internal resolver's version method.

type WrongTypeError

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

func (*WrongTypeError) Error

func (w *WrongTypeError) Error() string

type YamlPathError

type YamlPathError struct {
	Err   error
	Value interface{} `json:",omitempty"`
	Path  string
}

func (*YamlPathError) Error

func (y *YamlPathError) Error() string

func (*YamlPathError) MarshalJSON

func (y *YamlPathError) MarshalJSON() ([]byte, error)

MarshalJSON extracts the error since error is an interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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