Merge pull request #125841 from saschagrunert/get-container-events-ctx

cri: allow `GetContainerEvents` to pass a context
This commit is contained in:
Kubernetes Prow Robot 2024-07-08 14:13:41 -07:00 committed by GitHub
commit b106c291c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 7 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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