-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15560 from dfr/freebsd-specgen
Add FreeBSD support for pkg/specgen/generate
- Loading branch information
Showing
12 changed files
with
721 additions
and
495 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package generate | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/containers/podman/v4/libpod" | ||
"github.com/containers/podman/v4/pkg/specgen" | ||
"github.com/opencontainers/runtime-tools/generate" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func specConfigureNamespaces(s *specgen.SpecGenerator, g *generate.Generator, rt *libpod.Runtime, pod *libpod.Pod) error { | ||
// UTS | ||
|
||
hostname := s.Hostname | ||
if hostname == "" { | ||
switch { | ||
case s.UtsNS.NSMode == specgen.FromPod: | ||
hostname = pod.Hostname() | ||
case s.UtsNS.NSMode == specgen.FromContainer: | ||
utsCtr, err := rt.LookupContainer(s.UtsNS.Value) | ||
if err != nil { | ||
return fmt.Errorf("error looking up container to share uts namespace with: %w", err) | ||
} | ||
hostname = utsCtr.Hostname() | ||
case (s.NetNS.NSMode == specgen.Host && hostname == "") || s.UtsNS.NSMode == specgen.Host: | ||
tmpHostname, err := os.Hostname() | ||
if err != nil { | ||
return fmt.Errorf("unable to retrieve hostname of the host: %w", err) | ||
} | ||
hostname = tmpHostname | ||
default: | ||
logrus.Debug("No hostname set; container's hostname will default to runtime default") | ||
} | ||
} | ||
|
||
g.RemoveHostname() | ||
if s.Hostname != "" || s.UtsNS.NSMode != specgen.Host { | ||
// Set the hostname in the OCI configuration only if specified by | ||
// the user or if we are creating a new UTS namespace. | ||
// TODO: Should we be doing this for pod or container shared | ||
// namespaces? | ||
g.SetHostname(hostname) | ||
} | ||
if _, ok := s.Env["HOSTNAME"]; !ok && s.Hostname != "" { | ||
g.AddProcessEnv("HOSTNAME", hostname) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.