move ListContainers code to common and make rkt play nice
playing nice means not elliding the system.slice cgroup but allowing the raw handler to handle it
This commit is contained in:
parent
ae814a5fff
commit
5ca11bb1a0
@ -23,6 +23,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/cadvisor/container"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
"github.com/google/cadvisor/utils"
|
"github.com/google/cadvisor/utils"
|
||||||
|
|
||||||
@ -201,3 +202,23 @@ func CgroupExists(cgroupPaths map[string]string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ListContainers(name string, cgroupPaths map[string]string, listType container.ListType) ([]info.ContainerReference, error) {
|
||||||
|
containers := make(map[string]struct{})
|
||||||
|
for _, cgroupPath := range cgroupPaths {
|
||||||
|
err := ListDirectories(cgroupPath, name, listType == container.ListRecursive, containers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make into container references.
|
||||||
|
ret := make([]info.ContainerReference, 0, len(containers))
|
||||||
|
for cont := range containers {
|
||||||
|
ret = append(ret, info.ContainerReference{
|
||||||
|
Name: cont,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
@ -269,23 +269,7 @@ func (self *rawContainerHandler) GetContainerLabels() map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *rawContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) {
|
func (self *rawContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) {
|
||||||
containers := make(map[string]struct{})
|
return common.ListContainers(self.name, self.cgroupPaths, listType)
|
||||||
for _, cgroupPath := range self.cgroupPaths {
|
|
||||||
err := common.ListDirectories(cgroupPath, self.name, listType == container.ListRecursive, containers)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make into container references.
|
|
||||||
ret := make([]info.ContainerReference, 0, len(containers))
|
|
||||||
for cont := range containers {
|
|
||||||
ret = append(ret, info.ContainerReference{
|
|
||||||
Name: cont,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *rawContainerHandler) ListThreads(listType container.ListType) ([]int, error) {
|
func (self *rawContainerHandler) ListThreads(listType container.ListType) ([]int, error) {
|
||||||
|
@ -63,7 +63,7 @@ func (self *rktFactory) CanHandleAndAccept(name string) (bool, bool, error) {
|
|||||||
|
|
||||||
if strings.HasPrefix(name, "/machine.slice/machine-rkt\\x2d") {
|
if strings.HasPrefix(name, "/machine.slice/machine-rkt\\x2d") {
|
||||||
accept, err := verifyName(name)
|
accept, err := verifyName(name)
|
||||||
return true, accept, err
|
return accept, accept, err
|
||||||
}
|
}
|
||||||
return false, false, fmt.Errorf("%s not handled by rkt handler", name)
|
return false, false, fmt.Errorf("%s not handled by rkt handler", name)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package rkt
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rktapi "github.com/coreos/rkt/api/v1alpha"
|
rktapi "github.com/coreos/rkt/api/v1alpha"
|
||||||
@ -260,48 +259,7 @@ func (handler *rktContainerHandler) GetContainerLabels() map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *rktContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) {
|
func (handler *rktContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) {
|
||||||
containers := make(map[string]struct{})
|
return common.ListContainers(handler.name, handler.cgroupPaths, listType)
|
||||||
|
|
||||||
// Rkt containers do not have subcontainers, only the "Pod" does.
|
|
||||||
if handler.isPod == false {
|
|
||||||
var ret []info.ContainerReference
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn the system.slice cgroups into the Pod's subcontainers
|
|
||||||
for _, cgroupPath := range handler.cgroupPaths {
|
|
||||||
err := common.ListDirectories(path.Join(cgroupPath, "system.slice"), path.Join(handler.name, "system.slice"), listType == container.ListRecursive, containers)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the container references. for the Pod's subcontainers
|
|
||||||
ret := make([]info.ContainerReference, 0, len(handler.apiPod.Apps))
|
|
||||||
for cont := range containers {
|
|
||||||
aliases := make([]string, 1)
|
|
||||||
parsed, err := parseName(cont)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("this should be impossible!, unable to parse rkt subcontainer name = %s", cont)
|
|
||||||
}
|
|
||||||
aliases = append(aliases, parsed.Pod+":"+parsed.Container)
|
|
||||||
|
|
||||||
labels := make(map[string]string)
|
|
||||||
if annotations, ok := findAnnotations(handler.apiPod.Apps, parsed.Container); !ok {
|
|
||||||
glog.Warningf("couldn't find application in Pod matching %v", parsed.Container)
|
|
||||||
} else {
|
|
||||||
labels = createLabels(annotations)
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = append(ret, info.ContainerReference{
|
|
||||||
Name: cont,
|
|
||||||
Aliases: aliases,
|
|
||||||
Namespace: RktNamespace,
|
|
||||||
Labels: labels,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *rktContainerHandler) ListThreads(listType container.ListType) ([]int, error) {
|
func (handler *rktContainerHandler) ListThreads(listType container.ListType) ([]int, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user