Skip to content

Commit d16942c

Browse files
committed
feat: enable cri remote client to call with grpc calloptions
Signed-off-by: haoyun <[email protected]>
1 parent 0f27a42 commit d16942c

4 files changed

Lines changed: 85 additions & 82 deletions

File tree

integration/cri-api/pkg/apis/services.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,73 +37,74 @@ package cri
3737
import (
3838
"time"
3939

40+
"google.golang.org/grpc"
4041
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
4142
)
4243

4344
// RuntimeVersioner contains methods for runtime name, version and API version.
4445
type RuntimeVersioner interface {
4546
// Version returns the runtime name, runtime version and runtime API version
46-
Version(apiVersion string) (*runtimeapi.VersionResponse, error)
47+
Version(apiVersion string, opts ...grpc.CallOption) (*runtimeapi.VersionResponse, error)
4748
}
4849

4950
// ContainerManager contains methods to manipulate containers managed by a
5051
// container runtime. The methods are thread-safe.
5152
type ContainerManager interface {
5253
// CreateContainer creates a new container in specified PodSandbox.
53-
CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error)
54+
CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig, opts ...grpc.CallOption) (string, error)
5455
// StartContainer starts the container.
55-
StartContainer(containerID string) error
56+
StartContainer(containerID string, opts ...grpc.CallOption) error
5657
// StopContainer stops a running container with a grace period (i.e., timeout).
57-
StopContainer(containerID string, timeout int64) error
58+
StopContainer(containerID string, timeout int64, opts ...grpc.CallOption) error
5859
// RemoveContainer removes the container.
59-
RemoveContainer(containerID string) error
60+
RemoveContainer(containerID string, opts ...grpc.CallOption) error
6061
// ListContainers lists all containers by filters.
61-
ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error)
62+
ListContainers(filter *runtimeapi.ContainerFilter, opts ...grpc.CallOption) ([]*runtimeapi.Container, error)
6263
// ContainerStatus returns the status of the container.
63-
ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error)
64+
ContainerStatus(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStatus, error)
6465
// UpdateContainerResources updates the cgroup resources for the container.
65-
UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error
66+
UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources, opts ...grpc.CallOption) error
6667
// ExecSync executes a command in the container, and returns the stdout output.
6768
// If command exits with a non-zero exit code, an error is returned.
68-
ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error)
69+
ExecSync(containerID string, cmd []string, timeout time.Duration, opts ...grpc.CallOption) (stdout []byte, stderr []byte, err error)
6970
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
70-
Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error)
71+
Exec(req *runtimeapi.ExecRequest, opts ...grpc.CallOption) (*runtimeapi.ExecResponse, error)
7172
// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
72-
Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error)
73+
Attach(req *runtimeapi.AttachRequest, opts ...grpc.CallOption) (*runtimeapi.AttachResponse, error)
7374
// ReopenContainerLog asks runtime to reopen the stdout/stderr log file
7475
// for the container. If it returns error, new container log file MUST NOT
7576
// be created.
76-
ReopenContainerLog(ContainerID string) error
77+
ReopenContainerLog(ContainerID string, opts ...grpc.CallOption) error
7778
}
7879

7980
// PodSandboxManager contains methods for operating on PodSandboxes. The methods
8081
// are thread-safe.
8182
type PodSandboxManager interface {
8283
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
8384
// the sandbox is in ready state.
84-
RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error)
85+
RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string, opts ...grpc.CallOption) (string, error)
8586
// StopPodSandbox stops the sandbox. If there are any running containers in the
8687
// sandbox, they should be force terminated.
87-
StopPodSandbox(podSandboxID string) error
88+
StopPodSandbox(podSandboxID string, opts ...grpc.CallOption) error
8889
// RemovePodSandbox removes the sandbox. If there are running containers in the
8990
// sandbox, they should be forcibly removed.
90-
RemovePodSandbox(podSandboxID string) error
91+
RemovePodSandbox(podSandboxID string, opts ...grpc.CallOption) error
9192
// PodSandboxStatus returns the Status of the PodSandbox.
92-
PodSandboxStatus(podSandboxID string) (*runtimeapi.PodSandboxStatus, error)
93+
PodSandboxStatus(podSandboxID string, opts ...grpc.CallOption) (*runtimeapi.PodSandboxStatus, error)
9394
// ListPodSandbox returns a list of Sandbox.
94-
ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error)
95+
ListPodSandbox(filter *runtimeapi.PodSandboxFilter, opts ...grpc.CallOption) ([]*runtimeapi.PodSandbox, error)
9596
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
96-
PortForward(*runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error)
97+
PortForward(req *runtimeapi.PortForwardRequest, opts ...grpc.CallOption) (*runtimeapi.PortForwardResponse, error)
9798
}
9899

99100
// ContainerStatsManager contains methods for retrieving the container
100101
// statistics.
101102
type ContainerStatsManager interface {
102103
// ContainerStats returns stats of the container. If the container does not
103104
// exist, the call returns an error.
104-
ContainerStats(containerID string) (*runtimeapi.ContainerStats, error)
105+
ContainerStats(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStats, error)
105106
// ListContainerStats returns stats of all running containers.
106-
ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error)
107+
ListContainerStats(filter *runtimeapi.ContainerStatsFilter, opts ...grpc.CallOption) ([]*runtimeapi.ContainerStats, error)
107108
}
108109

