コード例 #1
0
ファイル: handler.go プロジェクト: Barba-studio/kubernetes
func newDockerContainerHandler(
	client *docker.Client,
	name string,
	machineInfoFactory info.MachineInfoFactory,
	useSystemd bool,
) (container.ContainerHandler, error) {
	handler := &dockerContainerHandler{
		client:             client,
		name:               name,
		machineInfoFactory: machineInfoFactory,
		useSystemd:         useSystemd,
	}
	if handler.isDockerRoot() {
		return handler, nil
	}
	parent, id, err := containerLibcontainer.SplitName(name)
	if err != nil {
		return nil, fmt.Errorf("invalid docker container %v: %v", name, err)
	}
	handler.parent = parent
	handler.id = id
	ctnr, err := client.InspectContainer(id)
	// We assume that if Inspect fails then the container is not known to docker.
	if err != nil {
		return nil, fmt.Errorf("failed to inspect container %s - %s\n", id, err)
	}
	handler.aliases = append(handler.aliases, path.Join("/docker", ctnr.Name))
	return handler, nil
}
コード例 #2
0
ファイル: factory.go プロジェクト: Barba-studio/kubernetes
// Docker handles all containers under /docker
// TODO(vishh): Change the CanHandle interface to be able to return errors.
func (self *dockerFactory) CanHandle(name string) bool {
	// In systemd systems the containers are: /system.slice/docker-{ID}
	if self.useSystemd {
		if !strings.HasPrefix(name, "/system.slice/docker-") {
			return false
		}
	} else if name == "/" {
		return false
	} else if name == "/docker" {
		// We need the docker driver to handle /docker. Otherwise the aggregation at the API level will break.
		return true
	} else if !strings.HasPrefix(name, "/docker/") {
		return false
	}
	// Check if the container is known to docker and it is active.
	_, id, err := libcontainer.SplitName(name)
	if err != nil {
		return false
	}
	ctnr, err := self.client.InspectContainer(id)
	// We assume that if Inspect fails then the container is not known to docker.
	// TODO(vishh): Detect lxc containers and avoid handling them.
	if err != nil || !ctnr.State.Running {
		return false
	}

	return true
}
コード例 #3
0
ファイル: handler.go プロジェクト: nyaxt/kubernetes
func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, machineInfoFactory info.MachineInfoFactory) (container.ContainerHandler, error) {
	parent, id, err := libcontainer.SplitName(name)
	if err != nil {
		return nil, err
	}
	return &rawContainerHandler{
		name: name,
		cgroup: &cgroups.Cgroup{
			Parent: parent,
			Name:   id,
		},
		cgroupSubsystems:   cgroupSubsystems,
		machineInfoFactory: machineInfoFactory,
	}, nil
}