* fixed parsing of docker image name/version now accounts for custom docker repo's which contain a colon for a non-default port * 1978: modifying docker test case to have a custom repo with non-standard port * using a temp var to store index, ran gofmt * fixes #1987, renaming iterator to 'i'
This commit is contained in:
parent
4a83c8c518
commit
3a45d8851d
|
@ -221,14 +221,18 @@ func (d *Docker) gatherContainer(
|
||||||
cname = strings.TrimPrefix(container.Names[0], "/")
|
cname = strings.TrimPrefix(container.Names[0], "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// the image name sometimes has a version part.
|
// the image name sometimes has a version part, or a private repo
|
||||||
// ie, rabbitmq:3-management
|
// ie, rabbitmq:3-management or docker.someco.net:4443/rabbitmq:3-management
|
||||||
imageParts := strings.Split(container.Image, ":")
|
imageName := ""
|
||||||
imageName := imageParts[0]
|
|
||||||
imageVersion := "unknown"
|
imageVersion := "unknown"
|
||||||
if len(imageParts) > 1 {
|
i := strings.LastIndex(container.Image, ":") // index of last ':' character
|
||||||
imageVersion = imageParts[1]
|
if i > -1 {
|
||||||
|
imageVersion = container.Image[i+1:]
|
||||||
|
imageName = container.Image[:i]
|
||||||
|
} else {
|
||||||
|
imageName = container.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"engine_host": d.engine_host,
|
"engine_host": d.engine_host,
|
||||||
"container_name": cname,
|
"container_name": cname,
|
||||||
|
|
|
@ -340,7 +340,7 @@ func (d FakeDockerClient) ContainerList(octx context.Context, options types.Cont
|
||||||
container2 := types.Container{
|
container2 := types.Container{
|
||||||
ID: "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
|
ID: "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
|
||||||
Names: []string{"/etcd2"},
|
Names: []string{"/etcd2"},
|
||||||
Image: "quay.io/coreos/etcd:v2.2.2",
|
Image: "quay.io:4443/coreos/etcd:v2.2.2",
|
||||||
Command: "/etcd -name etcd2 -advertise-client-urls http://localhost:2379 -listen-client-urls http://0.0.0.0:2379",
|
Command: "/etcd -name etcd2 -advertise-client-urls http://localhost:2379 -listen-client-urls http://0.0.0.0:2379",
|
||||||
Created: 1455941933,
|
Created: 1455941933,
|
||||||
Status: "Up 4 hours",
|
Status: "Up 4 hours",
|
||||||
|
@ -429,7 +429,7 @@ func TestDockerGatherInfo(t *testing.T) {
|
||||||
},
|
},
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"container_name": "etcd2",
|
"container_name": "etcd2",
|
||||||
"container_image": "quay.io/coreos/etcd",
|
"container_image": "quay.io:4443/coreos/etcd",
|
||||||
"cpu": "cpu3",
|
"cpu": "cpu3",
|
||||||
"container_version": "v2.2.2",
|
"container_version": "v2.2.2",
|
||||||
"engine_host": "absol",
|
"engine_host": "absol",
|
||||||
|
@ -477,7 +477,7 @@ func TestDockerGatherInfo(t *testing.T) {
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"engine_host": "absol",
|
"engine_host": "absol",
|
||||||
"container_name": "etcd2",
|
"container_name": "etcd2",
|
||||||
"container_image": "quay.io/coreos/etcd",
|
"container_image": "quay.io:4443/coreos/etcd",
|
||||||
"container_version": "v2.2.2",
|
"container_version": "v2.2.2",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue