mappings

package
v1.118.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AssertEnabled = true

AssertEnabled is true if we are running with assertions enabled. Like traditional assertions, assertions are runtime checks that will panic the program, but we only run those checks if assertion checks are enabled.

Functions

func AssertFail

func AssertFail()

Types

type Field

type Field interface {
	// ID returns the unique ID of the field, typically the value used in JSON serialization.
	ID() FieldID

	// Type returns the type of the field, using our reflectType mapper.
	Type() *reflectType
	// contains filtered or unexported methods
}

Field represents a field in an object type.

type FieldID

type FieldID string

FieldID is the unique identifier for a field within an object type.

type FieldMapping

type FieldMapping interface {
}

FieldMapping is the base interface for per-field mappings.

func Ignore

func Ignore(id string) FieldMapping

Ignore fields should not be mapped automatically. They are different from TODO fields, in that we have actively determined they should not be mapped.

func Spec

func Spec(id string) FieldMapping

Status fields are a proto top-level field but nested under Spec in KRM.

func Status

func Status(id string) FieldMapping

Status fields are a proto top-level field but nested under Status in KRM.

type Mapping

type Mapping struct {
	ResourceCloudType *reflectType
	ResourceKRMType   *reflectType

	Mappings []typeMapping
}

Mapping holds the logic for mapping a particular resource, including sub-object types.

func (*Mapping) Map

func (m *Mapping) Map(in any, out any) error

Map will convert an object from "in" to "out", mapping object subfields recurisvely.

func (*Mapping) Validate

func (m *Mapping) Validate() []ValidationError

Validate will perform some checks on the mapping. We always look for invalid mappings, where (for example) the field does not exist on one or both sides. If CHECK_COVERAGE is passed, it will look for missing mappings.

type MappingBuilder

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

MappingBuilder allows for fluid construction of a Mapping

func NewMapping

func NewMapping(cloudObj any, krmObj any, fields ...FieldMapping) *MappingBuilder

NewMapping starts a new mappingBuilder, for converting proto <-> KRM.

func (*MappingBuilder) Build

func (b *MappingBuilder) Build() (*Mapping, error)

Build "finalizes" the mapping, and returns the constructed mapping.

func (*MappingBuilder) MapNested

func (b *MappingBuilder) MapNested(cloudObj any, krmObj any, fields ...FieldMapping) *MappingBuilder

MapNested describes how a nested subobject should be mapped, when it is encountered in this context.

func (*MappingBuilder) MustBuild

func (b *MappingBuilder) MustBuild() *Mapping

MustBuild is like Build, but panics on error.

type ValidationError

type ValidationError struct {
	Message  string
	Proposal string
}

ValidationError is the type for one of our validation findings.

Jump to

Keyboard shortcuts

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