libpod: unset network state in reloadContainerNetwork

Ensure we set the network status to nil after the teardown and save it
to the db. This is needed on network reload as the setup reads the
existing status for the pesto forwarding logic.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2026-07-28 16:17:41 +02:00
parent aab2abf646
commit 2b5572b0a6
No known key found for this signature in database
GPG key ID: EB145DD938A3CAF2
3 changed files with 18 additions and 9 deletions

View file

@ -162,10 +162,20 @@ func (r *Runtime) reloadContainerNetwork(ctr *Container) (map[string]types.Statu
}
logrus.Infof("Going to reload container %s network", ctr.ID())
// store the old status before unsetting it
netStatus := ctr.getNetworkStatus()
err := r.teardownNetwork(ctr)
if err != nil {
logrus.Error(err)
}
// We must unset the network status here so
ctr.state.NetworkStatus = nil
// always save even when there was an error
err = ctr.save()
if err != nil {
return nil, fmt.Errorf("failed to save container status after network teardown: %w", err)
}
networkOpts, err := ctr.networks()
if err != nil {
@ -173,7 +183,6 @@ func (r *Runtime) reloadContainerNetwork(ctr *Container) (map[string]types.Statu
}
// Set the same network settings as before..
netStatus := ctr.getNetworkStatus()
newNetworkOpts := make([]types.NamedPerNetworkOptions, 0, len(networkOpts))
for _, network := range networkOpts {
for name, netInt := range netStatus[network.Name].Interfaces {
@ -190,7 +199,7 @@ func (r *Runtime) reloadContainerNetwork(ctr *Container) (map[string]types.Statu
}
ctr.perNetworkOpts = newNetworkOpts
return r.configureNetNS(ctr, ctr.state.NetNS)
return r.configureNetNS(ctr, ctr.state.NetNS, true)
}
// Produce an InspectNetworkSettings containing information on the container

View file

@ -47,14 +47,14 @@ type NetstatAddress struct {
// started. We can use this to initialise the container's vnet when we don't
// have a separate vnet jail (which is the case in FreeBSD 13.3 and later).
func (r *Runtime) setupNetNS(ctr *Container) error {
networkStatus, err := r.configureNetNS(ctr, ctr.ID())
networkStatus, err := r.configureNetNS(ctr, ctr.ID(), false)
ctr.state.NetNS = ctr.ID()
ctr.state.NetworkStatus = networkStatus
return err
}
// Create and configure a new network namespace for a container
func (r *Runtime) configureNetNS(ctr *Container, ctrNS string) (status map[string]types.StatusBlock, rerr error) {
func (r *Runtime) configureNetNS(ctr *Container, ctrNS string, _ bool) (status map[string]types.StatusBlock, rerr error) {
if err := r.exposeMachinePorts(ctr.config.PortMappings); err != nil {
return nil, err
}
@ -112,7 +112,7 @@ func (r *Runtime) createNetNS(ctr *Container) (n string, q map[string]types.Stat
logrus.Debugf("Created vnet jail %s for container %s", netns, ctr.ID())
var networkStatus map[string]types.StatusBlock
networkStatus, err = r.configureNetNS(ctr, netns)
networkStatus, err = r.configureNetNS(ctr, netns, false)
if err != nil {
jconf := jail.NewConfig()
jconf.Set("persist", false)

View file

@ -18,7 +18,7 @@ import (
)
// Create and configure a new network namespace for a container
func (r *Runtime) configureNetNS(ctr *Container, ctrNS string) (status map[string]types.StatusBlock, rerr error) {
func (r *Runtime) configureNetNS(ctr *Container, ctrNS string, reload bool) (status map[string]types.StatusBlock, rerr error) {
if err := r.exposeMachinePorts(ctr.config.PortMappings); err != nil {
return nil, err
}
@ -68,7 +68,7 @@ func (r *Runtime) configureNetNS(ctr *Container, ctrNS string) (status map[strin
case config.RootlessPortForwarderPasta:
// Handled by container-libs netavark Setup()
case config.RootlessPortForwarderRootlessport, "":
if ctr.getNetworkStatus() == nil {
if !reload {
err = r.setupRootlessPortMappingViaRLK(ctr, ctrNS, netStatus)
}
default:
@ -99,7 +99,7 @@ func (r *Runtime) createNetNS(ctr *Container) (n string, q map[string]types.Stat
logrus.Debugf("Made network namespace at %s for container %s", ctrNS.Path(), ctr.ID())
var networkStatus map[string]types.StatusBlock
networkStatus, err = r.configureNetNS(ctr, ctrNS.Path())
networkStatus, err = r.configureNetNS(ctr, ctrNS.Path(), false)
return ctrNS.Path(), networkStatus, err
}
@ -111,7 +111,7 @@ func (r *Runtime) setupNetNS(ctr *Container) error {
return err
}
networkStatus, err := r.configureNetNS(ctr, nsPath)
networkStatus, err := r.configureNetNS(ctr, nsPath, false)
// Assign NetNS attributes to container
ctr.state.NetNS = nsPath