Skip to content

Commit

Permalink
add *extensions.Deployent case
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Sep 15, 2017
1 parent 1232cbe commit edb4c59
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
24 changes: 24 additions & 0 deletions pkg/cmd/util/clientcmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,30 @@ func (f *Factory) ApproximatePodTemplateForObject(object runtime.Object) (*api.P
}
return fallback, nil

case *extensions.Deployment:
template := &t.Spec.Template

_, kc, err := f.Clients()
if err != nil {
return template, err
}

pods, err := kc.Core().Pods(t.Namespace).List(metav1.ListOptions{LabelSelector: labels.SelectorFromSet(t.Spec.Selector.MatchLabels).String()})
if err != nil {
return template, err
}

for i := range pods.Items {
pod := &pods.Items[i]
if template == nil || pod.CreationTimestamp.Before(template.CreationTimestamp) {
template = &api.PodTemplateSpec{
ObjectMeta: pod.ObjectMeta,
Spec: pod.Spec,
}
}
}
return template, nil

default:
pod, err := f.AttachablePodForObject(object, 1*time.Minute)
if pod != nil {
Expand Down
17 changes: 3 additions & 14 deletions pkg/oc/cli/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"k8s.io/apimachinery/pkg/watch"
restclient "k8s.io/client-go/rest"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
kclient "k8s.io/kubernetes/pkg/client/unversioned"
kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
Expand Down Expand Up @@ -242,20 +241,10 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args [
return fmt.Errorf("you must identify a resource with a pod template to debug")
}

var template *kapi.PodTemplateSpec

// if we have 0 replicas, don't attempt to get attachable pod,
// instead use the deployment's pod template.
deployment, ok := infos[0].Object.(*extensions.Deployment)
if ok && deployment.Spec.Replicas == 0 {
template = &deployment.Spec.Template
} else {
template, err = f.ApproximatePodTemplateForObject(infos[0].Object)
if err != nil && template == nil {
return fmt.Errorf("cannot debug %s: %v", infos[0].Name, err)
}
template, err := f.ApproximatePodTemplateForObject(infos[0].Object)
if err != nil && template == nil {
return fmt.Errorf("cannot debug %s: %v", infos[0].Name, err)
}

if err != nil {
glog.V(4).Infof("Unable to get exact template, but continuing with fallback: %v", err)
}
Expand Down

0 comments on commit edb4c59

Please sign in to comment.