Skip to content

Commit

Permalink
Merge pull request #15357 from dfr/freebsd-build
Browse files Browse the repository at this point in the history
Add non-linux build stubs for libpod
  • Loading branch information
openshift-merge-robot authored Aug 17, 2022
2 parents c90eec2 + 1572420 commit c2f9ab1
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 16 deletions.
19 changes: 19 additions & 0 deletions libpod/boltdb_state_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"
)

// replaceNetNS handle network namespace transitions after updating a
// container's state.
func replaceNetNS(netNSPath string, ctr *Container, newState *ContainerState) error {
return errors.New("replaceNetNS not supported on this platform")
}

// getNetNSPath retrieves the netns path to be stored in the database
func getNetNSPath(ctr *Container) string {
return ""
}
17 changes: 17 additions & 0 deletions libpod/container_copy_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"
"io"
)

func (c *Container) copyFromArchive(path string, chown, noOverwriteDirNonDir bool, rename map[string]string, reader io.Reader) (func() error, error) {
return nil, errors.New("not implemented (*Container) copyFromArchive")
}

func (c *Container) copyToArchive(path string, writer io.Writer) (func() error, error) {
return nil, errors.New("not implemented (*Container) copyToArchive")
}
20 changes: 4 additions & 16 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,8 @@ func (c *Container) handleRestartPolicy(ctx context.Context) (_ bool, retErr err
}

// set up slirp4netns again because slirp4netns will die when conmon exits
if c.config.NetMode.IsSlirp4netns() {
err := c.runtime.setupSlirp4netns(c, c.state.NetNS)
if err != nil {
return false, err
}
}

// set up rootlesskit port forwarder again since it dies when conmon exits
// we use rootlesskit port forwarder only as rootless and when bridge network is used
if rootless.IsRootless() && c.config.NetMode.IsBridge() && len(c.config.PortMappings) > 0 {
err := c.runtime.setupRootlessPortMappingViaRLK(c, c.state.NetNS.Path(), c.state.NetworkStatus)
if err != nil {
return false, err
}
if err := c.setupRootlessNetwork(); err != nil {
return false, err
}

if c.state.State == define.ContainerStateStopped {
Expand Down Expand Up @@ -1557,7 +1545,7 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {

rootUID, rootGID := c.RootUID(), c.RootGID()

dirfd, err := unix.Open(mountPoint, unix.O_RDONLY|unix.O_PATH, 0)
dirfd, err := openDirectory(mountPoint)
if err != nil {
return "", fmt.Errorf("open mount point: %w", err)
}
Expand All @@ -1580,7 +1568,7 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
return "", fmt.Errorf("resolve /etc in the container: %w", err)
}

etcInTheContainerFd, err := unix.Open(etcInTheContainerPath, unix.O_RDONLY|unix.O_PATH, 0)
etcInTheContainerFd, err := openDirectory(etcInTheContainerPath)
if err != nil {
return "", fmt.Errorf("open /etc in the container: %w", err)
}
Expand Down
25 changes: 25 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3228,3 +3228,28 @@ func (c *Container) ChangeHostPathOwnership(src string, recurse bool, uid, gid i
}
return chown.ChangeHostPathOwnership(src, recurse, uid, gid)
}

// If the container is rootless, set up the slirp4netns network
func (c *Container) setupRootlessNetwork() error {
// set up slirp4netns again because slirp4netns will die when conmon exits
if c.config.NetMode.IsSlirp4netns() {
err := c.runtime.setupSlirp4netns(c, c.state.NetNS)
if err != nil {
return err
}
}

// set up rootlesskit port forwarder again since it dies when conmon exits
// we use rootlesskit port forwarder only as rootless and when bridge network is used
if rootless.IsRootless() && c.config.NetMode.IsBridge() && len(c.config.PortMappings) > 0 {
err := c.runtime.setupRootlessPortMappingViaRLK(c, c.state.NetNS.Path(), c.state.NetworkStatus)
if err != nil {
return err
}
}
return nil
}

func openDirectory(path string) (fd int, err error) {
return unix.Open(path, unix.O_RDONLY|unix.O_PATH, 0)
}
99 changes: 99 additions & 0 deletions libpod/container_internal_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//go:build !linux
// +build !linux

package libpod

import (
"context"
"errors"

"github.com/containers/common/libnetwork/etchosts"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/lookup"
spec "github.com/opencontainers/runtime-spec/specs-go"
)

func (c *Container) mountSHM(shmOptions string) error {
return errors.New("not implemented (*Container) mountSHM")
}

func (c *Container) unmountSHM(mount string) error {
return errors.New("not implemented (*Container) unmountSHM")
}

func (c *Container) cleanupOverlayMounts() error {
return errors.New("not implemented (*Container) cleanupOverlayMounts")
}

// prepare mounts the container and sets up other required resources like net
// namespaces
func (c *Container) prepare() error {
return errors.New("not implemented (*Container) prepare")
}

// resolveWorkDir resolves the container's workdir and, depending on the
// configuration, will create it, or error out if it does not exist.
// Note that the container must be mounted before.
func (c *Container) resolveWorkDir() error {
return errors.New("not implemented (*Container) resolveWorkDir")
}

// cleanupNetwork unmounts and cleans up the container's network
func (c *Container) cleanupNetwork() error {
return errors.New("not implemented (*Container) cleanupNetwork")
}

// reloadNetwork reloads the network for the given container, recreating
// firewall rules.
func (c *Container) reloadNetwork() error {
return errors.New("not implemented (*Container) reloadNetwork")
}

// Generate spec for a container
// Accepts a map of the container's dependencies
func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
return nil, errors.New("not implemented (*Container) generateSpec")
}

