Introduce GroupVersioner for capturing desired target version

Convert single GV and lists of GVs into an interface that can handle
more complex scenarios (everything internal, nothing supported). Pass
the interface down into conversion.
This commit is contained in:
Clayton Coleman
2016-05-22 19:10:42 -04:00
parent 9d2a5fe5e8
commit 12a5eeea17
24 changed files with 617 additions and 332 deletions

View File

@@ -187,9 +187,14 @@ func (UnstructuredObjectConverter) Convert(in, out interface{}) error {
return nil
}
func (UnstructuredObjectConverter) ConvertToVersion(in Object, outVersion unversioned.GroupVersion) (Object, error) {
if gvk := in.GetObjectKind().GroupVersionKind(); gvk.GroupVersion() != outVersion {
return nil, errors.New("unstructured converter cannot convert versions")
func (UnstructuredObjectConverter) ConvertToVersion(in Object, target GroupVersioner) (Object, error) {
if kind := in.GetObjectKind().GroupVersionKind(); !kind.IsEmpty() {
gvk, ok := target.KindForGroupVersionKinds([]unversioned.GroupVersionKind{kind})
if !ok {
// TODO: should this be a typed error?
return nil, fmt.Errorf("%v is unstructured and is not suitable for converting to %q", kind, target)
}
in.GetObjectKind().SetGroupVersionKind(gvk)
}
return in, nil
}