mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-08 16:30:57 -04:00
Merge pull request #137476 from brianpursley/wait-context
Use context in kubectl wait and kubectl logs
This commit is contained in:
commit
644e26dc55
2 changed files with 6 additions and 6 deletions
|
|
@ -366,7 +366,7 @@ func (o LogsOptions) RunLogs() error {
|
|||
//
|
||||
// When a signal is received, streaming is stopped, then followed by os.Exit(1).
|
||||
func (o LogsOptions) RunLogsContext(ctx context.Context) error {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
intr := interrupt.New(nil, cancel)
|
||||
return intr.Run(func() error {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ func getObjAndCheckCondition(ctx context.Context, info *resource.Info, o *WaitOp
|
|||
errWaitTimeoutWithName := extendErrWaitTimeout(wait.ErrorInterrupted(nil), info) // nolint:staticcheck // SA1019
|
||||
if o.Timeout == 0 {
|
||||
// If timeout is zero we will fetch the object(s) once only and check
|
||||
gottenObj, initObjGetErr := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Get(context.Background(), info.Name, metav1.GetOptions{})
|
||||
gottenObj, initObjGetErr := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Get(ctx, info.Name, metav1.GetOptions{})
|
||||
if initObjGetErr != nil {
|
||||
return nil, false, initObjGetErr
|
||||
}
|
||||
|
|
@ -136,13 +136,13 @@ func getObjAndCheckCondition(ctx context.Context, info *resource.Info, o *WaitOp
|
|||
mapping := info.ResourceMapping() // used to pass back meaningful errors if object disappears
|
||||
fieldSelector := fields.OneTermEqualSelector("metadata.name", info.Name).String()
|
||||
lw := cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) {
|
||||
options.FieldSelector = fieldSelector
|
||||
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), options)
|
||||
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(ctx, options)
|
||||
},
|
||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||
WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) {
|
||||
options.FieldSelector = fieldSelector
|
||||
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), options)
|
||||
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(ctx, options)
|
||||
},
|
||||
}, o.DynamicClient)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue