mirror of https://github.com/k3s-io/k3s
Merge pull request #53606 from juanvallejo/jvallejo/add-approx-pod-template-factory-method
Automatic merge from submit-queue (batch tested with PRs 53606, 49361). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. add ApproximatePodTemplateForObject factory method Makes it possible to get at a pod spec template even if an object is scaled to zero, for use with commands that care about pod templates. **Release note**: ```release-note NONE ``` Related downstream patch and use-case: https://github.com/openshift/origin/pull/16379 cc @smarterclaytonpull/6/head
commit
87bd30a142
|
@ -449,6 +449,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
|
||||
}
|
||||
|
@ -713,6 +717,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
|
||||
}
|
||||
|
|
|
@ -223,6 +223,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)
|
||||
// OpenAPISchema returns the schema openapi schema definiton
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -351,6 +352,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 {
|
||||
|
|
Loading…
Reference in New Issue