diff --git a/pkg/server/service.go b/pkg/server/service.go index 73660d7e8..2b6ce9792 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -19,25 +19,25 @@ package server import ( "fmt" - "github.com/docker/docker/pkg/truncindex" - "github.com/kubernetes-incubator/cri-o/pkg/ocicni" - "google.golang.org/grpc" - contentapi "github.com/containerd/containerd/api/services/content" "github.com/containerd/containerd/api/services/execution" imagesapi "github.com/containerd/containerd/api/services/images" rootfsapi "github.com/containerd/containerd/api/services/rootfs" + versionapi "github.com/containerd/containerd/api/services/version" "github.com/containerd/containerd/content" "github.com/containerd/containerd/images" contentservice "github.com/containerd/containerd/services/content" imagesservice "github.com/containerd/containerd/services/images" + "github.com/docker/docker/pkg/truncindex" + "github.com/kubernetes-incubator/cri-o/pkg/ocicni" + "google.golang.org/grpc" + healthapi "google.golang.org/grpc/health/grpc_health_v1" + runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1" "github.com/kubernetes-incubator/cri-containerd/pkg/metadata" "github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store" osinterface "github.com/kubernetes-incubator/cri-containerd/pkg/os" "github.com/kubernetes-incubator/cri-containerd/pkg/registrar" - - runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1" ) // TODO remove the underscores from the following imports as the services are @@ -86,13 +86,17 @@ type criContainerdService struct { containerNameIndex *registrar.Registrar // containerService is containerd container service client. containerService execution.ContainerServiceClient - // contentStoreService is the containerd content service client.. + // contentStoreService is the containerd content service client. contentStoreService content.Store // rootfsService is the containerd rootfs service client. rootfsService rootfsapi.RootFSClient // imageStoreService is the containerd service to store and track // image metadata. imageStoreService images.Store + // versionService is the containerd version service client. + versionService versionapi.VersionClient + // healthService is the healthcheck service of containerd grpc server. + healthService healthapi.HealthClient // netPlugin is used to setup and teardown network when run/stop pod sandbox. netPlugin ocicni.CNIPlugin } @@ -117,6 +121,8 @@ func NewCRIContainerdService(conn *grpc.ClientConn, rootDir, networkPluginBinDir imageStoreService: imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)), contentStoreService: contentservice.NewStoreFromClient(contentapi.NewContentClient(conn)), rootfsService: rootfsapi.NewRootFSClient(conn), + versionService: versionapi.NewVersionClient(conn), + healthService: healthapi.NewHealthClient(conn), } netPlugin, err := ocicni.InitCNI(networkPluginBinDir, networkPluginConfDir) diff --git a/pkg/server/status.go b/pkg/server/status.go index ef7fc9c65..b4f9be745 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -17,14 +17,52 @@ limitations under the License. package server import ( - "errors" + "fmt" "golang.org/x/net/context" + healthapi "google.golang.org/grpc/health/grpc_health_v1" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1" ) +const ( + // runtimeNotReadyReason is the reason reported when runtime is not ready. + runtimeNotReadyReason = "ContainerdNotReady" + // networkNotReadyReason is the reason reported when network is not ready. + networkNotReadyReason = "NetworkPluginNotReady" +) + // Status returns the status of the runtime. func (c *criContainerdService) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) { - return nil, errors.New("not implemented") + runtimeCondition := &runtime.RuntimeCondition{ + Type: runtime.RuntimeReady, + Status: true, + } + // Use containerd grpc server healthcheck service to check its readiness. + resp, err := c.healthService.Check(ctx, &healthapi.HealthCheckRequest{}) + if err != nil || resp.Status != healthapi.HealthCheckResponse_SERVING { + runtimeCondition.Status = false + runtimeCondition.Reason = runtimeNotReadyReason + if err != nil { + runtimeCondition.Message = fmt.Sprintf("Containerd healthcheck returns error: %v", err) + } else { + runtimeCondition.Message = "Containerd grpc server is not serving" + } + } + + networkCondition := &runtime.RuntimeCondition{ + Type: runtime.NetworkReady, + Status: true, + } + if err := c.netPlugin.Status(); err != nil { + networkCondition.Status = false + networkCondition.Reason = networkNotReadyReason + networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err) + } + return &runtime.StatusResponse{ + Status: &runtime.RuntimeStatus{Conditions: []*runtime.RuntimeCondition{ + runtimeCondition, + networkCondition, + }}, + }, nil } diff --git a/pkg/server/update_runtime_config.go b/pkg/server/update_runtime_config.go index 73d9d0cc9..dcbc091dc 100644 --- a/pkg/server/update_runtime_config.go +++ b/pkg/server/update_runtime_config.go @@ -17,14 +17,13 @@ limitations under the License. package server import ( - "errors" - "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1" ) // UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates. +// TODO(random-liu): Figure out how to handle pod cidr in cri-containerd. func (c *criContainerdService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) { - return nil, errors.New("not implemented") + return &runtime.UpdateRuntimeConfigResponse{}, nil } diff --git a/pkg/server/version.go b/pkg/server/version.go index 73766a051..c9f1f1215 100644 --- a/pkg/server/version.go +++ b/pkg/server/version.go @@ -17,14 +17,35 @@ limitations under the License. package server import ( - "errors" + "fmt" + "github.com/golang/protobuf/ptypes/empty" "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1" ) +const ( + containerName = "containerd" + containerdAPIVersion = "0.0.0" + containerdVersion = "0.0.0" + // kubeAPIVersion is the api version of kubernetes. + kubeAPIVersion = "0.1.0" +) + // Version returns the runtime name, runtime version and runtime API version. func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) { - return nil, errors.New("not implemented") + _, err := c.versionService.Version(ctx, &empty.Empty{}) + if err != nil { + return nil, fmt.Errorf("failed to get containerd version: %v", err) + } + return &runtime.VersionResponse{ + Version: kubeAPIVersion, + RuntimeName: containerName, + // Containerd doesn't return semver because of a bug. + // TODO(random-liu): Replace this with version from containerd. + RuntimeVersion: containerdVersion, + // Containerd doesn't have an api version now. + RuntimeApiVersion: containerdAPIVersion, + }, nil }