add ApproximatePodTemplateForObject factory method

This commit is contained in:
juanvallejo 2017-10-09 14:57:23 -04:00
parent c7f970c560
commit ba1914d514
No known key found for this signature in database
GPG Key ID: 7D2C958002D6448D
3 changed files with 36 additions and 0 deletions

View File

@ -454,6 +454,10 @@ func (f *FakeFactory) AttachablePodForObject(ob runtime.Object, timeout time.Dur
return nil, nil
}
func (f *FakeFactory) ApproximatePodTemplateForObject(obj runtime.Object) (*api.PodTemplateSpec, error) {
return f.ApproximatePodTemplateForObject(obj)
}
func (f *FakeFactory) UpdatePodSpecForObject(obj runtime.Object, fn func(*api.PodSpec) error) (bool, error) {
return false, nil
}
@ -718,6 +722,10 @@ func (f *fakeAPIFactory) AttachablePodForObject(object runtime.Object, timeout t
}
}
func (f *fakeAPIFactory) ApproximatePodTemplateForObject(obj runtime.Object) (*api.PodTemplateSpec, error) {
return f.Factory.ApproximatePodTemplateForObject(obj)
}
func (f *fakeAPIFactory) Validator(validate bool) (validation.Schema, error) {
return f.tf.Validator, f.tf.Err
}

View File

@ -231,6 +231,11 @@ type ObjectMappingFactory interface {
// AttachablePodForObject returns the pod to which to attach given an object.
AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error)
// ApproximatePodTemplateForObject returns a pod template object for the provided source.
// It may return both an error and a object. It attempt to return the best possible template
// available at the current time.
ApproximatePodTemplateForObject(runtime.Object) (*api.PodTemplateSpec, error)
// Returns a schema that can validate objects stored on disk.
Validator(validate bool) (validation.Schema, error)
// SwaggerSchema returns the schema declaration for the provided group version kind.

View File

@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"os"
"reflect"
"sort"
"sync"
"time"
@ -354,6 +355,28 @@ func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusVi
return kubectl.StatusViewerFor(mapping.GroupVersionKind.GroupKind(), clientset)
}
func (f *ring1Factory) ApproximatePodTemplateForObject(object runtime.Object) (*api.PodTemplateSpec, error) {
switch t := object.(type) {
case *api.Pod:
return &api.PodTemplateSpec{
ObjectMeta: t.ObjectMeta,
Spec: t.Spec,
}, nil
case *api.ReplicationController:
return t.Spec.Template, nil
case *extensions.ReplicaSet:
return &t.Spec.Template, nil
case *extensions.DaemonSet:
return &t.Spec.Template, nil
case *extensions.Deployment:
return &t.Spec.Template, nil
case *batch.Job:
return &t.Spec.Template, nil
}
return nil, fmt.Errorf("unable to extract pod template from type %v", reflect.TypeOf(object))
}
func (f *ring1Factory) AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error) {
clientset, err := f.clientAccessFactory.ClientSetForVersion(nil)
if err != nil {