Documentation ¶
Index ¶
- func IsInlineStruct(field *reflect.StructField) bool
- func IsZero(v reflect.Value) bool
- func WriteObject(obj runtime.Object, dst *hclwrite.Body) error
- type ObjectWalker
- func (w *ObjectWalker) Enter(l reflectwalk.Location) error
- func (w *ObjectWalker) Exit(l reflectwalk.Location) error
- func (w *ObjectWalker) Map(m reflect.Value) error
- func (w *ObjectWalker) MapElem(m, k, v reflect.Value) error
- func (w *ObjectWalker) Primitive(v reflect.Value) error
- func (w *ObjectWalker) ResourceName() string
- func (w *ObjectWalker) ResourceType() string
- func (w *ObjectWalker) Slice(v reflect.Value) error
- func (w *ObjectWalker) SliceElem(i int, v reflect.Value) error
- func (w *ObjectWalker) Struct(v reflect.Value) error
- func (w *ObjectWalker) StructField(field reflect.StructField, v reflect.Value) error
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"`
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 ¶
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 ¶
func (w *ObjectWalker) Exit(l reflectwalk.Location) error
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.