chore: reduce memory usage of docker container info

This commit is contained in:
yusing
2025-04-10 04:56:50 +08:00
parent 49ee9c908a
commit 5d2b700cb2
3 changed files with 25 additions and 15 deletions

View File

@@ -15,7 +15,7 @@ import (
)
type (
PortMapping = map[int]container.Port
PortMapping = map[int]*container.Port
Container struct {
_ U.NoCopy
@@ -58,21 +58,12 @@ var DummyContainer = new(Container)
func FromDocker(c *container.Summary, dockerHost string) (res *Container) {
isExplicit := false
helper := containerHelper{c}
for lbl := range c.Labels {
if strings.HasPrefix(lbl, NSProxy+".") {
isExplicit = true
} else {
delete(c.Labels, lbl)
}
}
res = &Container{
DockerHost: dockerHost,
Image: helper.parseImage(),
ContainerName: helper.getName(),
ContainerID: c.ID,
Labels: c.Labels,
Mounts: helper.getMounts(),
PublicPortMapping: helper.getPublicPortMapping(),
@@ -100,11 +91,20 @@ func FromDocker(c *container.Summary, dockerHost string) (res *Container) {
res.setPrivateHostname(helper)
res.setPublicHostname()
for lbl := range c.Labels {
if strings.HasPrefix(lbl, NSProxy+".") {
isExplicit = true
} else {
delete(c.Labels, lbl)
}
}
res.RouteConfig = utils.FitMap(c.Labels)
return
}
func FromInspectResponse(json container.InspectResponse, dockerHost string) *Container {
ports := make([]container.Port, 0)
ports := make([]container.Port, 0, len(json.NetworkSettings.Ports))
for k, bindings := range json.NetworkSettings.Ports {
proto, privPortStr := nat.SplitProtoPort(string(k))
privPort, _ := strconv.ParseUint(privPortStr, 10, 16)