Merge pull request #125841 from saschagrunert/get-container-events-ctx
cri: allow `GetContainerEvents` to pass a context
This commit is contained in:
		@@ -335,11 +335,11 @@ func (in instrumentedRuntimeService) CheckpointContainer(ctx context.Context, op
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (in instrumentedRuntimeService) GetContainerEvents(containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error {
 | 
			
		||||
func (in instrumentedRuntimeService) GetContainerEvents(ctx context.Context, containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error {
 | 
			
		||||
	const operation = "get_container_events"
 | 
			
		||||
	defer recordOperation(operation, time.Now())
 | 
			
		||||
 | 
			
		||||
	err := in.service.GetContainerEvents(containerEventsCh, connectionEstablishedCallback)
 | 
			
		||||
	err := in.service.GetContainerEvents(ctx, containerEventsCh, connectionEstablishedCallback)
 | 
			
		||||
	recordError(operation, err)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ limitations under the License.
 | 
			
		||||
package pleg
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -192,7 +193,7 @@ func (e *EventedPLEG) watchEventsChannel() {
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			err := e.runtimeService.GetContainerEvents(containerEventsResponseCh, func(runtimeapi.RuntimeService_GetContainerEventsClient) {
 | 
			
		||||
			err := e.runtimeService.GetContainerEvents(context.Background(), containerEventsResponseCh, func(runtimeapi.RuntimeService_GetContainerEventsClient) {
 | 
			
		||||
				metrics.EventedPLEGConn.Inc()
 | 
			
		||||
			})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ type ContainerManager interface {
 | 
			
		||||
	// CheckpointContainer checkpoints a container
 | 
			
		||||
	CheckpointContainer(ctx context.Context, options *runtimeapi.CheckpointContainerRequest) error
 | 
			
		||||
	// GetContainerEvents gets container events from the CRI runtime
 | 
			
		||||
	GetContainerEvents(containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error
 | 
			
		||||
	GetContainerEvents(ctx context.Context, containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PodSandboxManager contains methods for operating on PodSandboxes. The methods
 | 
			
		||||
 
 | 
			
		||||
@@ -716,7 +716,7 @@ func (r *FakeRuntimeService) CheckpointContainer(_ context.Context, options *run
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *FakeRuntimeService) GetContainerEvents(containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error {
 | 
			
		||||
func (f *FakeRuntimeService) GetContainerEvents(ctx context.Context, containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -822,8 +822,8 @@ func (r *remoteRuntimeService) CheckpointContainer(ctx context.Context, options
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *remoteRuntimeService) GetContainerEvents(containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error {
 | 
			
		||||
	containerEventsStreamingClient, err := r.runtimeClient.GetContainerEvents(context.Background(), &runtimeapi.GetEventsRequest{})
 | 
			
		||||
func (r *remoteRuntimeService) GetContainerEvents(ctx context.Context, containerEventsCh chan *runtimeapi.ContainerEventResponse, connectionEstablishedCallback func(runtimeapi.RuntimeService_GetContainerEventsClient)) error {
 | 
			
		||||
	containerEventsStreamingClient, err := r.runtimeClient.GetContainerEvents(ctx, &runtimeapi.GetEventsRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		r.logErr(err, "GetContainerEvents failed to get streaming client")
 | 
			
		||||
		return err
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user