Fix /etc/hostname backward compatibility issue for in-place upgrade.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2019-03-12 01:17:41 -07:00
parent 25442a865c
commit 3691cb6550
2 changed files with 41 additions and 5 deletions

View File

@@ -483,11 +483,19 @@ func (c *criService) generateContainerMounts(sandboxID string, config *runtime.C
var mounts []*runtime.Mount
securityContext := config.GetLinux().GetSecurityContext()
if !isInCRIMounts(etcHostname, config.GetMounts()) {
mounts = append(mounts, &runtime.Mount{
ContainerPath: etcHostname,
HostPath: c.getSandboxHostname(sandboxID),
Readonly: securityContext.GetReadonlyRootfs(),
})
// /etc/hostname is added since 1.1.6, 1.2.4 and 1.3.
// For in-place upgrade, the old sandbox doesn't have the hostname file,
// do not mount this in that case.
// TODO(random-liu): Remove the check and always mount this when
// containerd 1.1 and 1.2 are deprecated.
hostpath := c.getSandboxHostname(sandboxID)
if _, err := c.os.Stat(hostpath); err == nil {
mounts = append(mounts, &runtime.Mount{
ContainerPath: etcHostname,
HostPath: hostpath,
Readonly: securityContext.GetReadonlyRootfs(),
})
}
}
if !isInCRIMounts(etcHosts, config.GetMounts()) {