109110
// RuntimeService interface should be implemented by a container runtime.
@@ -115,23 +116,23 @@ type RuntimeService interface {
115116
ContainerStatsManager
116117

117118
// UpdateRuntimeConfig updates runtime configuration if specified
118-
UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error
119+
UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error
119120
// Status returns the status of the runtime.
120-
Status() (*runtimeapi.RuntimeStatus, error)
121+
Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeStatus, error)
121122
}
122123

123124
// ImageManagerService interface should be implemented by a container image
124125
// manager.
125126
// The methods should be thread-safe.
126127
type ImageManagerService interface {
127128
// ListImages lists the existing images.
128-
ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error)
129+
ListImages(filter *runtimeapi.ImageFilter, opts ...grpc.CallOption) ([]*runtimeapi.Image, error)
129130
// ImageStatus returns the status of the image.
130-
ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error)
131+
ImageStatus(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) (*runtimeapi.Image, error)
131132
// PullImage pulls an image with the authentication config.
132-
PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error)
133+
PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig, opts ...grpc.CallOption) (string, error)
133134
// RemoveImage removes the image.
134-
RemoveImage(image *runtimeapi.ImageSpec) error
135+
RemoveImage(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) error
135136
// ImageFsInfo returns information of the filesystem that is used to store images.
136-
ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error)
137+
ImageFsInfo(opts ...grpc.CallOption) ([]*runtimeapi.FilesystemUsage, error)
137138
}

integration/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func ConnectDaemons() error {
8484
}
8585
// Since CRI grpc client doesn't have `WithBlock` specified, we
8686
// need to check whether it is actually connected.
87-
// TODO(random-liu): Extend cri remote client to accept extra grpc options.
87+
// TODO(#6069) Use grpc options to block on connect and remove for this list containers request.
8888
_, err = runtimeService.ListContainers(&runtime.ContainerFilter{})
8989
if err != nil {
9090
return errors.Wrap(err, "failed to list containers")

integration/remote/remote_image.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ func NewImageService(endpoint string, connectionTimeout time.Duration) (internal
7777
}
7878

7979
// ListImages lists available images.
80-
func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
80+
func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter, opts ...grpc.CallOption) ([]*runtimeapi.Image, error) {
8181
ctx, cancel := getContextWithTimeout(r.timeout)
8282
defer cancel()
8383

8484
resp, err := r.imageClient.ListImages(ctx, &runtimeapi.ListImagesRequest{
8585
Filter: filter,
86-
})
86+
}, opts...)
8787
if err != nil {
8888
klog.Errorf("ListImages with filter %+v from image service failed: %v", filter, err)
8989
return nil, err
@@ -93,13 +93,13 @@ func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi
9393
}
9494

9595
// ImageStatus returns the status of the image.
96-
func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
96+
func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) (*runtimeapi.Image, error) {
9797
ctx, cancel := getContextWithTimeout(r.timeout)
9898
defer cancel()
9999

100100
resp, err := r.imageClient.ImageStatus(ctx, &runtimeapi.ImageStatusRequest{
101101
Image: image,
102-
})
102+
}, opts...)
103103
if err != nil {
104104
klog.Errorf("ImageStatus %q from image service failed: %v", image.Image, err)
105105
return nil, err
@@ -117,15 +117,15 @@ func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Ima
117117
}
118118

119119
// PullImage pulls an image with authentication config.
120-
func (r *ImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
120+
func (r *ImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig, opts ...grpc.CallOption) (string, error) {
121121
ctx, cancel := getContextWithCancel()
122122
defer cancel()
123123

124124
resp, err := r.imageClient.PullImage(ctx, &runtimeapi.PullImageRequest{
125125
Image: image,
126126
Auth: auth,
127127
SandboxConfig: podSandboxConfig,
128-
})
128+
}, opts...)
129129
if err != nil {
130130
klog.Errorf("PullImage %q from image service failed: %v", image.Image, err)
131131
return "", err
@@ -141,13 +141,13 @@ func (r *ImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.A
141141
}
142142

143143
// RemoveImage removes the image.
144-
func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
144+
func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) error {
145145
ctx, cancel := getContextWithTimeout(r.timeout)
146146
defer cancel()
147147

148148
_, err := r.imageClient.RemoveImage(ctx, &runtimeapi.RemoveImageRequest{
149149
Image: image,
150-
})
150+
}, opts...)
151151
if err != nil {
152152
klog.Errorf("RemoveImage %q from image service failed: %v", image.Image, err)
153153
return err
@@ -157,13 +157,13 @@ func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
157157
}
158158

159159
// ImageFsInfo returns information of the filesystem that is used to store images.
160-
func (r *ImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) {
160+
func (r *ImageService) ImageFsInfo(opts ...grpc.CallOption) ([]*runtimeapi.FilesystemUsage, error) {
161161
// Do not set timeout, because `ImageFsInfo` takes time.
162162
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
163163
ctx, cancel := getContextWithCancel()
164164
defer cancel()
165165

166-
resp, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{})
166+
resp, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{}, opts...)
167167
if err != nil {
168168
klog.Errorf("ImageFsInfo from image service failed: %v", err)
169169
return nil, err

0 commit comments

Comments
 (0)