The code in question looks up mounts two times: first by using
HasMountFor(), and then directly by looking in container.MountPoints.
There is no need to do it twice.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
... | ... |
@@ -65,12 +65,11 @@ func (container *Container) NetworkMounts() []Mount { |
65 | 65 |
if _, err := os.Stat(container.ResolvConfPath); err != nil { |
66 | 66 |
logrus.Warnf("ResolvConfPath set to %q, but can't stat this filename (err = %v); skipping", container.ResolvConfPath, err) |
67 | 67 |
} else { |
68 |
- if !container.HasMountFor("/etc/resolv.conf") { |
|
69 |
- label.Relabel(container.ResolvConfPath, container.MountLabel, shared) |
|
70 |
- } |
|
71 | 68 |
writable := !container.HostConfig.ReadonlyRootfs |
72 | 69 |
if m, exists := container.MountPoints["/etc/resolv.conf"]; exists { |
73 | 70 |
writable = m.RW |
71 |
+ } else { |
|
72 |
+ label.Relabel(container.ResolvConfPath, container.MountLabel, shared) |
|
74 | 73 |
} |
75 | 74 |
mounts = append(mounts, Mount{ |
76 | 75 |
Source: container.ResolvConfPath, |
... | ... |
@@ -84,12 +83,11 @@ func (container *Container) NetworkMounts() []Mount { |
84 | 84 |
if _, err := os.Stat(container.HostnamePath); err != nil { |
85 | 85 |
logrus.Warnf("HostnamePath set to %q, but can't stat this filename (err = %v); skipping", container.HostnamePath, err) |
86 | 86 |
} else { |
87 |
- if !container.HasMountFor("/etc/hostname") { |
|
88 |
- label.Relabel(container.HostnamePath, container.MountLabel, shared) |
|
89 |
- } |
|
90 | 87 |
writable := !container.HostConfig.ReadonlyRootfs |
91 | 88 |
if m, exists := container.MountPoints["/etc/hostname"]; exists { |
92 | 89 |
writable = m.RW |
90 |
+ } else { |
|
91 |
+ label.Relabel(container.HostnamePath, container.MountLabel, shared) |
|
93 | 92 |
} |
94 | 93 |
mounts = append(mounts, Mount{ |
95 | 94 |
Source: container.HostnamePath, |
... | ... |
@@ -103,12 +101,11 @@ func (container *Container) NetworkMounts() []Mount { |
103 | 103 |
if _, err := os.Stat(container.HostsPath); err != nil { |
104 | 104 |
logrus.Warnf("HostsPath set to %q, but can't stat this filename (err = %v); skipping", container.HostsPath, err) |
105 | 105 |
} else { |
106 |
- if !container.HasMountFor("/etc/hosts") { |
|
107 |
- label.Relabel(container.HostsPath, container.MountLabel, shared) |
|
108 |
- } |
|
109 | 106 |
writable := !container.HostConfig.ReadonlyRootfs |
110 | 107 |
if m, exists := container.MountPoints["/etc/hosts"]; exists { |
111 | 108 |
writable = m.RW |
109 |
+ } else { |
|
110 |
+ label.Relabel(container.HostsPath, container.MountLabel, shared) |
|
112 | 111 |
} |
113 | 112 |
mounts = append(mounts, Mount{ |
114 | 113 |
Source: container.HostsPath, |