From 09d7d652e6621742cd76ed12f3bb755fed9dbc2c Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Sat, 7 Oct 2017 00:47:51 +0000 Subject: [PATCH] Change `Version` to return cri-containerd version instead. Signed-off-by: Lantao Liu --- Makefile | 4 ++-- pkg/server/version.go | 17 +++++++++-------- pkg/version/version.go | 7 ++++--- pkg/version/version_test.go | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 62095dc63..d4cc6e979 100644 --- a/Makefile +++ b/Makefile @@ -18,14 +18,14 @@ PROJECT := github.com/kubernetes-incubator/cri-containerd BINDIR := ${DESTDIR}/usr/local/bin BUILD_DIR := _output # VERSION is derived from the current tag for HEAD plus amends. Version is used -# to set/overide the criContainerdVersion variable in the verison package for +# to set/overide the CRIContainerdVersion variable in the verison package for # cri-containerd. VERSION := $(shell git describe --tags --dirty) # strip the first char of the tag if it's a `v` VERSION := $(VERSION:v%=%) TARBALL := cri-containerd-$(VERSION).tar.gz BUILD_TAGS := seccomp apparmor -GO_LDFLAGS := -X $(PROJECT)/pkg/version.criContainerdVersion=$(VERSION) +GO_LDFLAGS := -X $(PROJECT)/pkg/version.CRIContainerdVersion=$(VERSION) SOURCES := $(shell find cmd/ pkg/ vendor/ -name '*.go') INTEGRATION_SOURCES := $(shell find integration/ -name '*.go') diff --git a/pkg/server/version.go b/pkg/server/version.go index 82beda712..e909085ec 100644 --- a/pkg/server/version.go +++ b/pkg/server/version.go @@ -17,14 +17,19 @@ limitations under the License. package server import ( - "fmt" - "golang.org/x/net/context" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" + + "github.com/kubernetes-incubator/cri-containerd/pkg/version" ) const ( - containerName = "containerd" + // For now, containerd and runc are bundled with cri-containerd, cri-containerd + // version is more important to us. + // TODO(random-liu): Figure out how to package cri-containerd and containerd, + // and how to version it. We still prefer calling the container runtime "containerd", + // but we care both the cri-containerd version and containerd version. + containerName = "cri-containerd" containerdAPIVersion = "0.0.0" // kubeAPIVersion is the api version of kubernetes. kubeAPIVersion = "0.1.0" @@ -32,14 +37,10 @@ const ( // Version returns the runtime name, runtime version and runtime API version. func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) { - resp, err := c.client.Version(ctx) - if err != nil { - return nil, fmt.Errorf("failed to get containerd version: %v", err) - } return &runtime.VersionResponse{ Version: kubeAPIVersion, RuntimeName: containerName, - RuntimeVersion: resp.Version, + RuntimeVersion: version.CRIContainerdVersion, // Containerd doesn't have an api version now. RuntimeApiVersion: containerdAPIVersion, }, nil diff --git a/pkg/version/version.go b/pkg/version/version.go index 05a2ca4b8..05d0abc2b 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -22,7 +22,8 @@ import ( "github.com/blang/semver" ) -var criContainerdVersion = "UNKNOWN" +// CRIContainerdVersion is the version of the cri-containerd. +var CRIContainerdVersion = "UNKNOWN" func validateSemver(sv string) error { _, err := semver.Parse(sv) @@ -34,9 +35,9 @@ func validateSemver(sv string) error { // PrintVersion outputs the release version of cri-containerd func PrintVersion() { - err := validateSemver(criContainerdVersion) + err := validateSemver(CRIContainerdVersion) if err != nil { fmt.Println(err) } - fmt.Println(criContainerdVersion) + fmt.Println(CRIContainerdVersion) } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 22b0335a8..0a40304b6 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -28,6 +28,6 @@ func TestValidateSemver(t *testing.T) { assert.NotNil(err) err = validateSemver("0.0.0-1-gdf6a1cc-dirty") assert.Nil(err) - err = validateSemver(criContainerdVersion) + err = validateSemver(CRIContainerdVersion) assert.Nil(err) }