Skip to content

Commit f7668aa

Browse files
juanvallejodeads2k
authored andcommitted
UPSTREAM: 53606: implement ApproximatePodTemplateObject upstream
:100644 100644 48b5d52550... 7f1327d3da... M pkg/kubectl/cmd/testing/fake.go :100644 100644 05014de60d... 29c63bcec5... M pkg/kubectl/cmd/util/factory.go :100644 100644 abb10d52bb... 01ad1ff2a3... M pkg/kubectl/cmd/util/factory_object_mapping.go
1 parent 4fbcbd3 commit f7668aa

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Diff for: pkg/kubectl/cmd/testing/fake.go

+8
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ func (f *FakeFactory) AttachablePodForObject(ob runtime.Object, timeout time.Dur
437437
return nil, nil
438438
}
439439

440+
func (f *FakeFactory) ApproximatePodTemplateForObject(obj runtime.Object) (*api.PodTemplateSpec, error) {
441+
return f.ApproximatePodTemplateForObject(obj)
442+
}
443+
440444
func (f *FakeFactory) UpdatePodSpecForObject(obj runtime.Object, fn func(*api.PodSpec) error) (bool, error) {
441445
return false, nil
442446
}
@@ -679,6 +683,10 @@ func (f *fakeAPIFactory) AttachablePodForObject(object runtime.Object, timeout t
679683
}
680684
}
681685

686+
func (f *fakeAPIFactory) ApproximatePodTemplateForObject(obj runtime.Object) (*api.PodTemplateSpec, error) {
687+
return f.Factory.ApproximatePodTemplateForObject(obj)
688+
}
689+
682690
func (f *fakeAPIFactory) Validator(validate bool, cacheDir string) (validation.Schema, error) {
683691
return f.tf.Validator, f.tf.Err
684692
}

Diff for: pkg/kubectl/cmd/util/factory.go

+5
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ type ObjectMappingFactory interface {
218218
// AttachablePodForObject returns the pod to which to attach given an object.
219219
AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error)
220220

221+
// ApproximatePodTemplateForObject returns a pod template object for the provided source.
222+
// It may return both an error and a object. It attempt to return the best possible template
223+
// available at the current time.
224+
ApproximatePodTemplateForObject(runtime.Object) (*api.PodTemplateSpec, error)
225+
221226
// Returns a schema that can validate objects stored on disk.
222227
Validator(validate bool, cacheDir string) (validation.Schema, error)
223228
// SwaggerSchema returns the schema declaration for the provided group version kind.

Diff for: pkg/kubectl/cmd/util/factory_object_mapping.go

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"os"
2525
"path"
26+
"reflect"
2627
"sort"
2728
"sync"
2829
"time"
@@ -349,6 +350,28 @@ func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusVi
349350
return kubectl.StatusViewerFor(mapping.GroupVersionKind.GroupKind(), clientset)
350351
}
351352

353+
func (f *ring1Factory) ApproximatePodTemplateForObject(object runtime.Object) (*api.PodTemplateSpec, error) {
354+
switch t := object.(type) {
355+
case *api.Pod:
356+
return &api.PodTemplateSpec{
357+
ObjectMeta: t.ObjectMeta,
358+
Spec: t.Spec,
359+
}, nil
360+
case *api.ReplicationController:
361+
return t.Spec.Template, nil
362+
case *extensions.ReplicaSet:
363+
return &t.Spec.Template, nil
364+
case *extensions.DaemonSet:
365+
return &t.Spec.Template, nil
366+
case *extensions.Deployment:
367+
return &t.Spec.Template, nil
368+
case *batch.Job:
369+
return &t.Spec.Template, nil
370+
}
371+
372+
return nil, fmt.Errorf("unable to extract pod template from type %v", reflect.TypeOf(object))
373+
}
374+
352375
func (f *ring1Factory) AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error) {
353376
clientset, err := f.clientAccessFactory.ClientSetForVersion(nil)
354377
if err != nil {

0 commit comments

Comments
 (0)