hclwriter

package
v0.0.0-...-8549fe5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInlineStruct

func IsInlineStruct(field *reflect.StructField) bool

IsInlineStruct looks at the json tag of the given StructField, to determine if it has been marked as "inline" e.g. someField string `json:",inline"`

func IsZero

func IsZero(v reflect.Value) bool

IsZero reports whether is considered the zero / empty / unset value fo the type

func WriteObject

func WriteObject(obj runtime.Object, dst *hclwrite.Body) error

WriteObject converts a Kubernetes runtime.Object to HCL

Types

type ObjectWalker

type ObjectWalker struct {
	// The Kubernetes API Object to be walked
	RuntimeObject runtime.Object
	// contains filtered or unexported fields
}

ObjectWalker implements reflectwalk.Walker interfaces It's used to "walk" the Kubernetes API Objects structure and generate an HCL document based on the values defined.

func NewObjectWalker

func NewObjectWalker(obj runtime.Object, dst *hclwrite.Body) (*ObjectWalker, error)

NewObjectWalker returns a new ObjectWalker object dst is the hclwrite.Body where HCL blocks will be appended.

func (*ObjectWalker) Enter

func (w *ObjectWalker) Enter(l reflectwalk.Location) error

Enter is called by reflectwalk.Walk each time we enter a level

func (*ObjectWalker) Exit

Exit is called by reflectwalk each time it exits from a reflectwalk.Location

func (*ObjectWalker) Map

func (w *ObjectWalker) Map(m reflect.Value) error

Map is called everytime reflectwalk enters a Map Golang maps are usally output as HCL maps, but sometimes as sub-blocks.

func (*ObjectWalker) MapElem

func (w *ObjectWalker) MapElem(m, k, v reflect.Value) error

MapElem is called every time reflectwalk enters a Map element

normalize the element key, and write element value to the HCL block as an attribute value

func (*ObjectWalker) Primitive

func (w *ObjectWalker) Primitive(v reflect.Value) error

Primitive is called whenever reflectwalk visits a Primitive value. If it's not a zero value, add an Attribute to the current HCL Block.

func (*ObjectWalker) ResourceName

func (w *ObjectWalker) ResourceName() string

ResourceName returns the Terraform Resource name for the Kubernetes Object

func (*ObjectWalker) ResourceType

func (w *ObjectWalker) ResourceType() string

ResourceType returns the Terraform Resource type for the Kubernetes Object

func (*ObjectWalker) Slice

func (w *ObjectWalker) Slice(v reflect.Value) error

Slice implements reflectwalk.SliceWalker interface, and is called each time reflectwalk enters a Slice Golang slices need to be converted to HCL in one of two ways:

*1 - a simple list of primitive values:

list_name = ["foo", "bar", "baz"]

*2 - a list of complex objects that will be rendered as repeating HCL blocks

container {
	name  = "blah"
	image = "nginx"
}

container {
	name  = "foo"
	image = "sidecar"
}

For the second case, each time we process a SliceElem we need to use the StructField data of the Slice itself, and not the slice elem.

func (*ObjectWalker) SliceElem

func (w *ObjectWalker) SliceElem(i int, v reflect.Value) error

SliceElem implements reflectwalk.SliceWalker interface

func (*ObjectWalker) Struct

func (w *ObjectWalker) Struct(v reflect.Value) error

Struct is called every time reflectwalk enters a Struct

func (*ObjectWalker) StructField

func (w *ObjectWalker) StructField(field reflect.StructField, v reflect.Value) error

StructField is called by reflectwalk whenever it enters a field of a struct. We ignore Invalid fields, or some API fields we don't need to convert to HCL. The rest are added to the StuctField stack so we have access to the StructField data in other funcs.

Jump to

Keyboard shortcuts

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