func (c *Container) getUserOverrides() *lookup.Overrides {
return &lookup.Overrides{}
}

func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (*define.CRIUCheckpointRestoreStatistics, int64, error) {
return nil, 0, errors.New("not implemented (*Container) checkpoint")
}

func (c *Container) restore(ctx context.Context, options ContainerCheckpointOptions) (criuStatistics *define.CRIUCheckpointRestoreStatistics, runtimeRestoreDuration int64, retErr error) {
return nil, 0, errors.New("not implemented (*Container) restore")
}

// getHostsEntries returns the container ip host entries for the correct netmode
func (c *Container) getHostsEntries() (etchosts.HostEntries, error) {
return nil, errors.New("unspported (*Container) getHostsEntries")
}

// Fix ownership and permissions of the specified volume if necessary.
func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
return errors.New("unspported (*Container) fixVolumePermissions")
}

func (c *Container) expectPodCgroup() (bool, error) {
return false, errors.New("unspported (*Container) expectPodCgroup")
}

// Get cgroup path in a format suitable for the OCI spec
func (c *Container) getOCICgroupPath() (string, error) {
return "", errors.New("unspported (*Container) getOCICgroupPath")
}

func getLocalhostHostEntry(c *Container) etchosts.HostEntries {
return nil
}

func isRootlessCgroupSet(cgroup string) bool {
return false
}

func openDirectory(path string) (fd int, err error) {
return -1, errors.New("unsupported openDirectory")
}
14 changes: 14 additions & 0 deletions libpod/container_stat_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"

"github.com/containers/podman/v4/libpod/define"
)

func (c *Container) stat(containerMountPoint string, containerPath string) (*define.FileInfo, string, string, error) {
return nil, "", "", errors.New("Containers stat not supported on this platform")
}
14 changes: 14 additions & 0 deletions libpod/container_top_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"
)

// Top gathers statistics about the running processes in a container. It returns a
// []string for output
func (c *Container) Top(descriptors []string) ([]string, error) {
return nil, errors.New("not implemented (*Container) Top")
}
7 changes: 7 additions & 0 deletions libpod/container_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !linux
// +build !linux

package libpod

type containerPlatformState struct {
}
25 changes: 25 additions & 0 deletions libpod/healthcheck_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !linux
// +build !linux

package libpod

import (
"context"
"errors"
)

// createTimer systemd timers for healthchecks of a container
func (c *Container) createTimer() error {
return errors.New("not implemented (*Container) createTimer")
}

// startTimer starts a systemd timer for the healthchecks
func (c *Container) startTimer() error {
return errors.New("not implemented (*Container) startTimer")
}

