Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpod: Report network setup errors properly on FreeBSD #16554

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
dfr marked this conversation as resolved.
Show resolved Hide resolved
// 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