matches with the full path of the container
This commit is contained in:
parent
99d2c31f4d
commit
4c740cbc54
@ -1,18 +0,0 @@
|
||||
package raw
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
cDesc, err := Unmarshal("test_resources/cdesc.json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error in unmarshalling: %s", err)
|
||||
}
|
||||
|
||||
if cDesc.All_hosts[0].NetworkInterface.VethHost != "veth24031eth1" &&
|
||||
cDesc.All_hosts[0].NetworkInterface.VethChild != "eth1" {
|
||||
t.Errorf("Cannot find network interface in %s", cDesc)
|
||||
}
|
||||
}
|
@ -23,27 +23,29 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_description.json", "container hints file")
|
||||
var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_hints.json", "container hints file")
|
||||
type containerHints struct {
|
||||
All_hosts []containerHint `json:"all_hosts,omitempty"`
|
||||
AllHosts []containerHint `json:"all_hosts,omitempty"`
|
||||
}
|
||||
|
||||
type containerHint struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
FullPath string `json:"full_path,omitempty"`
|
||||
NetworkInterface *networkInterface `json:"network_interface,omitempty"`
|
||||
}
|
||||
|
||||
type networkInterface struct {
|
||||
VethHost string `json:"VethHost,omitempty"`
|
||||
VethChild string `json:"VethChild,omitempty"`
|
||||
NsPath string `json:"NsPath,omitempty"`
|
||||
VethHost string `json:"veth_host,omitempty"`
|
||||
VethChild string `json:"veth_child,omitempty"`
|
||||
NsPath string `json:"ns_path,omitempty"`
|
||||
}
|
||||
|
||||
func Unmarshal(containerHintsFile string) (containerHints, error) {
|
||||
func getContainerHintsFromFile(containerHintsFile string) (containerHints, error) {
|
||||
dat, err := ioutil.ReadFile(containerHintsFile)
|
||||
var cDesc containerHints
|
||||
|
||||
var cHints containerHints
|
||||
if err == nil {
|
||||
err = json.Unmarshal(dat, &cDesc)
|
||||
err = json.Unmarshal(dat, &cHints)
|
||||
}
|
||||
return cDesc, err
|
||||
|
||||
return cHints, err
|
||||
}
|
18
container/raw/container_hints_test.go
Normal file
18
container/raw/container_hints_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
package raw
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
cHints, err := getContainerHintsFromFile("test_resources/container_hints.json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error in unmarshalling: %s", err)
|
||||
}
|
||||
|
||||
if cHints.AllHosts[0].NetworkInterface.VethHost != "veth24031eth1" &&
|
||||
cHints.AllHosts[0].NetworkInterface.VethChild != "eth1" {
|
||||
t.Errorf("Cannot find network interface in %s", cHints)
|
||||
}
|
||||
}
|
@ -52,20 +52,16 @@ func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, mac
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cDesc, err := Unmarshal(*argContainerHints)
|
||||
cHints, err := getContainerHintsFromFile(*argContainerHints)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
glog.Fatalf("Error unmarshalling json %s Error: %s", *argContainerHints, err)
|
||||
}
|
||||
var networkInterface *networkInterface
|
||||
for _, container := range cDesc.All_hosts {
|
||||
var cName string
|
||||
if strings.Contains(container.Id, "/") {
|
||||
cName = name
|
||||
} else {
|
||||
names := strings.SplitAfter(name, "/")
|
||||
cName = names[len(names)-1]
|
||||
for _, container := range cHints.AllHosts {
|
||||
if !strings.Contains(container.FullPath, "/") {
|
||||
glog.Fatalf("Invalid container fullPath %s", container.FullPath)
|
||||
}
|
||||
if cName == container.Id {
|
||||
if name == container.FullPath {
|
||||
networkInterface = container.NetworkInterface
|
||||
break
|
||||
}
|
||||
|
@ -1,22 +1,11 @@
|
||||
{
|
||||
"name": "Container specification",
|
||||
"description": "Container specification",
|
||||
"name": "Container Hints",
|
||||
"description": "Container hints file",
|
||||
"all_hosts": [
|
||||
{
|
||||
"name": "10-10-10-27",
|
||||
"ip": "10.10.10.27/24",
|
||||
"publish": null,
|
||||
"gateway": null,
|
||||
"hostname": "10-10-10-27.local.altiscale.com",
|
||||
"privileged": "true",
|
||||
"init": null,
|
||||
"cpu": null,
|
||||
"memory": null,
|
||||
"net": null,
|
||||
"netinit": "false",
|
||||
"network_interface": {
|
||||
"VethChild": "eth1",
|
||||
"VethHost": "veth24031eth1"
|
||||
"veth_child": "eth1",
|
||||
"veth_host": "veth24031eth1"
|
||||
},
|
||||
"mounts": [
|
||||
{
|
||||
@ -45,7 +34,7 @@
|
||||
"permission": "rw"
|
||||
}
|
||||
],
|
||||
"id": "18a4585950db428e4d5a65c216a5d708d241254709626f4cb300ee963fb4b144"
|
||||
"full_path": "18a4585950db428e4d5a65c216a5d708d241254709626f4cb300ee963fb4b144"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user