Adding a way to decode to a specified version.

This is largely needed as a way to get a versioned client without
requiring everyone to switch to versioned types at once.
This commit is contained in:
Kris Rousey
2015-08-07 12:45:20 -07:00
parent 213e7a8ab6
commit 6e64a63a84
7 changed files with 49 additions and 7 deletions

View File

@@ -446,6 +446,19 @@ func (s *Scheme) Decode(data []byte) (Object, error) {
return obj.(Object), nil
}
// DecodeToVersion converts a YAML or JSON string back into a pointer to an api
// object. Deduces the type based upon the APIVersion and Kind fields, which
// are set by Encode. Only versioned objects (APIVersion != "") are
// accepted. The object will be converted into the in-memory versioned type
// requested before being returned.
func (s *Scheme) DecodeToVersion(data []byte, version string) (Object, error) {
obj, err := s.raw.DecodeToVersion(data, version)
if err != nil {
return nil, err
}
return obj.(Object), nil
}
// DecodeInto parses a YAML or JSON string and stores it in obj. Returns an error
// if data.Kind is set and doesn't match the type of obj. Obj should be a
// pointer to an api type.