@@ -14,20 +14,20 @@ import (
14
14
kapierrors "k8s.io/kubernetes/pkg/api/errors"
15
15
"k8s.io/kubernetes/pkg/api/unversioned"
16
16
"k8s.io/kubernetes/pkg/client/restclient"
17
+ kclient "k8s.io/kubernetes/pkg/client/unversioned"
17
18
"k8s.io/kubernetes/pkg/fields"
18
19
kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
19
20
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
20
21
"k8s.io/kubernetes/pkg/kubectl/resource"
22
+ "k8s.io/kubernetes/pkg/runtime"
21
23
"k8s.io/kubernetes/pkg/util/interrupt"
22
24
"k8s.io/kubernetes/pkg/util/term"
23
- "k8s.io/kubernetes/pkg/util/wait"
24
25
"k8s.io/kubernetes/pkg/watch"
25
26
26
27
cmdutil "github.com/openshift/origin/pkg/cmd/util"
27
28
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
28
- "github.com/openshift/origin/pkg/generate/app"
29
+ generateapp "github.com/openshift/origin/pkg/generate/app"
29
30
imageapi "github.com/openshift/origin/pkg/image/api"
30
- "k8s.io/kubernetes/pkg/runtime"
31
31
)
32
32
33
33
type DebugOptions struct {
@@ -102,7 +102,7 @@ the shell.`
102
102
// NewCmdDebug creates a command for debugging pods.
103
103
func NewCmdDebug (fullName string , f * clientcmd.Factory , in io.Reader , out , errout io.Writer ) * cobra.Command {
104
104
options := & DebugOptions {
105
- Timeout : 30 * time .Second ,
105
+ Timeout : 15 * time .Minute ,
106
106
Attach : kcmd.AttachOptions {
107
107
In : in ,
108
108
Out : out ,
@@ -238,7 +238,7 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args [
238
238
ObjectMeta : template .ObjectMeta ,
239
239
Spec : template .Spec ,
240
240
}
241
- pod .Name , pod .Namespace = infos [0 ].Name , infos [0 ].Namespace
241
+ pod .Name , pod .Namespace = fmt . Sprintf ( "%s-debug" , generateapp . MakeSimpleName ( infos [0 ].Name )) , infos [0 ].Namespace
242
242
o .Attach .Pod = pod
243
243
244
244
o .AsNonRoot = ! o .AsRoot && cmd .Flag ("as-root" ).Changed
@@ -288,106 +288,6 @@ func (o DebugOptions) Validate() error {
288
288
return nil
289
289
}
290
290
291
- // WatchConditionFunc returns true if the condition has been reached, false if it has not been reached yet,
292
- // or an error if the condition cannot be checked and should terminate.
293
- type WatchConditionFunc func (event watch.Event ) (bool , error )
294
-
295
- // Until reads items from the watch until each provided condition succeeds, and then returns the last watch
296
- // encountered. The first condition that returns an error terminates the watch (and the event is also returned).
297
- // If no event has been received, the returned event will be nil.
298
- // TODO: move to pkg/watch upstream
299
- func Until (timeout time.Duration , watcher watch.Interface , conditions ... WatchConditionFunc ) (* watch.Event , error ) {
300
- ch := watcher .ResultChan ()
301
- defer watcher .Stop ()
302
- var after <- chan time.Time
303
- if timeout > 0 {
304
- after = time .After (timeout )
305
- } else {
306
- ch := make (chan time.Time )
307
- close (ch )
308
- after = ch
309
- }
310
- var lastEvent * watch.Event
311
- for _ , condition := range conditions {
312
- for {
313
- select {
314
- case event , ok := <- ch :
315
- if ! ok {
316
- return lastEvent , wait .ErrWaitTimeout
317
- }
318
- lastEvent = & event
319
- // TODO: check for watch expired error and retry watch from latest point?
320
- done , err := condition (event )
321
- if err != nil {
322
- return lastEvent , err
323
- }
324
- if done {
325
- return lastEvent , nil
326
- }
327
- case <- after :
328
- return lastEvent , wait .ErrWaitTimeout
329
- }
330
- }
331
- }
332
- return lastEvent , wait .ErrWaitTimeout
333
- }
334
-
335
- // ErrPodCompleted is returned by PodRunning or PodContainerRunning to indicate that
336
- // the pod has already reached completed state.
337
- var ErrPodCompleted = fmt .Errorf ("pod ran to completion" )
338
-
339
- // TODO: move to pkg/client/conditions.go upstream
340
- //
341
- // Example of a running condition, will be used elsewhere
342
- //
343
- // PodRunning returns true if the pod is running, false if the pod has not yet reached running state,
344
- // returns ErrPodCompleted if the pod has run to completion, or an error in any other case.
345
- // func PodRunning(event watch.Event) (bool, error) {
346
- // switch event.Type {
347
- // case watch.Deleted:
348
- // return false, kapierrors.NewNotFound(unversioned.GroupResource{Resource: "pods"}, "")
349
- // }
350
- // switch t := event.Object.(type) {
351
- // case *kapi.Pod:
352
- // switch t.Status.Phase {
353
- // case kapi.PodRunning:
354
- // return true, nil
355
- // case kapi.PodFailed, kapi.PodSucceeded:
356
- // return false, ErrPodCompleted
357
- // }
358
- // }
359
- // return false, nil
360
- // }
361
-
362
- // PodContainerRunning returns false until the named container has ContainerStatus running (at least once),
363
- // and will return an error if the pod is deleted, runs to completion, or the container pod is not available.
364
- func PodContainerRunning (containerName string ) WatchConditionFunc {
365
- return func (event watch.Event ) (bool , error ) {
366
- switch event .Type {
367
- case watch .Deleted :
368
- return false , kapierrors .NewNotFound (unversioned.GroupResource {Resource : "pods" }, "" )
369
- }
370
- switch t := event .Object .(type ) {
371
- case * kapi.Pod :
372
- switch t .Status .Phase {
373
- case kapi .PodRunning , kapi .PodPending :
374
- case kapi .PodFailed , kapi .PodSucceeded :
375
- return false , ErrPodCompleted
376
- default :
377
- return false , nil
378
- }
379
- for _ , s := range t .Status .ContainerStatuses {
380
- if s .Name != containerName {
381
- continue
382
- }
383
- return s .State .Running != nil , nil
384
- }
385
- return false , nil
386
- }
387
- return false , nil
388
- }
389
- }
390
-
391
291
// SingleObject returns a ListOptions for watching a single object.
392
292
// TODO: move to pkg/api/helpers.go upstream.
393
293
func SingleObject (meta kapi.ObjectMeta ) kapi.ListOptions {
@@ -439,7 +339,7 @@ func (o *DebugOptions) Debug() error {
439
339
return err
440
340
}
441
341
fmt .Fprintf (o .Attach .Err , "Waiting for pod to start ...\n " )
442
- switch containerRunningEvent , err := Until (o .Timeout , w , PodContainerRunning (o .Attach .ContainerName )); {
342
+ switch containerRunningEvent , err := watch . Until (o .Timeout , w , kclient . PodContainerRunning (o .Attach .ContainerName )); {
443
343
// api didn't error right away but the pod wasn't even created
444
344
case kapierrors .IsNotFound (err ):
445
345
msg := fmt .Sprintf ("unable to create the debug pod %q" , pod .Name )
@@ -448,7 +348,7 @@ func (o *DebugOptions) Debug() error {
448
348
}
449
349
return fmt .Errorf (msg )
450
350
// switch to logging output
451
- case err == ErrPodCompleted , ! o .Attach .Stdin :
351
+ case err == kclient . ErrPodCompleted , ! o .Attach .Stdin :
452
352
_ , err := kcmd.LogsOptions {
453
353
Object : pod ,
454
354
Options : & kapi.PodLogOptions {
@@ -566,9 +466,6 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kap
566
466
pod .ResourceVersion = ""
567
467
pod .Spec .RestartPolicy = kapi .RestartPolicyNever
568
468
569
- // shorten segments to handle long names and names with bad characters
570
- pod .Name , _ = app .NewUniqueNameGenerator (fmt .Sprintf ("%s-debug" , pod .Name )).Generate (nil )
571
-
572
469
pod .Status = kapi.PodStatus {}
573
470
pod .UID = ""
574
471
pod .CreationTimestamp = unversioned.Time {}
0 commit comments