sandbox: record whether sb is using host network

We need to record whether the sandbox is using hostnetwok because the
kubelet needs that information when computing pod changes. Without this
patch it could happen that a pod that's using host network is restarted
just because the sandbox's status isn't reporting that it's running
using host network.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2018-02-13 11:45:31 +01:00
parent 9128ffc226
commit ab204b6641
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
5 changed files with 27 additions and 0 deletions

View file

@ -340,6 +340,7 @@ func (c *ContainerServer) LoadSandbox(id string) error {
privileged := isTrue(m.Annotations[annotations.PrivilegedRuntime])
trusted := isTrue(m.Annotations[annotations.TrustedSandbox])
hostNetwork := isTrue(m.Annotations[annotations.HostNetwork])
sb, err := sandbox.New(id, m.Annotations[annotations.Namespace], name, m.Annotations[annotations.KubeName], filepath.Dir(m.Annotations[annotations.LogPath]), labels, kubeAnnotations, processLabel, mountLabel, &metadata, m.Annotations[annotations.ShmPath], m.Annotations[annotations.CgroupParent], privileged, trusted, m.Annotations[annotations.ResolvPath], m.Annotations[annotations.HostName], portMappings)
if err != nil {
@ -348,6 +349,7 @@ func (c *ContainerServer) LoadSandbox(id string) error {
sb.AddHostnamePath(m.Annotations[annotations.HostnamePath])
sb.AddIP(ip)
sb.SetSeccompProfilePath(spp)
sb.SetHostNetwork(hostNetwork)
// We add a netNS only if we can load a permanent one.
// Otherwise, the sandbox will live in the host namespace.

View file

@ -160,6 +160,7 @@ type Sandbox struct {
ip string
seccompProfilePath string
created time.Time
hostNetwork bool
}
const (
@ -224,6 +225,16 @@ func (s *Sandbox) AddIP(ip string) {
s.ip = ip
}
// SetHostNetwork sets whether the pod is running using host network
func (s *Sandbox) SetHostNetwork(hn bool) {
s.hostNetwork = hn
}
// HostNetwork returns whether the pod is using host network
func (s *Sandbox) HostNetwork() bool {
return s.hostNetwork
}
// IP returns the ip of the sandbox
func (s *Sandbox) IP() string {
return s.ip