// removeTransientFiles removes the systemd timer and unit files
// for the container
func (c *Container) removeTransientFiles(ctx context.Context) error {
return errors.New("not implemented (*Container) removeTransientFiles")
}
3 changes: 3 additions & 0 deletions libpod/info.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

package libpod

import (
Expand Down
14 changes: 14 additions & 0 deletions libpod/info_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"

"github.com/containers/podman/v4/libpod/define"
)

func (r *Runtime) info() (*define.Info, error) {
return nil, errors.New("not implemented (*Runtime) info")
}
79 changes: 79 additions & 0 deletions libpod/networking_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"
"path/filepath"

"github.com/containers/common/libnetwork/types"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/storage/pkg/lockfile"
)

type RootlessNetNS struct {
dir string
Lock lockfile.Locker
}

// ocicniPortsToNetTypesPorts convert the old port format to the new one
// while deduplicating ports into ranges
func ocicniPortsToNetTypesPorts(ports []types.OCICNIPortMapping) []types.PortMapping {
return []types.PortMapping{}
}

func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, error) {
return nil, errors.New("not implemented (*Container) getContainerNetworkInfo")
}

func (c *Container) setupRootlessNetwork() error {
return errors.New("not implemented (*Container) setupRootlessNetwork")
}

func (r *Runtime) setupNetNS(ctr *Container) error {
return errors.New("not implemented (*Runtime) setupNetNS")
}

// normalizeNetworkName takes a network name, a partial or a full network ID and returns the network name.
// If the network is not found a errors is returned.
func (r *Runtime) normalizeNetworkName(nameOrID string) (string, error) {
return "", errors.New("not implemented (*Runtime) normalizeNetworkName")
}

// DisconnectContainerFromNetwork removes a container from its CNI network
func (r *Runtime) DisconnectContainerFromNetwork(nameOrID, netName string, force bool) error {
return errors.New("not implemented (*Runtime) DisconnectContainerFromNetwork")
}

// ConnectContainerToNetwork connects a container to a CNI network
func (r *Runtime) ConnectContainerToNetwork(nameOrID, netName string, netOpts types.PerNetworkOptions) error {
return errors.New("not implemented (*Runtime) ConnectContainerToNetwork")
}

// getPath will join the given path to the rootless netns dir
func (r *RootlessNetNS) getPath(path string) string {
return filepath.Join(r.dir, path)
}

// Do - run the given function in the rootless netns.
// It does not lock the rootlessCNI lock, the caller
// should only lock when needed, e.g. for cni operations.
func (r *RootlessNetNS) Do(toRun func() error) error {
return errors.New("not implemented (*RootlessNetNS) Do")
}

// Cleanup the rootless network namespace if needed.
// It checks if we have running containers with the bridge network mode.
// Cleanup() expects that r.Lock is locked
func (r *RootlessNetNS) Cleanup(runtime *Runtime) error {
return errors.New("not implemented (*RootlessNetNS) Cleanup")
}

// GetRootlessNetNs returns the rootless netns object. If create is set to true
// the rootless network namespace will be created if it does not exists already.
// If called as root it returns always nil.
// On success the returned RootlessCNI lock is locked and must be unlocked by the caller.
func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
return nil, errors.New("not implemented (*Runtime) GetRootlessNetNs")
}
24 changes: 24 additions & 0 deletions libpod/oci_conmon_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !linux
// +build !linux

package libpod

import (
"errors"

"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/resize"
)

// Make a new Conmon-based OCI runtime with the given options.
// Conmon will wrap the given OCI runtime, which can be `runc`, `crun`, or
// any runtime with a runc-compatible CLI.
// The first path that points to a valid executable will be used.
// Deliberately private. Someone should not be able to construct this outside of
// libpod.
func newConmonOCIRuntime(name string, paths []string, conmonPath string, runtimeFlags []string, runtimeCfg *config.Config) (OCIRuntime, error) {
return nil, errors.New("newConmonOCIRuntime not supported on this platform")
}

func registerResizeFunc(r <-chan resize.TerminalSize, bundlePath string) {
}
Loading

0 comments on commit c2f9ab1

Please sign in to comment.