Use containerd version returned by version service.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
d0949687b4
commit
f770d4fea3
@ -28,23 +28,20 @@ import (
|
|||||||
const (
|
const (
|
||||||
containerName = "containerd"
|
containerName = "containerd"
|
||||||
containerdAPIVersion = "0.0.0"
|
containerdAPIVersion = "0.0.0"
|
||||||
containerdVersion = "0.0.0"
|
|
||||||
// kubeAPIVersion is the api version of kubernetes.
|
// kubeAPIVersion is the api version of kubernetes.
|
||||||
kubeAPIVersion = "0.1.0"
|
kubeAPIVersion = "0.1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version returns the runtime name, runtime version and runtime API version.
|
// Version returns the runtime name, runtime version and runtime API version.
|
||||||
func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) {
|
func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) {
|
||||||
_, err := c.versionService.Version(ctx, &empty.Empty{})
|
resp, err := c.versionService.Version(ctx, &empty.Empty{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get containerd version: %v", err)
|
return nil, fmt.Errorf("failed to get containerd version: %v", err)
|
||||||
}
|
}
|
||||||
return &runtime.VersionResponse{
|
return &runtime.VersionResponse{
|
||||||
Version: kubeAPIVersion,
|
Version: kubeAPIVersion,
|
||||||
RuntimeName: containerName,
|
RuntimeName: containerName,
|
||||||
// Containerd doesn't return semver because of a bug.
|
RuntimeVersion: resp.Version,
|
||||||
// TODO(random-liu): Replace this with version from containerd.
|
|
||||||
RuntimeVersion: containerdVersion,
|
|
||||||
// Containerd doesn't have an api version now.
|
// Containerd doesn't have an api version now.
|
||||||
RuntimeApiVersion: containerdAPIVersion,
|
RuntimeApiVersion: containerdAPIVersion,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -35,9 +35,10 @@ func TestVersion(t *testing.T) {
|
|||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
// TODO(random-liu): Check containerd version after containerd fixes its version.
|
// TODO(random-liu): Check containerd version after containerd fixes its version.
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
versionRes *versionapi.VersionResponse
|
versionRes *versionapi.VersionResponse
|
||||||
versionErr error
|
versionErr error
|
||||||
expectErr bool
|
expectErr bool
|
||||||
|
expectedVersion string
|
||||||
}{
|
}{
|
||||||
"should return error if containerd version returns error": {
|
"should return error if containerd version returns error": {
|
||||||
versionErr: errors.New("random error"),
|
versionErr: errors.New("random error"),
|
||||||
@ -55,7 +56,11 @@ func TestVersion(t *testing.T) {
|
|||||||
mock.EXPECT().Version(ctx, &empty.Empty{}).Return(test.versionRes, test.versionErr)
|
mock.EXPECT().Version(ctx, &empty.Empty{}).Return(test.versionRes, test.versionErr)
|
||||||
|
|
||||||
c.versionService = mock
|
c.versionService = mock
|
||||||
_, err := c.Version(ctx, &runtime.VersionRequest{})
|
v, err := c.Version(ctx, &runtime.VersionRequest{})
|
||||||
assert.Equal(t, test.expectErr, err != nil)
|
if test.expectErr {
|
||||||
|
assert.Equal(t, test.expectErr, err != nil)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, test.versionRes.Version, v.RuntimeVersion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user