Skip to content

Add remote runtime/image Close() API #133211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/kubelet/kuberuntime/instrumented_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ func (in instrumentedImageManagerService) ImageFsInfo(ctx context.Context) (*run
return fsInfo, nil
}

func (in instrumentedImageManagerService) Close() error {
const operation = "close"
defer recordOperation(operation, time.Now())

err := in.service.Close()
recordError(operation, err)
return err
}

func (in instrumentedRuntimeService) CheckpointContainer(ctx context.Context, options *runtimeapi.CheckpointContainerRequest) error {
const operation = "checkpoint_container"
defer recordOperation(operation, time.Now())
Expand Down Expand Up @@ -379,3 +388,12 @@ func (in instrumentedRuntimeService) RuntimeConfig(ctx context.Context) (*runtim
recordError(operation, err)
return out, err
}

func (in instrumentedRuntimeService) Close() error {
const operation = "close"
defer recordOperation(operation, time.Now())

err := in.service.Close()
recordError(operation, err)
return err
}
4 changes: 4 additions & 0 deletions staging/src/k8s.io/cri-api/pkg/apis/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type RuntimeService interface {
Status(ctx context.Context, verbose bool) (*runtimeapi.StatusResponse, error)
// RuntimeConfig returns the configuration information of the runtime.
RuntimeConfig(ctx context.Context) (*runtimeapi.RuntimeConfigResponse, error)
// Close will shutdown the internal gRPC client connection.
Close() error
}

// ImageManagerService interface should be implemented by a container image
Expand All @@ -139,4 +141,6 @@ type ImageManagerService interface {
RemoveImage(ctx context.Context, image *runtimeapi.ImageSpec) error
// ImageFsInfo returns information of the filesystem(s) used to store the read-only layers and the writeable layer.
ImageFsInfo(ctx context.Context) (*runtimeapi.ImageFsInfoResponse, error)
// Close will shutdown the internal gRPC client connection.
Close() error
}
13 changes: 13 additions & 0 deletions staging/src/k8s.io/cri-api/pkg/apis/testing/fake_image_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,16 @@ type pulledImage struct {
imageSpec *runtimeapi.ImageSpec
authConfig *runtimeapi.AuthConfig
}

// Close will shutdown the internal gRPC client connection.
func (r *FakeImageService) Close() error {
r.Lock()
defer r.Unlock()

r.Called = append(r.Called, "Close")
if err := r.popError("Close"); err != nil {
return err
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,16 @@ func (r *FakeRuntimeService) UpdatePodSandboxResources(context.Context, *runtime

return &runtimeapi.UpdatePodSandboxResourcesResponse{}, nil
}

// Close will shutdown the internal gRPC client connection.
func (r *FakeRuntimeService) Close() error {
r.Lock()
defer r.Unlock()

r.Called = append(r.Called, "Close")
if err := r.popError("Close"); err != nil {
return err
}

return nil
}
5 changes: 5 additions & 0 deletions staging/src/k8s.io/cri-client/pkg/fake/fake_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,8 @@ func (f *RemoteRuntime) RuntimeConfig(ctx context.Context, req *kubeapi.RuntimeC
func (f *RemoteRuntime) UpdatePodSandboxResources(ctx context.Context, req *kubeapi.UpdatePodSandboxResourcesRequest) (*kubeapi.UpdatePodSandboxResourcesResponse, error) {
return f.RuntimeService.UpdatePodSandboxResources(ctx, req)
}

// Close will shutdown the internal gRPC client connection.
func (f *RemoteRuntime) Close() error {
return f.RuntimeService.Close()
}
7 changes: 7 additions & 0 deletions staging/src/k8s.io/cri-client/pkg/remote_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type remoteImageService struct {
timeout time.Duration
imageClient runtimeapi.ImageServiceClient
logger *klog.Logger
conn *grpc.ClientConn
}

// NewRemoteImageService creates a new internalapi.ImageManagerService.
Expand Down Expand Up @@ -94,6 +95,7 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration, tp
service := &remoteImageService{
timeout: connectionTimeout,
logger: logger,
conn: conn,
}
if err := service.validateServiceConnection(ctx, conn, endpoint); err != nil {
return nil, fmt.Errorf("validate service connection: %w", err)
Expand All @@ -103,6 +105,11 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration, tp

}

// Close will shutdown the internal gRPC client connection.
func (r *remoteImageService) Close() error {
return r.conn.Close()
}

func (r *remoteImageService) log(level int, msg string, keyAndValues ...any) {
internal.Log(r.logger, level, msg, keyAndValues...)
}
Expand Down
7 changes: 7 additions & 0 deletions staging/src/k8s.io/cri-client/pkg/remote_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type remoteRuntimeService struct {
// Cache last per-container error message to reduce log spam
logReduction *logreduction.LogReduction
logger *klog.Logger
conn *grpc.ClientConn
}

const (
Expand Down Expand Up @@ -127,6 +128,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration, t
timeout: connectionTimeout,
logReduction: logreduction.NewLogReduction(identicalErrorDelay),
logger: logger,
conn: conn,
}

if err := service.validateServiceConnection(ctx, conn, endpoint); err != nil {
Expand All @@ -136,6 +138,11 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration, t
return service, nil
}

// Close will shutdown the internal gRPC client connection.
func (r *remoteRuntimeService) Close() error {
return r.conn.Close()
}

func (r *remoteRuntimeService) log(level int, msg string, keyAndValues ...any) {
internal.Log(r.logger, level, msg, keyAndValues...)
}
Expand Down