diff --git a/cmd/cri-containerd/cri_containerd.go b/cmd/cri-containerd/cri_containerd.go new file mode 100644 index 000000000..8917af8aa --- /dev/null +++ b/cmd/cri-containerd/cri_containerd.go @@ -0,0 +1,44 @@ +/* +Copyright 2017 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "github.com/golang/glog" + "github.com/spf13/pflag" + + "github.com/kubernetes-incubator/cri-containerd/cmd/cri-containerd/options" + "github.com/kubernetes-incubator/cri-containerd/pkg/server" +) + +func main() { + o := options.NewCRIContainerdOptions() + o.AddFlags(pflag.CommandLine) + options.InitFlags() + + glog.V(2).Infof("Connect to containerd socket %q with timeout %v", o.ContainerdSocketPath, o.ContainerdConnectionTimeout) + conn, err := server.ConnectToContainerd(o.ContainerdSocketPath, o.ContainerdConnectionTimeout) + if err != nil { + glog.Exitf("Failed to connect containerd socket %q: %v", o.ContainerdSocketPath, err) + } + + glog.V(2).Infof("Run cri-containerd grpc server on socket %q", o.CRIContainerdSocketPath) + service := server.NewCRIContainerdService(conn) + s := server.NewCRIContainerdServer(o.CRIContainerdSocketPath, service, service) + if err := s.Run(); err != nil { + glog.Exitf("Failed to run cri-containerd grpc server: %v", err) + } +} diff --git a/cmd/cri-containerd/options/options.go b/cmd/cri-containerd/options/options.go new file mode 100644 index 000000000..b21ca4bc8 --- /dev/null +++ b/cmd/cri-containerd/options/options.go @@ -0,0 +1,53 @@ +/* +Copyright 2017 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package options + +import ( + "flag" + "time" + + "github.com/spf13/pflag" +) + +// CRIContainerdOptions contains cri-containerd command line options. +type CRIContainerdOptions struct { + // CRIContainerdSocketPath is the path to the socket which cri-containerd serves on. + CRIContainerdSocketPath string + // ContainerdSocketPath is the path to the containerd socket. + ContainerdSocketPath string + // ContainerdConnectionTimeout is the connection timeout for containerd client. + ContainerdConnectionTimeout time.Duration +} + +func NewCRIContainerdOptions() *CRIContainerdOptions { + return &CRIContainerdOptions{} +} + +// AddFlags adds cri-containerd command line options to pflag. +func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) { + fs.StringVar(&c.CRIContainerdSocketPath, "cri-containerd-socket", + "/var/run/cri-containerd.sock", "Path to the socket which cri-containerd serves on.") + fs.StringVar(&c.ContainerdSocketPath, "containerd-socket", + "/run/containerd/containerd.sock", "Path to the containerd socket.") + fs.DurationVar(&c.ContainerdConnectionTimeout, "containerd-connection-timeout", + 2*time.Minute, "Connection timeout for containerd client.") +} + +func InitFlags() { + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() +} diff --git a/pkg/server/container_attach.go b/pkg/server/container_attach.go new file mode 100644 index 000000000..1744f439f --- /dev/null +++ b/pkg/server/container_attach.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// Attach prepares a streaming endpoint to attach to a running container, and returns the address. +func (c *criContainerdService) Attach(ctx context.Context, r *runtime.AttachRequest) (*runtime.AttachResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go new file mode 100644 index 000000000..63d0643e6 --- /dev/null +++ b/pkg/server/container_create.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// CreateContainer creates a new container in the given PodSandbox. +func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (*runtime.CreateContainerResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_exec.go b/pkg/server/container_exec.go new file mode 100644 index 000000000..a95cad478 --- /dev/null +++ b/pkg/server/container_exec.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// Exec prepares a streaming endpoint to execute a command in the container, and returns the address. +func (c *criContainerdService) Exec(ctx context.Context, r *runtime.ExecRequest) (*runtime.ExecResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_execsync.go b/pkg/server/container_execsync.go new file mode 100644 index 000000000..a2ba47abb --- /dev/null +++ b/pkg/server/container_execsync.go @@ -0,0 +1,31 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// 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 *criContainerdService) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (*runtime.ExecSyncResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_list.go b/pkg/server/container_list.go new file mode 100644 index 000000000..254323e44 --- /dev/null +++ b/pkg/server/container_list.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// ListContainers lists all containers matching the filter. +func (c *criContainerdService) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (*runtime.ListContainersResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_remove.go b/pkg/server/container_remove.go new file mode 100644 index 000000000..d3e8bd1ce --- /dev/null +++ b/pkg/server/container_remove.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// RemoveContainer removes the container. +func (c *criContainerdService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (*runtime.RemoveContainerResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_start.go b/pkg/server/container_start.go new file mode 100644 index 000000000..dfd5f80a6 --- /dev/null +++ b/pkg/server/container_start.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// StartContainer starts the container. +func (c *criContainerdService) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (*runtime.StartContainerResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_status.go b/pkg/server/container_status.go new file mode 100644 index 000000000..78c871964 --- /dev/null +++ b/pkg/server/container_status.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// ContainerStatus inspects the container and returns the status. +func (c *criContainerdService) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (*runtime.ContainerStatusResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/container_stop.go b/pkg/server/container_stop.go new file mode 100644 index 000000000..28e7b156c --- /dev/null +++ b/pkg/server/container_stop.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// StopContainer stops a running container with a grace period (i.e., timeout). +func (c *criContainerdService) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (*runtime.StopContainerResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/image_list.go b/pkg/server/image_list.go new file mode 100644 index 000000000..953d71240 --- /dev/null +++ b/pkg/server/image_list.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// ListImages lists existing images. +func (c *criContainerdService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (*runtime.ListImagesResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/image_pull.go b/pkg/server/image_pull.go new file mode 100644 index 000000000..67a71151d --- /dev/null +++ b/pkg/server/image_pull.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// PullImage pulls an image with authentication config. +func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (*runtime.PullImageResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/image_remove.go b/pkg/server/image_remove.go new file mode 100644 index 000000000..fd55c4bea --- /dev/null +++ b/pkg/server/image_remove.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// RemoveImage removes the image. +func (c *criContainerdService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (*runtime.RemoveImageResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/image_status.go b/pkg/server/image_status.go new file mode 100644 index 000000000..b74515973 --- /dev/null +++ b/pkg/server/image_status.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// ImageStatus returns the status of the image, returns nil if the image doesn't present. +func (c *criContainerdService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (*runtime.ImageStatusResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/sandbox_list.go b/pkg/server/sandbox_list.go new file mode 100644 index 000000000..bc7832c79 --- /dev/null +++ b/pkg/server/sandbox_list.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// ListPodSandbox returns a list of Sandbox. +func (c *criContainerdService) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (*runtime.ListPodSandboxResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/sandbox_portforward.go b/pkg/server/sandbox_portforward.go new file mode 100644 index 000000000..2411b1e02 --- /dev/null +++ b/pkg/server/sandbox_portforward.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address. +func (c *criContainerdService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (*runtime.PortForwardResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/sandbox_remove.go b/pkg/server/sandbox_remove.go new file mode 100644 index 000000000..90c741ca1 --- /dev/null +++ b/pkg/server/sandbox_remove.go @@ -0,0 +1,31 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// RemovePodSandbox removes the sandbox. If there are running containers in the +// sandbox, they should be forcibly removed. +func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (*runtime.RemovePodSandboxResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go new file mode 100644 index 000000000..d3b0d46f2 --- /dev/null +++ b/pkg/server/sandbox_run.go @@ -0,0 +1,31 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure +// the sandbox is in ready state. +func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (*runtime.RunPodSandboxResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/sandbox_status.go b/pkg/server/sandbox_status.go new file mode 100644 index 000000000..8034dfef5 --- /dev/null +++ b/pkg/server/sandbox_status.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// PodSandboxStatus returns the status of the PodSandbox. +func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (*runtime.PodSandboxStatusResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/sandbox_stop.go b/pkg/server/sandbox_stop.go new file mode 100644 index 000000000..06a3fedc7 --- /dev/null +++ b/pkg/server/sandbox_stop.go @@ -0,0 +1,31 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// StopPodSandbox stops the sandbox. If there are any running containers in the +// sandbox, they should be forcibly terminated. +func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/server.go b/pkg/server/server.go new file mode 100644 index 000000000..60543b85c --- /dev/null +++ b/pkg/server/server.go @@ -0,0 +1,89 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "fmt" + "net" + "os" + "syscall" + "time" + + "github.com/golang/glog" + "google.golang.org/grpc" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" + "k8s.io/kubernetes/pkg/util/interrupt" +) + +// unixProtocol is the network protocol of unix socket. +const unixProtocol = "unix" + +// CRIContainerdServer is the grpc server of cri-containerd. +type CRIContainerdServer struct { + // addr is the address to serve on. + addr string + // runtimeService is the cri-containerd runtime service. + runtimeService runtime.RuntimeServiceServer + // imageService is the cri-containerd image service. + imageService runtime.ImageServiceServer + // server is the grpc server. + server *grpc.Server +} + +// NewCRIContainerdServer creates the cri-containerd grpc server. +func NewCRIContainerdServer(addr string, r runtime.RuntimeServiceServer, i runtime.ImageServiceServer) *CRIContainerdServer { + return &CRIContainerdServer{ + addr: addr, + runtimeService: r, + imageService: i, + } +} + +// Run runs the cri-containerd grpc server. +func (s *CRIContainerdServer) Run() error { + glog.V(2).Infof("Start cri-containerd grpc server") + // Unlink to cleanup the previous socket file. + err := syscall.Unlink(s.addr) + if err != nil && !os.IsNotExist(err) { + return fmt.Errorf("failed to unlink socket file %q: %v", s.addr, err) + } + l, err := net.Listen(unixProtocol, s.addr) + if err != nil { + return fmt.Errorf("failed to listen on %q: %v", s.addr, err) + } + // Create the grpc server and register runtime and image services. + s.server = grpc.NewServer() + runtime.RegisterRuntimeServiceServer(s.server, s.runtimeService) + runtime.RegisterImageServiceServer(s.server, s.imageService) + // Use interrupt handler to make sure the server to be stopped properly. + h := interrupt.New(nil, s.server.Stop) + return h.Run(func() error { return s.server.Serve(l) }) +} + +// ConnectToContainerd returns a grpc client for containerd. +func ConnectToContainerd(path string, connectionTimeout time.Duration) (*grpc.ClientConn, error) { + // get the containerd client + dialOpts := []grpc.DialOption{ + grpc.WithInsecure(), + grpc.WithTimeout(connectionTimeout), + grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { + return net.DialTimeout(unixProtocol, path, timeout) + }), + } + return grpc.Dial(fmt.Sprintf("%s://%s", unixProtocol, path), dialOpts...) +} diff --git a/pkg/server/service.go b/pkg/server/service.go new file mode 100644 index 000000000..18ac41474 --- /dev/null +++ b/pkg/server/service.go @@ -0,0 +1,47 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "google.golang.org/grpc" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" + + _ "github.com/containerd/containerd/api/services/content" + _ "github.com/containerd/containerd/api/services/execution" + _ "github.com/containerd/containerd/api/services/images" + _ "github.com/containerd/containerd/api/services/rootfs" + _ "github.com/containerd/containerd/api/types/container" + _ "github.com/containerd/containerd/api/types/descriptor" + _ "github.com/containerd/containerd/api/types/mount" + _ "github.com/opencontainers/image-spec/specs-go" + _ "github.com/opencontainers/runtime-spec/specs-go" +) + +// CRIContainerdService is the interface implement CRI remote service server. +type CRIContainerdService interface { + runtime.RuntimeServiceServer + runtime.ImageServiceServer +} + +// criContainerdService implements CRIContainerdService. +type criContainerdService struct{} + +func NewCRIContainerdService(conn *grpc.ClientConn) CRIContainerdService { + // TODO: Initialize different containerd clients. + return &criContainerdService{} +} diff --git a/pkg/server/status.go b/pkg/server/status.go new file mode 100644 index 000000000..85553b68b --- /dev/null +++ b/pkg/server/status.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// 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") +} diff --git a/pkg/server/update_runtime_config.go b/pkg/server/update_runtime_config.go new file mode 100644 index 000000000..689d9d9f4 --- /dev/null +++ b/pkg/server/update_runtime_config.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates. +func (c *criContainerdService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) { + return nil, errors.New("not implemented") +} diff --git a/pkg/server/version.go b/pkg/server/version.go new file mode 100644 index 000000000..619b5a2f2 --- /dev/null +++ b/pkg/server/version.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package server + +import ( + "errors" + + "golang.org/x/net/context" + + "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" +) + +// 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") +}