@@ -102,12 +102,28 @@ func (p ParseableType) FromYAML(object YAMLObject) (*TypedValue, error) {
102
102
return AsTyped (value .NewValueInterface (v ), p .Schema , p .TypeRef )
103
103
}
104
104
105
- // FromUnstructured converts a go interface to a TypedValue. It will return an
105
+ // FromUnstructured converts a go "interface{}" type, typically an
106
+ // unstructured object in Kubernetes world. to a TypedValue. It returns an
106
107
// error if the resulting object fails schema validation.
108
+ // The provided interface{} must be one of: map[string]interface{},
109
+ // map[interface{}]interface{}, []interface{}, int types, float types,
110
+ // string or boolean. Nested interface{} must also be one of these types.
107
111
func (p ParseableType ) FromUnstructured (in interface {}) (* TypedValue , error ) {
108
112
return AsTyped (value .NewValueInterface (in ), p .Schema , p .TypeRef )
109
113
}
110
114
115
+ // FromStructured converts a go "interface{}" type, typically an structured object in
116
+ // Kubernetes, to a TypedValue. It will return an
117
+ // error if the resulting object fails schema validation.
118
+ // The provided "interface{}" may contain structs and types that are converted to Values
119
+ // // by the jsonMarshaler interface.
120
+ func (p ParseableType ) FromStructured (in interface {}) (* TypedValue , error ) {
121
+ v , err := value .NewValueReflect (in )
122
+ if err != nil {
123
+ return nil , fmt .Errorf ("error creating struct value reflector: %v" , err )
124
+ }
125
+ return AsTyped (v , p .Schema , p .TypeRef )
126
+ }
111
127
// DeducedParseableType is a ParseableType that deduces the type from
112
128
// the content of the object.
113
129
var DeducedParseableType ParseableType = createOrDie (YAMLObject (`types:
0 commit comments