mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
add ApproximatePodTemplateForObject factory method
This commit is contained in:
parent
c7f970c560
commit
ba1914d514
@ -454,6 +454,10 @@ func (f *FakeFactory) AttachablePodForObject(ob runtime.Object, timeout time.Dur
|
|||||||
return nil, nil
|
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) {
|
func (f *FakeFactory) UpdatePodSpecForObject(obj runtime.Object, fn func(*api.PodSpec) error) (bool, error) {
|
||||||
return false, nil
|
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) {
|
func (f *fakeAPIFactory) Validator(validate bool) (validation.Schema, error) {
|
||||||
return f.tf.Validator, f.tf.Err
|
return f.tf.Validator, f.tf.Err
|
||||||
}
|
}
|
||||||
|
@ -231,6 +231,11 @@ type ObjectMappingFactory interface {
|
|||||||
// AttachablePodForObject returns the pod to which to attach given an object.
|
// AttachablePodForObject returns the pod to which to attach given an object.
|
||||||
AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error)
|
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.
|
// Returns a schema that can validate objects stored on disk.
|
||||||
Validator(validate bool) (validation.Schema, error)
|
Validator(validate bool) (validation.Schema, error)
|
||||||
// SwaggerSchema returns the schema declaration for the provided group version kind.
|
// SwaggerSchema returns the schema declaration for the provided group version kind.
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -354,6 +355,28 @@ func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusVi
|
|||||||
return kubectl.StatusViewerFor(mapping.GroupVersionKind.GroupKind(), clientset)
|
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) {
|
func (f *ring1Factory) AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error) {
|
||||||
clientset, err := f.clientAccessFactory.ClientSetForVersion(nil)
|
clientset, err := f.clientAccessFactory.ClientSetForVersion(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user