docker_service.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package dockershim
  14. import (
  15. "fmt"
  16. "io"
  17. "k8s.io/kubernetes/pkg/api"
  18. internalApi "k8s.io/kubernetes/pkg/kubelet/api"
  19. runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
  20. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  21. "k8s.io/kubernetes/pkg/kubelet/dockertools"
  22. )
  23. const (
  24. dockerRuntimeName = "docker"
  25. kubeAPIVersion = "0.1.0"
  26. // String used to detect docker host mode for various namespaces (e.g.
  27. // networking). Must match the value returned by docker inspect -f
  28. // '{{.HostConfig.NetworkMode}}'.
  29. namespaceModeHost = "host"
  30. dockerNetNSFmt = "/proc/%v/ns/net"
  31. defaultSeccompProfile = "unconfined"
  32. // Internal docker labels used to identify whether a container is a sandbox
  33. // or a regular container.
  34. // TODO: This is not backward compatible with older containers. We will
  35. // need to add filtering based on names.
  36. containerTypeLabelKey = "io.kubernetes.docker.type"
  37. containerTypeLabelSandbox = "podsandbox"
  38. containerTypeLabelContainer = "container"
  39. )
  40. func NewDockerSevice(client dockertools.DockerInterface) DockerLegacyService {
  41. return &dockerService{
  42. client: dockertools.NewInstrumentedDockerInterface(client),
  43. }
  44. }
  45. // DockerLegacyService is an interface that embeds both the new
  46. // RuntimeService and ImageService interfaces, while including legacy methods
  47. // for backward compatibility.
  48. type DockerLegacyService interface {
  49. internalApi.RuntimeService
  50. internalApi.ImageManagerService
  51. // Supporting legacy methods for docker.
  52. GetContainerLogs(pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, stdout, stderr io.Writer) (err error)
  53. kubecontainer.ContainerAttacher
  54. PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error
  55. }
  56. type dockerService struct {
  57. client dockertools.DockerInterface
  58. }
  59. // Version returns the runtime name, runtime version and runtime API version
  60. func (ds *dockerService) Version(apiVersion string) (*runtimeApi.VersionResponse, error) {
  61. v, err := ds.client.Version()
  62. if err != nil {
  63. return nil, fmt.Errorf("docker: failed to get docker version: %v", err)
  64. }
  65. runtimeAPIVersion := kubeAPIVersion
  66. name := dockerRuntimeName
  67. return &runtimeApi.VersionResponse{
  68. Version: &runtimeAPIVersion,
  69. RuntimeName: &name,
  70. RuntimeVersion: &v.Version,
  71. RuntimeApiVersion: &v.APIVersion,
  72. }, nil
  73. }