mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 19:52:42 +00:00
Add documentation and tests to conversion.
This commit is contained in:
@@ -28,12 +28,12 @@ import (
|
||||
// s.InternalVersion type before being returned. Decode will refuse to decode
|
||||
// objects without a version, because that's probably an error.
|
||||
func (s *Scheme) Decode(data []byte) (interface{}, error) {
|
||||
version, kind, err := s.DataAPIVersionAndKind(data)
|
||||
version, kind, err := s.DataVersionAndKind(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if version == "" {
|
||||
return nil, fmt.Errorf("API Version not set in '%s'", string(data))
|
||||
return nil, fmt.Errorf("version not set in '%s'", string(data))
|
||||
}
|
||||
obj, err := s.NewObject(version, kind)
|
||||
if err != nil {
|
||||
@@ -47,8 +47,7 @@ func (s *Scheme) Decode(data []byte) (interface{}, error) {
|
||||
}
|
||||
|
||||
// Version and Kind should be blank in memory.
|
||||
blankVersionAndKind := s.MetaInsertionFactory.Create("", "")
|
||||
err = s.converter.Convert(blankVersionAndKind, obj, SourceToDest|IgnoreMissingFields|AllowDifferentFieldNames)
|
||||
err = s.SetVersionAndKind("", "", obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -71,14 +70,14 @@ func (s *Scheme) Decode(data []byte) (interface{}, error) {
|
||||
// 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.
|
||||
// If obj's APIVersion doesn't match that in data, an attempt will be made to convert
|
||||
// If obj's version doesn't match that in data, an attempt will be made to convert
|
||||
// data into obj's version.
|
||||
func (s *Scheme) DecodeInto(data []byte, obj interface{}) error {
|
||||
dataVersion, dataKind, err := s.DataAPIVersionAndKind(data)
|
||||
dataVersion, dataKind, err := s.DataVersionAndKind(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
objVersion, objKind, err := s.ObjectAPIVersionAndKind(obj)
|
||||
objVersion, objKind, err := s.ObjectVersionAndKind(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,10 +119,5 @@ func (s *Scheme) DecodeInto(data []byte, obj interface{}) error {
|
||||
}
|
||||
|
||||
// Version and Kind should be blank in memory.
|
||||
blankVersionAndKind := s.MetaInsertionFactory.Create("", "")
|
||||
err = s.converter.Convert(blankVersionAndKind, obj, SourceToDest|IgnoreMissingFields|AllowDifferentFieldNames)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return s.SetVersionAndKind("", "", obj)
|
||||
}
|
||||
|
Reference in New Issue
Block a user