Skip to content

Commit

Permalink
Merge pull request #16554 from dfr/freebsd-network-errors
Browse files Browse the repository at this point in the history
libpod: Report network setup errors properly on FreeBSD
  • Loading branch information
openshift-merge-robot authored Nov 23, 2022
2 parents 1b583a7 + 504fcbb commit 34cc61d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
19 changes: 19 additions & 0 deletions libpod/container_internal_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,33 @@ func (c *Container) prepare() error {
wg.Wait()

var createErr error
if createNetNSErr != nil {
createErr = createNetNSErr
}
if mountStorageErr != nil {
if createErr != nil {
logrus.Errorf("Preparing container %s: %v", c.ID(), createErr)
}
createErr = mountStorageErr
}

// Only trigger storage cleanup if mountStorage was successful.
// Otherwise, we may mess up mount counters.
if createErr != nil {
if mountStorageErr == nil {
if err := c.cleanupStorage(); err != nil {
// createErr is guaranteed non-nil, so print
// unconditionally
logrus.Errorf("Preparing container %s: %v", c.ID(), createErr)
createErr = fmt.Errorf("unmounting storage for container %s after network create failure: %w", c.ID(), err)
}
}
// It's OK to unconditionally trigger network cleanup. If the network
// isn't ready it will do nothing.
if err := c.cleanupNetwork(); err != nil {
logrus.Errorf("Preparing container %s: %v", c.ID(), createErr)
createErr = fmt.Errorf("cleaning up container %s network after setup failure: %w", c.ID(), err)
}
return createErr
}

Expand Down
13 changes: 11 additions & 2 deletions libpod/networking_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,23 @@ func (r *Runtime) createNetNS(ctr *Container) (n *jailNetNS, q map[string]types.
jconf.Set("allow.raw_sockets", true)
jconf.Set("allow.chflags", true)
jconf.Set("securelevel", -1)
if _, err := jail.Create(jconf); err != nil {
logrus.Debugf("Failed to create vnet jail %s for container %s", ctrNS.Name, ctr.ID())
j, err := jail.Create(jconf)
if err != nil {
return nil, nil, fmt.Errorf("Failed to create vnet jail %s for container %s: %w", ctrNS.Name, ctr.ID(), err)
}

logrus.Debugf("Created vnet jail %s for container %s", ctrNS.Name, ctr.ID())

var networkStatus map[string]types.StatusBlock
networkStatus, err = r.configureNetNS(ctr, ctrNS)
if err != nil {
jconf := jail.NewConfig()
jconf.Set("persist", false)
if err := j.Set(jconf); err != nil {
// Log this error and return the error from configureNetNS
logrus.Errorf("failed to destroy vnet jail %s: %w", ctrNS.Name, err)
}
}
return ctrNS, networkStatus, err
}

Expand Down

0 comments on commit 34cc61d

Please sign in to comment.