Skip to content

Commit

Permalink
update vendor
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <[email protected]>
  • Loading branch information
YaoZengzeng committed Dec 28, 2017
1 parent 824695b commit 682f150
Show file tree
Hide file tree
Showing 22 changed files with 32,681 additions and 178 deletions.
189 changes: 23 additions & 166 deletions cri/cri.go
Original file line number Diff line number Diff line change
@@ -1,194 +1,51 @@
package cri

import (
"os"
"fmt"
"net"
"os"
"syscall"

"google.golang.org/grpc"
"golang.org/x/net/context"

"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/daemon/mgr"

"google.golang.org/grpc"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

// CRIManager serves the kubelet runtime grpc api which will be consumed by kubelet.
type CRIManager struct {
// The grpc server.
// Service serves the kubelet runtime grpc api which will be consumed by kubelet.
type Service struct {
config config.Config
server *grpc.Server

// The address which grpc server serves on.
listen string

ContainerMgr mgr.ContainerMgr
ImageMgr mgr.ImageMgr
criMgr mgr.CriMgr
}

// NewCRIManager creates a brand new cri manager.
func NewCRIManager(cfg *config.Config, ctrMgr mgr.ContainerMgr, imgMgr mgr.ImageMgr) (*CRIManager, error) {
c := &CRIManager{
server: grpc.NewServer(),
listen: cfg.ListenCRI,
ContainerMgr: ctrMgr,
ImageMgr: imgMgr,
// NewService creates a brand new cri service.
func NewService(cfg config.Config, criMgr mgr.CriMgr) (*Service, error) {
s := &Service{
config: cfg,
server: grpc.NewServer(),
criMgr: criMgr,
}

runtime.RegisterRuntimeServiceServer(c.server, c)
runtime.RegisterImageServiceServer(c.server, c)
// TODO: Prepare streaming server.

runtime.RegisterRuntimeServiceServer(s.server, s.criMgr)
runtime.RegisterImageServiceServer(s.server, s.criMgr)

return c, nil
return s, nil
}

func (c *CRIManager) Serve() error {
// Serve starts grpc server.
func (s *Service) Serve() error {
// Unlink to cleanup the previous socket file.
if err := syscall.Unlink(c.listen); err != nil && !os.IsNotExist(err) {
if err := syscall.Unlink(s.config.ListenCRI); err != nil && !os.IsNotExist(err) {
return err
}

l, err := net.Listen("unix", c.listen)
l, err := net.Listen("unix", s.config.ListenCRI)
if err != nil {
return err
}

return c.server.Serve(l)
}

// TODO: Move the underlying functions to their respective files in the future.

// Version returns the runtime name, runtime version and runtime API version.
func (c *CRIManager) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) {
return nil, fmt.Errorf("Version Not Implemented Yet")
}

// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
// the sandbox is in ready state.
func (c *CRIManager) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (*runtime.RunPodSandboxResponse, error) {
return nil, fmt.Errorf("RunPodSandbox Not Implemented Yet")
}

// StopPodSandbox stops the sandbox. If there are any running containers in the
// sandbox, they should be forcibly terminated.
func (c *CRIManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) {
return nil, fmt.Errorf("StopPodSandbox Not Implemented Yet")
}

// RemovePodSandbox removes the sandbox. If there are running containers in the
// sandbox, they should be forcibly removed.
func (c *CRIManager) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (*runtime.RemovePodSandboxResponse, error) {
return nil, fmt.Errorf("RemovePodSandbox Not Implemented Yet")
}

// PodSandboxStatus returns the status of the PodSandbox.
func (c *CRIManager) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (*runtime.PodSandboxStatusResponse, error) {
return nil, fmt.Errorf("PodSandboxStatus Not Implemented Yet")
}

// ListPodSandbox returns a list of Sandbox.
func (c *CRIManager) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (*runtime.ListPodSandboxResponse, error) {
return nil, fmt.Errorf("ListPodSandbox Not Implemented Yet")
}

// CreateContainer creates a new container in the given PodSandbox.
func (c *CRIManager) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (*runtime.CreateContainerResponse, error) {
return nil, fmt.Errorf("CreateContainer Not Implemented Yet")
}

// StartContainer starts the container.
func (c *CRIManager) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (*runtime.StartContainerResponse, error) {
return nil, fmt.Errorf("StartContainer Not Implemented Yet")
}

// StopContainer stops a running container with a grace period (i.e., timeout).
func (c *CRIManager) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (*runtime.StopContainerResponse, error) {
return nil, fmt.Errorf("StopContainer Not Implemented Yet")
}

// RemoveContainer removes the container.
func (c *CRIManager) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (*runtime.RemoveContainerResponse, error) {
return nil, fmt.Errorf("RemoveContainer Not Implemented Yet")
}

// ListContainers lists all containers matching the filter.
func (c *CRIManager) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (*runtime.ListContainersResponse, error) {
return nil, fmt.Errorf("ListContainers Not Implemented Yet")
}

// ContainerStatus inspects the container and returns the status.
func (c *CRIManager) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (*runtime.ContainerStatusResponse, error) {
return nil, fmt.Errorf("ContainerStatus Not Implemented Yet")
}

// ContainerStats returns stats of the container. If the container does not
// exist, the call returns an error.
func (c *CRIManager) ContainerStats(ctx context.Context, r *runtime.ContainerStatsRequest) (*runtime.ContainerStatsResponse, error) {
return nil, fmt.Errorf("ContainerStats Not Implemented Yet")
}

// ListContainerStats returns stats of all running containers.
func (c *CRIManager) ListContainerStats(ctx context.Context, r *runtime.ListContainerStatsRequest) (*runtime.ListContainerStatsResponse, error) {
return nil, fmt.Errorf("ListContainerStats Not Implemented Yet")
}

// UpdateContainerResources updates ContainerConfig of the container.
func (c *CRIManager) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (*runtime.UpdateContainerResourcesResponse, error) {
return nil, fmt.Errorf("UpdateContainerResources Not Implemented Yet")
}

// ExecSync executes a command in the container, and returns the stdout output.
// If command exits with a non-zero exit code, an error is returned.
func (c *CRIManager) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (*runtime.ExecSyncResponse, error) {
return nil, fmt.Errorf("ExecSync Not Implemented Yet")
}

// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
func (c *CRIManager) Exec(ctx context.Context, r *runtime.ExecRequest) (*runtime.ExecResponse, error) {
return nil, fmt.Errorf("Exec Not Implemented Yet")
}

// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
func (c *CRIManager) Attach(ctx context.Context, r *runtime.AttachRequest) (*runtime.AttachResponse, error) {
return nil, fmt.Errorf("Attach Not Implemented Yet")
}

// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
func (c *CRIManager) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (*runtime.PortForwardResponse, error) {
return nil, fmt.Errorf("PortForward Not Implemented Yet")
}

// UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.
func (c *CRIManager) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) {
return nil, fmt.Errorf("UpdateRuntimeConfig Not Implemented Yet")
}

// Status returns the status of the runtime.
func (c *CRIManager) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) {
return nil, fmt.Errorf("Status Not Implemented Yet")
}

// ListImages lists existing images.
func (c *CRIManager) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (*runtime.ListImagesResponse, error) {
return nil, fmt.Errorf("ListImages Not Implemented Yet")
}

// ImageStatus returns the status of the image, returns nil if the image isn't present.
func (c *CRIManager) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (*runtime.ImageStatusResponse, error) {
return nil, fmt.Errorf("ImageStatus Not Implemented Yet")
}

// PullImage pulls an image with authentication config.
func (c *CRIManager) PullImage(ctx context.Context, r *runtime.PullImageRequest) (*runtime.PullImageResponse, error) {
return nil, fmt.Errorf("PullImage Not Implemented Yet")
}

// RemoveImage removes the image.
func (c *CRIManager) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (*runtime.RemoveImageResponse, error) {
return nil, fmt.Errorf("RemoveImage Not Implemented Yet")
}

// ImageFsInfo returns information of the filesystem that is used to store images.
func (c *CRIManager) ImageFsInfo(ctx context.Context, r *runtime.ImageFsInfoRequest) (*runtime.ImageFsInfoResponse, error) {
return nil, fmt.Errorf("ImageFsInfo Not Implemented Yet")
return s.server.Serve(l)
}
20 changes: 13 additions & 7 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"reflect"

"github.com/alibaba/pouch/apis/server"
"github.com/alibaba/pouch/cri"
"github.com/alibaba/pouch/ctrd"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/daemon/meta"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/internal"
"github.com/alibaba/pouch/network/bridge"
"github.com/alibaba/pouch/cri"

"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
Expand All @@ -28,8 +28,9 @@ type Daemon struct {
imageMgr mgr.ImageMgr
volumeMgr mgr.VolumeMgr
networkMgr mgr.NetworkMgr
criManager *cri.CRIManager
criMgr mgr.CriMgr
server server.Server
criService *cri.Service
}

// router represents the router of daemon.
Expand Down Expand Up @@ -104,11 +105,16 @@ func (d *Daemon) Run() error {
}
d.containerMgr = containerMgr

criManager, err := internal.GenCRIManager(d)
criMgr, err := internal.GenCriMgr(d)
if err != nil {
return err
}
d.criMgr = criMgr

d.criService, err = cri.NewService(d.config, criMgr)
if err != nil {
return err
}
d.criManager = criManager

d.server = server.Server{
Config: d.config,
Expand All @@ -128,15 +134,15 @@ func (d *Daemon) Run() error {
httpServerCloseCh := make(chan struct{})
go func() {
if err := d.server.Start(); err != nil {
logrus.Errorf("Failed to start http server: %v", err)
logrus.Errorf("failed to start http server: %v", err)
}
close(httpServerCloseCh)
}()

grpcServerCloseCh := make(chan struct{})
go func() {
if err := d.criManager.Serve(); err != nil {
logrus.Errorf("Failed to start grpc server: %v", err)
if err := d.criService.Serve(); err != nil {
logrus.Errorf("failed to start grpc server: %v", err)
}
close(grpcServerCloseCh)
}()
Expand Down
Loading

0 comments on commit 682f150

Please sign in to comment.