From cfc08dea340f18cca5687f83f1f5be71117c6b6c Mon Sep 17 00:00:00 2001 From: Tamer Tas Date: Tue, 16 Aug 2016 00:35:07 +0300 Subject: [PATCH 1/3] kubelet/api: extract RuntimeVersioner interface --- pkg/kubelet/api/services.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/api/services.go b/pkg/kubelet/api/services.go index 03155b96587..94a37f999ca 100644 --- a/pkg/kubelet/api/services.go +++ b/pkg/kubelet/api/services.go @@ -22,11 +22,17 @@ import ( runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" ) +// RuntimeVersioner contains methods for runtime name, version and API version. +type RuntimeVersioner interface { + // Version returns the runtime name, runtime version and runtime API version + Version(apiVersion string) (*runtimeApi.VersionResponse, error) +} + // RuntimeService interface should be implemented by a container runtime. // The methods should be thread-safe. type RuntimeService interface { - // Version returns the runtime name, runtime version and runtime API version - Version(apiVersion string) (*runtimeApi.VersionResponse, error) + RuntimeVersioner + // CreatePodSandbox creates a pod-level sandbox. // The definition of PodSandbox is at https://github.com/kubernetes/kubernetes/pull/25899 CreatePodSandbox(config *runtimeApi.PodSandboxConfig) (string, error) From f715aa475c6070ecdf876471f627b0bf4f32566f Mon Sep 17 00:00:00 2001 From: Tamer Tas Date: Tue, 16 Aug 2016 00:36:45 +0300 Subject: [PATCH 2/3] kubelet/api: extract ContainerManager interface --- pkg/kubelet/api/services.go | 42 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/pkg/kubelet/api/services.go b/pkg/kubelet/api/services.go index 94a37f999ca..06b8f16bf00 100644 --- a/pkg/kubelet/api/services.go +++ b/pkg/kubelet/api/services.go @@ -28,24 +28,9 @@ type RuntimeVersioner interface { Version(apiVersion string) (*runtimeApi.VersionResponse, error) } -// RuntimeService interface should be implemented by a container runtime. -// The methods should be thread-safe. -type RuntimeService interface { - RuntimeVersioner - - // CreatePodSandbox creates a pod-level sandbox. - // The definition of PodSandbox is at https://github.com/kubernetes/kubernetes/pull/25899 - CreatePodSandbox(config *runtimeApi.PodSandboxConfig) (string, error) - // StopPodSandbox stops the sandbox. If there are any running containers in the - // sandbox, they should be force terminated. - StopPodSandbox(podSandboxID string) error - // RemovePodSandbox removes the sandbox. If there are running containers in the - // sandbox, they should be forcibly removed. - RemovePodSandbox(podSandboxID string) error - // PodSandboxStatus returns the Status of the PodSandbox. - PodSandboxStatus(podSandboxID string) (*runtimeApi.PodSandboxStatus, error) - // ListPodSandbox returns a list of Sandbox. - ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]*runtimeApi.PodSandbox, error) +// ContainerManager contains methods to manipulate containers managed by a +// container runtime. The methods are thread-safe. +type ContainerManager interface { // CreateContainer creates a new container in specified PodSandbox. CreateContainer(podSandboxID string, config *runtimeApi.ContainerConfig, sandboxConfig *runtimeApi.PodSandboxConfig) (string, error) // StartContainer starts the container. @@ -62,6 +47,27 @@ type RuntimeService interface { Exec(containerID string, cmd []string, tty bool, stdin io.Reader, stdout, stderr io.WriteCloser) error } +// RuntimeService interface should be implemented by a container runtime. +// The methods should be thread-safe. +type RuntimeService interface { + RuntimeVersioner + ContainerManager + + // CreatePodSandbox creates a pod-level sandbox. + // The definition of PodSandbox is at https://github.com/kubernetes/kubernetes/pull/25899 + CreatePodSandbox(config *runtimeApi.PodSandboxConfig) (string, error) + // StopPodSandbox stops the sandbox. If there are any running containers in the + // sandbox, they should be force terminated. + StopPodSandbox(podSandboxID string) error + // RemovePodSandbox removes the sandbox. If there are running containers in the + // sandbox, they should be forcibly removed. + RemovePodSandbox(podSandboxID string) error + // PodSandboxStatus returns the Status of the PodSandbox. + PodSandboxStatus(podSandboxID string) (*runtimeApi.PodSandboxStatus, error) + // ListPodSandbox returns a list of Sandbox. + ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]*runtimeApi.PodSandbox, error) +} + // ImageManagerService interface should be implemented by a container image // manager. // The methods should be thread-safe. From f031f09efc5d10fea4f4f5a4bd4cfa3e670da9ba Mon Sep 17 00:00:00 2001 From: Tamer Tas Date: Tue, 16 Aug 2016 00:38:35 +0300 Subject: [PATCH 3/3] kubelet/api: extract PodSandboxManager interface Splits `RuntimeService` interface into smaller interfaces to make testing easier and to delineate responsibilities. --- pkg/kubelet/api/services.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/api/services.go b/pkg/kubelet/api/services.go index 06b8f16bf00..7a06cb38f55 100644 --- a/pkg/kubelet/api/services.go +++ b/pkg/kubelet/api/services.go @@ -47,12 +47,9 @@ type ContainerManager interface { Exec(containerID string, cmd []string, tty bool, stdin io.Reader, stdout, stderr io.WriteCloser) error } -// RuntimeService interface should be implemented by a container runtime. -// The methods should be thread-safe. -type RuntimeService interface { - RuntimeVersioner - ContainerManager - +// PodSandboxManager contains methods for operating on PodSandboxes. The methods +// are thread-safe. +type PodSandboxManager interface { // CreatePodSandbox creates a pod-level sandbox. // The definition of PodSandbox is at https://github.com/kubernetes/kubernetes/pull/25899 CreatePodSandbox(config *runtimeApi.PodSandboxConfig) (string, error) @@ -68,6 +65,14 @@ type RuntimeService interface { ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]*runtimeApi.PodSandbox, error) } +// RuntimeService interface should be implemented by a container runtime. +// The methods should be thread-safe. +type RuntimeService interface { + RuntimeVersioner + ContainerManager + PodSandboxManager +} + // ImageManagerService interface should be implemented by a container image // manager. // The methods should be thread-safe.