Documentation
¶
Overview ¶
Package codec provides a JSON/YAML codec for Manifests.
Usage:
// Decode one manifest from a JSON file. man, err := JSON.Decode(b).One() // Decode all of the manifests out of this file. manifests, err := YAML.Decode(b).All() err := YAML.Encode(filename).One("hello") // Encode multiple objects to one file (as separate docs). err := YAML.Encode(filename).All("one", "two", "three")
Index ¶
- Variables
- func SplitYAMLDocument(data []byte, atEOF bool) (advance int, token []byte, err error)
- type Codec
- type DecodeFunc
- type Decoder
- type Encoder
- type Metadata
- type Object
- func (m *Object) AddAnnotations(ann map[string]string) error
- func (m *Object) AddLabels(labels map[string]string) error
- func (m *Object) DaemonSet() (*v1beta1.DaemonSet, error)
- func (m *Object) Deployment() (*v1beta1.Deployment, error)
- func (m *Object) HorizontalPodAutoscaler() (*v1beta1.HorizontalPodAutoscaler, error)
- func (m *Object) Ingress() (*v1beta1.Ingress, error)
- func (m *Object) JSON() ([]byte, error)
- func (m *Object) Job() (*v1beta1.Job, error)
- func (m *Object) Meta() (*Metadata, error)
- func (m *Object) Namespace() (*v1.Namespace, error)
- func (m *Object) Object(v interface{}) error
- func (m *Object) PersistentVolume() (*v1.PersistentVolume, error)
- func (m *Object) Pod() (*v1.Pod, error)
- func (m *Object) RC() (*v1.ReplicationController, error)
- func (m *Object) Ref() (*v1.ObjectReference, error)
- func (m *Object) Secret() (*v1.Secret, error)
- func (m *Object) Service() (*v1.Service, error)
- func (m *Object) ServiceAccount() (*v1.ServiceAccount, error)
- func (m *Object) YAML() ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
var JSON jsonCodec
JSON is the default JSON encoder/decoder.
var YAML yamlCodec
YAML is the default YAML encoder/decoder.
Functions ¶
func SplitYAMLDocument ¶
SplitYAMLDocument is a bufio.SplitFunc for splitting a YAML document into individual documents.
This is from Kubernetes' 'pkg/util/yaml'.splitYAMLDocument, which is unfortunately not exported.
Types ¶
type DecodeFunc ¶
DecodeFunc is a func that can decode bytes into an interface.
type Decoder ¶
type Decoder interface { // Get one object from a file. One() (*Object, error) // Get all objects from a file. All() ([]*Object, error) }
Decoder decodes an encoded representation into one or many objects.
type Encoder ¶
type Encoder interface { // Write one object to one file One(interface{}) error // Write all objects to one file All(...interface{}) error }
Encoder describes something capable of encoding to a given format.
An Encoder should be able to encode one object to an output stream, or many objects to an output stream.
For example, a single YAML file can contain multiple YAML objects, and a single JSONList file can contain many JSON objects.
type Metadata ¶
type Metadata struct { unversioned.TypeMeta `json:",inline"` api.ObjectMeta `json:"metadata,omitempty"` }
Metadata provides just the basic metadata fields of an object.
It contains more data than an ObjectReference, since it includes standard metadata values like Name, Labels, and Annotations.
This is a readable structure, but should not be used to write changes.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object describes some discrete instance of a Kind.
Objects are tracked as raw []byte data. They can be decoded into a variety of forms, but the decoded version is never stored on the object itself.
Mutators like AddLabels typically decode the object, mutate it, and then re-encode it. The reason for this is that those operations can assume a very simply and generic type and trust that the decoder/encoder pair can preserve structure.
Some operations, like Ref() and Meta(), can produce structured subsets of the original data, but will not preserve the entire object. These can be used to read data easily, but should not be used to mutate an object.
Operations like JSON() and YAML() will decode the data into a generic form and then re-encode the data.
func (*Object) AddAnnotations ¶
AddAnnotations adds the map of annotations to an object, regardless of kind.
This looks for a top-level metadata entry and adds annotations inside of that.
See the notes on AddLabels for performance implications.
func (*Object) AddLabels ¶
AddLabels adds the map of labels to an object, regardless of kind.
This looks for a top-level metadata entry, and adds labels there. Because this decodes the object into a generic format and then re-encodes it, this is a more costly operation than unmarshaling into a specific type and mutating the properties. However, it works on all types.
func (*Object) Deployment ¶
func (m *Object) Deployment() (*v1beta1.Deployment, error)
Deployment decodes a manifest into a Deployment.
func (*Object) HorizontalPodAutoscaler ¶
func (m *Object) HorizontalPodAutoscaler() (*v1beta1.HorizontalPodAutoscaler, error)
HorizontalPodAutoscaler decodes a manifest into a HorizontalPodAutoscaler.
func (*Object) Meta ¶
Meta returns a *Metadata
This contains more information than an ObjectReference. It is valid for the core Kubernetes kinds, but is not guranteed to work for all possible kinds.
func (*Object) Object ¶
Object decodes the manifest into the given object.
You can use ObjectReference.Kind to figure out what kind of object to decode into.
There are several shortcut methods that will allow you to decode directly to one of the common types, like Pod(), RC(), and Service().
func (*Object) PersistentVolume ¶
func (m *Object) PersistentVolume() (*v1.PersistentVolume, error)
PersistentVolume decodes a manifest into a PersistentVolume
func (*Object) RC ¶
func (m *Object) RC() (*v1.ReplicationController, error)
RC decodes a manifest into a ReplicationController.
func (*Object) Ref ¶
func (m *Object) Ref() (*v1.ObjectReference, error)
Ref returns an ObjectReference with basic information about the object.
This can be used to perform simple operations, as well as to instrospect a record enough to know how to unmarshal it.
func (*Object) ServiceAccount ¶
func (m *Object) ServiceAccount() (*v1.ServiceAccount, error)
ServiceAccount decodes a manifest into a ServiceAccount.