func ReconcileFieldSetWithSchema(fieldset *fieldpath.Set, tv *TypedValue) (*fieldpath.Set, error)
ReconcileFieldSetWithSchema reconciles the a field set with any changes to the object's schema since the field set was written. Returns the reconciled field set, or nil of no changes were made to the field set.
Supports: - changing types from atomic to granular - changing types from granular to atomic
Comparison is the return value of a TypedValue.Compare() operation.
No field will appear in more than one of the three fieldsets. If all of the fieldsets are empty, then the objects must have been equal.
type Comparison struct { // Removed contains any fields removed by rhs (the right-hand-side // object in the comparison). Removed *fieldpath.Set // Modified contains fields present in both objects but different. Modified *fieldpath.Set // Added contains any fields added by rhs. Added *fieldpath.Set }
func (c *Comparison) ExcludeFields(fields *fieldpath.Set) *Comparison
ExcludeFields fields from the compare recursively removes the fields from the entire comparison
func (c *Comparison) IsSame() bool
IsSame returns true if the comparison returned no changes (the two compared objects are similar).
func (c *Comparison) String() string
String returns a human readable version of the comparison.
ParseableType allows for easy production of typed objects.
type ParseableType struct { TypeRef schema.TypeRef Schema *schema.Schema }
DeducedParseableType is a ParseableType that deduces the type from the content of the object.
var DeducedParseableType ParseableType = createOrDie(YAMLObject(`types: - name: __untyped_atomic_ scalar: untyped list: elementType: namedType: __untyped_atomic_ elementRelationship: atomic map: elementType: namedType: __untyped_atomic_ elementRelationship: atomic - name: __untyped_deduced_ scalar: untyped list: elementType: namedType: __untyped_atomic_ elementRelationship: atomic map: elementType: namedType: __untyped_deduced_ elementRelationship: separable `)).Type("__untyped_deduced_")
func (p ParseableType) FromStructured(in interface{}, opts ...ValidationOptions) (*TypedValue, error)
FromStructured converts a go "interface{}" type, typically an structured object in Kubernetes, to a TypedValue. It will return an error if the resulting object fails schema validation. The provided "interface{}" value must be a pointer so that the value can be modified via reflection. The provided "interface{}" may contain structs and types that are converted to Values by the jsonMarshaler interface.
func (p ParseableType) FromUnstructured(in interface{}, opts ...ValidationOptions) (*TypedValue, error)
FromUnstructured converts a go "interface{}" type, typically an unstructured object in Kubernetes world, to a TypedValue. It returns an error if the resulting object fails schema validation. The provided interface{} must be one of: map[string]interface{}, map[interface{}]interface{}, []interface{}, int types, float types, string or boolean. Nested interface{} must also be one of these types.
func (p ParseableType) FromYAML(object YAMLObject, opts ...ValidationOptions) (*TypedValue, error)
FromYAML parses a yaml string into an object with the current schema and the type "typename" or an error if validation fails.
func (p ParseableType) IsValid() bool
IsValid return true if p's schema and typename are valid.
Parser implements YAMLParser and allows introspecting the schema.
type Parser struct { Schema schema.Schema }
func NewParser(schema YAMLObject) (*Parser, error)
NewParser will build a YAMLParser from a schema. The schema is validated.
func (p *Parser) Type(name string) ParseableType
Type returns a helper which can produce objects of the given type. Any errors are deferred until a further function is called.
func (p *Parser) TypeNames() (names []string)
TypeNames returns a list of types this parser understands.
TypedValue is a value of some specific type.
type TypedValue struct {
// contains filtered or unexported fields
}
func AsTyped(v value.Value, s *schema.Schema, typeRef schema.TypeRef, opts ...ValidationOptions) (*TypedValue, error)
AsTyped accepts a value and a type and returns a TypedValue. 'v' must have type 'typeName' in the schema. An error is returned if the v doesn't conform to the schema.
func AsTypedUnvalidated(v value.Value, s *schema.Schema, typeRef schema.TypeRef) *TypedValue
AsTypeUnvalidated is just like AsTyped, but doesn't validate that the type conforms to the schema, for cases where that has already been checked or where you're going to call a method that validates as a side-effect (like ToFieldSet).
Deprecated: This function was initially created because validation was expensive. Now that this has been solved, objects should always be created as validated, using `AsTyped`.
func (tv TypedValue) AsValue() value.Value
AsValue removes the type from the TypedValue and only keeps the value.
func (tv TypedValue) Compare(rhs *TypedValue) (c *Comparison, err error)
Compare compares the two objects. See the comments on the `Comparison` struct for details on the return value.
tv and rhs must both be of the same type (their Schema and TypeRef must match), or an error will be returned. Validation errors will be returned if the objects don't conform to the schema.
func (tv TypedValue) Empty() *TypedValue
func (tv TypedValue) ExtractItems(items *fieldpath.Set) *TypedValue
ExtractItems returns a value with only the provided list or map items extracted from the value.
func (tv TypedValue) Merge(pso *TypedValue) (*TypedValue, error)
Merge returns the result of merging tv and pso ("partially specified object") together. Of note:
tv and pso must both be of the same type (their Schema and TypeRef must match), or an error will be returned. Validation errors will be returned if the objects don't conform to the schema.
func (tv TypedValue) RemoveItems(items *fieldpath.Set) *TypedValue
RemoveItems removes each provided list or map item from the value.
func (tv TypedValue) Schema() *schema.Schema
Schema gets the schema from the TypedValue.
func (tv TypedValue) ToFieldSet() (*fieldpath.Set, error)
ToFieldSet creates a set containing every leaf field and item mentioned, or validation errors, if any were encountered.
func (tv TypedValue) TypeRef() schema.TypeRef
TypeRef is the type of the value.
func (tv TypedValue) Validate(opts ...ValidationOptions) error
Validate returns an error with a list of every spec violation.
ValidationError reports an error about a particular field
type ValidationError struct { Path string ErrorMessage string }
func (ve ValidationError) Error() string
Error returns a human readable error message.
ValidationErrors accumulates multiple validation error messages.
type ValidationErrors []ValidationError
func (errs ValidationErrors) Error() string
Error returns a human readable error message reporting each error in the list.
func (errs ValidationErrors) WithLazyPrefix(fn func() string) ValidationErrors
WithLazyPrefix prefixes all errors path with the given pathelement. This is useful when unwinding the stack on errors. Prefix is computed lazily only if there is an error.
func (errs ValidationErrors) WithPath(p string) ValidationErrors
Set the given path to all the validation errors.
func (errs ValidationErrors) WithPrefix(prefix string) ValidationErrors
WithPrefix prefixes all errors path with the given pathelement. This is useful when unwinding the stack on errors.
ValidationOptions is the list of all the options available when running the validation.
type ValidationOptions int
const ( // AllowDuplicates means that sets and associative lists can have duplicate similar items. AllowDuplicates ValidationOptions = iota )
YAMLObject is an object encoded in YAML.
type YAMLObject string