mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Split AsVersionedObjects so it can be reused
This commit is contained in:
parent
9a764b764b
commit
1707c5d28c
@ -207,6 +207,29 @@ func (r *Result) Watch(resourceVersion string) (watch.Interface, error) {
|
|||||||
// version will be preferred as the conversion target, but the Object's mapping version will be
|
// version will be preferred as the conversion target, but the Object's mapping version will be
|
||||||
// used if that version is not present.
|
// used if that version is not present.
|
||||||
func AsVersionedObject(infos []*Info, forceList bool, version string) (runtime.Object, error) {
|
func AsVersionedObject(infos []*Info, forceList bool, version string) (runtime.Object, error) {
|
||||||
|
objects, err := AsVersionedObjects(infos, version)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var object runtime.Object
|
||||||
|
if len(objects) == 1 && !forceList {
|
||||||
|
object = objects[0]
|
||||||
|
} else {
|
||||||
|
object = &api.List{Items: objects}
|
||||||
|
converted, err := tryConvert(api.Scheme, object, version, latest.Version)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
object = converted
|
||||||
|
}
|
||||||
|
return object, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AsVersionedObjects converts a list of infos into versioned objects. The provided
|
||||||
|
// version will be preferred as the conversion target, but the Object's mapping version will be
|
||||||
|
// used if that version is not present.
|
||||||
|
func AsVersionedObjects(infos []*Info, version string) ([]runtime.Object, error) {
|
||||||
objects := []runtime.Object{}
|
objects := []runtime.Object{}
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
if info.Object == nil {
|
if info.Object == nil {
|
||||||
@ -233,19 +256,7 @@ func AsVersionedObject(infos []*Info, forceList bool, version string) (runtime.O
|
|||||||
}
|
}
|
||||||
objects = append(objects, converted)
|
objects = append(objects, converted)
|
||||||
}
|
}
|
||||||
|
return objects, nil
|
||||||
var object runtime.Object
|
|
||||||
if len(objects) == 1 && !forceList {
|
|
||||||
object = objects[0]
|
|
||||||
} else {
|
|
||||||
object = &api.List{Items: objects}
|
|
||||||
converted, err := tryConvert(api.Scheme, object, version, latest.Version)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
object = converted
|
|
||||||
}
|
|
||||||
return object, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tryConvert attempts to convert the given object to the provided versions in order. This function assumes
|
// tryConvert attempts to convert the given object to the provided versions in order. This function assumes
|
||||||
|
Loading…
Reference in New Issue
Block a user