Add support for CRI verbose fields

The remote runtime implementation now supports the `verbose` fields,
which are required for consumers like cri-tools to enable multi CRI
version support.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
Sascha Grunert
2022-02-04 12:34:53 +01:00
parent 56273a6aa3
commit effbcd3a0a
22 changed files with 198 additions and 138 deletions

View File

@@ -27,8 +27,8 @@ func fromV1alpha2VersionResponse(from *v1alpha2.VersionResponse) *runtimeapi.Ver
return (*runtimeapi.VersionResponse)(unsafe.Pointer(from))
}
func fromV1alpha2PodSandboxStatus(from *v1alpha2.PodSandboxStatus) *runtimeapi.PodSandboxStatus {
return (*runtimeapi.PodSandboxStatus)(unsafe.Pointer(from))
func fromV1alpha2PodSandboxStatusResponse(from *v1alpha2.PodSandboxStatusResponse) *runtimeapi.PodSandboxStatusResponse {
return (*runtimeapi.PodSandboxStatusResponse)(unsafe.Pointer(from))
}
func fromV1alpha2ListPodSandboxResponse(from *v1alpha2.ListPodSandboxResponse) *runtimeapi.ListPodSandboxResponse {
@@ -39,8 +39,8 @@ func fromV1alpha2ListContainersResponse(from *v1alpha2.ListContainersResponse) *
return (*runtimeapi.ListContainersResponse)(unsafe.Pointer(from))
}
func fromV1alpha2ContainerStatus(from *v1alpha2.ContainerStatus) *runtimeapi.ContainerStatus {
return (*runtimeapi.ContainerStatus)(unsafe.Pointer(from))
func fromV1alpha2ContainerStatusResponse(from *v1alpha2.ContainerStatusResponse) *runtimeapi.ContainerStatusResponse {
return (*runtimeapi.ContainerStatusResponse)(unsafe.Pointer(from))
}
func fromV1alpha2ExecResponse(from *v1alpha2.ExecResponse) *runtimeapi.ExecResponse {
@@ -61,8 +61,8 @@ func fromV1alpha2PortForwardResponse(from *v1alpha2.PortForwardResponse) *runtim
return (*runtimeapi.PortForwardResponse)(unsafe.Pointer(from))
}
func fromV1alpha2RuntimeStatus(from *v1alpha2.RuntimeStatus) *runtimeapi.RuntimeStatus {
return (*runtimeapi.RuntimeStatus)(unsafe.Pointer(from))
func fromV1alpha2StatusResponse(from *v1alpha2.StatusResponse) *runtimeapi.StatusResponse {
return (*runtimeapi.StatusResponse)(unsafe.Pointer(from))
}
func fromV1alpha2ContainerStats(from *v1alpha2.ContainerStats) *runtimeapi.ContainerStats {
@@ -85,8 +85,8 @@ func fromV1alpha2ListPodSandboxStatsResponse(from *v1alpha2.ListPodSandboxStatsR
return (*runtimeapi.ListPodSandboxStatsResponse)(unsafe.Pointer(from))
}
func fromV1alpha2Image(from *v1alpha2.Image) *runtimeapi.Image {
return (*runtimeapi.Image)(unsafe.Pointer(from))
func fromV1alpha2ImageStatusResponse(from *v1alpha2.ImageStatusResponse) *runtimeapi.ImageStatusResponse {
return (*runtimeapi.ImageStatusResponse)(unsafe.Pointer(from))
}
func fromV1alpha2ListImagesResponse(from *v1alpha2.ListImagesResponse) *runtimeapi.ListImagesResponse {

View File

@@ -205,10 +205,10 @@ func TestFromV1alpha2VersionResponse(t *testing.T) {
assertEqual(t, from, to)
}
func TestFromV1alpha2PodSandboxStatus(t *testing.T) {
from := &v1alpha2.PodSandboxStatus{}
func TestFromV1alpha2PodSandboxStatusResponse(t *testing.T) {
from := &v1alpha2.PodSandboxStatusResponse{}
fillFields(from)
to := fromV1alpha2PodSandboxStatus(from)
to := fromV1alpha2PodSandboxStatusResponse(from)
assertEqual(t, from, to)
}
@@ -226,10 +226,10 @@ func TestFromV1alpha2ListContainersResponse(t *testing.T) {
assertEqual(t, from, to)
}
func TestFromV1alpha2ContainerStatus(t *testing.T) {
from := &v1alpha2.ContainerStatus{}
func TestFromV1alpha2ContainerStatusResponse(t *testing.T) {
from := &v1alpha2.ContainerStatusResponse{}
fillFields(from)
to := fromV1alpha2ContainerStatus(from)
to := fromV1alpha2ContainerStatusResponse(from)
assertEqual(t, from, to)
}
@@ -254,10 +254,10 @@ func TestFromV1alpha2PortForwardResponse(t *testing.T) {
assertEqual(t, from, to)
}
func TestFromV1alpha2RuntimeStatus(t *testing.T) {
from := &v1alpha2.RuntimeStatus{}
func TestFromV1alpha2StatusResponse(t *testing.T) {
from := &v1alpha2.StatusResponse{}
fillFields(from)
to := fromV1alpha2RuntimeStatus(from)
to := fromV1alpha2StatusResponse(from)
assertEqual(t, from, to)
}
@@ -296,11 +296,10 @@ func TestFromV1alpha2ListPodSandboxStatsResponse(t *testing.T) {
assertEqual(t, from, to)
}
func TestFromV1alpha2Image(t *testing.T) {
from := &v1alpha2.Image{}
func TestFromV1alpha2ImageStatusResponse(t *testing.T) {
from := &v1alpha2.ImageStatusResponse{}
fillFields(from)
to := fromV1alpha2Image(from)
fmt.Printf(":%+v\n", to)
to := fromV1alpha2ImageStatusResponse(from)
assertEqual(t, from, to)
}

View File

@@ -38,12 +38,12 @@ func (f *RemoteRuntime) ListImages(ctx context.Context, req *kubeapi.ListImagesR
// present, returns a response with ImageStatusResponse.Image set to
// nil.
func (f *RemoteRuntime) ImageStatus(ctx context.Context, req *kubeapi.ImageStatusRequest) (*kubeapi.ImageStatusResponse, error) {
status, err := f.ImageService.ImageStatus(req.Image)
resp, err := f.ImageService.ImageStatus(req.Image, false)
if err != nil {
return nil, err
}
return &kubeapi.ImageStatusResponse{Image: status}, nil
return resp, nil
}
// PullImage pulls an image with authentication config.

View File

@@ -123,12 +123,12 @@ func (f *RemoteRuntime) RemovePodSandbox(ctx context.Context, req *kubeapi.Remov
// PodSandboxStatus returns the status of the PodSandbox. If the PodSandbox is not
// present, returns an error.
func (f *RemoteRuntime) PodSandboxStatus(ctx context.Context, req *kubeapi.PodSandboxStatusRequest) (*kubeapi.PodSandboxStatusResponse, error) {
podStatus, err := f.RuntimeService.PodSandboxStatus(req.PodSandboxId)
resp, err := f.RuntimeService.PodSandboxStatus(req.PodSandboxId, false)
if err != nil {
return nil, err
}
return &kubeapi.PodSandboxStatusResponse{Status: podStatus}, nil
return resp, nil
}
// ListPodSandbox returns a list of PodSandboxes.
@@ -199,12 +199,12 @@ func (f *RemoteRuntime) ListContainers(ctx context.Context, req *kubeapi.ListCon
// ContainerStatus returns status of the container. If the container is not
// present, returns an error.
func (f *RemoteRuntime) ContainerStatus(ctx context.Context, req *kubeapi.ContainerStatusRequest) (*kubeapi.ContainerStatusResponse, error) {
status, err := f.RuntimeService.ContainerStatus(req.ContainerId)
resp, err := f.RuntimeService.ContainerStatus(req.ContainerId, false)
if err != nil {
return nil, err
}
return &kubeapi.ContainerStatusResponse{Status: status}, nil
return resp, nil
}
// ExecSync runs a command in a container synchronously.
@@ -295,12 +295,12 @@ func (f *RemoteRuntime) UpdateRuntimeConfig(ctx context.Context, req *kubeapi.Up
// Status returns the status of the runtime.
func (f *RemoteRuntime) Status(ctx context.Context, req *kubeapi.StatusRequest) (*kubeapi.StatusResponse, error) {
status, err := f.RuntimeService.Status()
resp, err := f.RuntimeService.Status(false)
if err != nil {
return nil, err
}
return &kubeapi.StatusResponse{Status: status}, nil
return resp, nil
}
// UpdateContainerResources updates ContainerConfig of the container.

View File

@@ -137,7 +137,7 @@ func (r *remoteImageService) listImagesV1(ctx context.Context, filter *runtimeap
}
// ImageStatus returns the status of the image.
func (r *remoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
func (r *remoteImageService) ImageStatus(image *runtimeapi.ImageSpec, verbose bool) (*runtimeapi.ImageStatusResponse, error) {
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()
@@ -146,15 +146,16 @@ func (r *remoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea
// https://github.com/kubernetes/kubernetes/pull/104575/files#r705600987
// https://github.com/kubernetes/kubernetes/pull/104575/files#r696793706
if r.useV1API() {
return r.imageStatusV1(ctx, image)
return r.imageStatusV1(ctx, image, verbose)
}
return r.imageStatusV1alpha2(ctx, image)
return r.imageStatusV1alpha2(ctx, image, verbose)
}
func (r *remoteImageService) imageStatusV1alpha2(ctx context.Context, image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
func (r *remoteImageService) imageStatusV1alpha2(ctx context.Context, image *runtimeapi.ImageSpec, verbose bool) (*runtimeapi.ImageStatusResponse, error) {
resp, err := r.imageClientV1alpha2.ImageStatus(ctx, &runtimeapiV1alpha2.ImageStatusRequest{
Image: v1alpha2ImageSpec(image),
Image: v1alpha2ImageSpec(image),
Verbose: verbose,
})
if err != nil {
klog.ErrorS(err, "Get ImageStatus from image service failed", "image", image.Image)
@@ -170,12 +171,13 @@ func (r *remoteImageService) imageStatusV1alpha2(ctx context.Context, image *run
}
}
return fromV1alpha2Image(resp.Image), nil
return fromV1alpha2ImageStatusResponse(resp), nil
}
func (r *remoteImageService) imageStatusV1(ctx context.Context, image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
func (r *remoteImageService) imageStatusV1(ctx context.Context, image *runtimeapi.ImageSpec, verbose bool) (*runtimeapi.ImageStatusResponse, error) {
resp, err := r.imageClient.ImageStatus(ctx, &runtimeapi.ImageStatusRequest{
Image: image,
Image: image,
Verbose: verbose,
})
if err != nil {
klog.ErrorS(err, "Get ImageStatus from image service failed", "image", image.Image)
@@ -191,7 +193,7 @@ func (r *remoteImageService) imageStatusV1(ctx context.Context, image *runtimeap
}
}
return resp.Image, nil
return resp, nil
}
// PullImage pulls an image with authentication config.

View File

@@ -55,6 +55,9 @@ const (
// versions.
type CRIVersion string
// ErrContainerStatusNil indicates that the returned container status is nil.
var ErrContainerStatusNil = errors.New("container status is nil")
const (
// CRIVersionV1 references the v1 CRI API.
CRIVersionV1 CRIVersion = "v1"
@@ -278,21 +281,22 @@ func (r *remoteRuntimeService) RemovePodSandbox(podSandBoxID string) (err error)
}
// PodSandboxStatus returns the status of the PodSandbox.
func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string, verbose bool) (*runtimeapi.PodSandboxStatusResponse, error) {
klog.V(10).InfoS("[RemoteRuntimeService] PodSandboxStatus", "podSandboxID", podSandBoxID, "timeout", r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()
if r.useV1API() {
return r.podSandboxStatusV1(ctx, podSandBoxID)
return r.podSandboxStatusV1(ctx, podSandBoxID, verbose)
}
return r.podSandboxStatusV1alpha2(ctx, podSandBoxID)
return r.podSandboxStatusV1alpha2(ctx, podSandBoxID, verbose)
}
func (r *remoteRuntimeService) podSandboxStatusV1alpha2(ctx context.Context, podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
func (r *remoteRuntimeService) podSandboxStatusV1alpha2(ctx context.Context, podSandBoxID string, verbose bool) (*runtimeapi.PodSandboxStatusResponse, error) {
resp, err := r.runtimeClientV1alpha2.PodSandboxStatus(ctx, &runtimeapiV1alpha2.PodSandboxStatusRequest{
PodSandboxId: podSandBoxID,
Verbose: verbose,
})
if err != nil {
return nil, err
@@ -300,19 +304,20 @@ func (r *remoteRuntimeService) podSandboxStatusV1alpha2(ctx context.Context, pod
klog.V(10).InfoS("[RemoteRuntimeService] PodSandboxStatus Response", "podSandboxID", podSandBoxID, "status", resp.Status)
status := fromV1alpha2PodSandboxStatus(resp.Status)
if resp.Status != nil {
if err := verifySandboxStatus(status); err != nil {
res := fromV1alpha2PodSandboxStatusResponse(resp)
if res.Status != nil {
if err := verifySandboxStatus(res.Status); err != nil {
return nil, err
}
}
return status, nil
return res, nil
}
func (r *remoteRuntimeService) podSandboxStatusV1(ctx context.Context, podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
func (r *remoteRuntimeService) podSandboxStatusV1(ctx context.Context, podSandBoxID string, verbose bool) (*runtimeapi.PodSandboxStatusResponse, error) {
resp, err := r.runtimeClient.PodSandboxStatus(ctx, &runtimeapi.PodSandboxStatusRequest{
PodSandboxId: podSandBoxID,
Verbose: verbose,
})
if err != nil {
return nil, err
@@ -327,7 +332,7 @@ func (r *remoteRuntimeService) podSandboxStatusV1(ctx context.Context, podSandBo
}
}
return status, nil
return resp, nil
}
// ListPodSandbox returns a list of PodSandboxes.
@@ -550,21 +555,22 @@ func (r *remoteRuntimeService) listContainersV1(ctx context.Context, filter *run
}
// ContainerStatus returns the container status.
func (r *remoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
func (r *remoteRuntimeService) ContainerStatus(containerID string, verbose bool) (*runtimeapi.ContainerStatusResponse, error) {
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStatus", "containerID", containerID, "timeout", r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()
if r.useV1API() {
return r.containerStatusV1(ctx, containerID)
return r.containerStatusV1(ctx, containerID, verbose)
}
return r.containerStatusV1alpha2(ctx, containerID)
return r.containerStatusV1alpha2(ctx, containerID, verbose)
}
func (r *remoteRuntimeService) containerStatusV1alpha2(ctx context.Context, containerID string) (*runtimeapi.ContainerStatus, error) {
func (r *remoteRuntimeService) containerStatusV1alpha2(ctx context.Context, containerID string, verbose bool) (*runtimeapi.ContainerStatusResponse, error) {
resp, err := r.runtimeClientV1alpha2.ContainerStatus(ctx, &runtimeapiV1alpha2.ContainerStatusRequest{
ContainerId: containerID,
Verbose: verbose,
})
if err != nil {
// Don't spam the log with endless messages about the same failure.
@@ -576,20 +582,21 @@ func (r *remoteRuntimeService) containerStatusV1alpha2(ctx context.Context, cont
r.logReduction.ClearID(containerID)
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStatus Response", "containerID", containerID, "status", resp.Status)
status := fromV1alpha2ContainerStatus(resp.Status)
res := fromV1alpha2ContainerStatusResponse(resp)
if resp.Status != nil {
if err := verifyContainerStatus(status); err != nil {
if err := verifyContainerStatus(res.Status); err != nil {
klog.ErrorS(err, "verify ContainerStatus failed", "containerID", containerID)
return nil, err
}
}
return status, nil
return res, nil
}
func (r *remoteRuntimeService) containerStatusV1(ctx context.Context, containerID string) (*runtimeapi.ContainerStatus, error) {
func (r *remoteRuntimeService) containerStatusV1(ctx context.Context, containerID string, verbose bool) (*runtimeapi.ContainerStatusResponse, error) {
resp, err := r.runtimeClient.ContainerStatus(ctx, &runtimeapi.ContainerStatusRequest{
ContainerId: containerID,
Verbose: verbose,
})
if err != nil {
// Don't spam the log with endless messages about the same failure.
@@ -609,7 +616,7 @@ func (r *remoteRuntimeService) containerStatusV1(ctx context.Context, containerI
}
}
return status, nil
return resp, nil
}
// UpdateContainerResources updates a containers resource config
@@ -898,20 +905,22 @@ func (r *remoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.Run
}
// Status returns the status of the runtime.
func (r *remoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
func (r *remoteRuntimeService) Status(verbose bool) (*runtimeapi.StatusResponse, error) {
klog.V(10).InfoS("[RemoteRuntimeService] Status", "timeout", r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()
if r.useV1API() {
return r.statusV1(ctx)
return r.statusV1(ctx, verbose)
}
return r.statusV1alpha2(ctx)
return r.statusV1alpha2(ctx, verbose)
}
func (r *remoteRuntimeService) statusV1alpha2(ctx context.Context) (*runtimeapi.RuntimeStatus, error) {
resp, err := r.runtimeClientV1alpha2.Status(ctx, &runtimeapiV1alpha2.StatusRequest{})
func (r *remoteRuntimeService) statusV1alpha2(ctx context.Context, verbose bool) (*runtimeapi.StatusResponse, error) {
resp, err := r.runtimeClientV1alpha2.Status(ctx, &runtimeapiV1alpha2.StatusRequest{
Verbose: verbose,
})
if err != nil {
klog.ErrorS(err, "Status from runtime service failed")
return nil, err
@@ -926,11 +935,13 @@ func (r *remoteRuntimeService) statusV1alpha2(ctx context.Context) (*runtimeapi.
return nil, err
}
return fromV1alpha2RuntimeStatus(resp.Status), nil
return fromV1alpha2StatusResponse(resp), nil
}
func (r *remoteRuntimeService) statusV1(ctx context.Context) (*runtimeapi.RuntimeStatus, error) {
resp, err := r.runtimeClient.Status(ctx, &runtimeapi.StatusRequest{})
func (r *remoteRuntimeService) statusV1(ctx context.Context, verbose bool) (*runtimeapi.StatusResponse, error) {
resp, err := r.runtimeClient.Status(ctx, &runtimeapi.StatusRequest{
Verbose: verbose,
})
if err != nil {
klog.ErrorS(err, "Status from runtime service failed")
return nil, err
@@ -945,7 +956,7 @@ func (r *remoteRuntimeService) statusV1(ctx context.Context) (*runtimeapi.Runtim
return nil, err
}
return resp.Status, nil
return resp, nil
}
// ContainerStats returns the stats of the container.