diff --git a/libpod/options.go b/libpod/options.go index 2ef252eebf..20f56aa535 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -19,7 +19,6 @@ import ( "github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/libpod/events" "github.com/containers/podman/v5/pkg/namespaces" - "github.com/containers/podman/v5/pkg/specgen" "github.com/containers/podman/v5/pkg/util" "github.com/containers/storage" "github.com/containers/storage/pkg/fileutils" @@ -134,22 +133,6 @@ func WithImageStore(imageStore string) RuntimeOption { } } -// WithSignaturePolicy specifies the path of a file which decides how trust is -// managed for images we've pulled. -// If this is not specified, the system default configuration will be used -// instead. -func WithSignaturePolicy(path string) RuntimeOption { - return func(rt *Runtime) error { - if rt.valid { - return define.ErrRuntimeFinalized - } - - rt.config.Engine.SignaturePolicyPath = path - - return nil - } -} - // WithOCIRuntime specifies an OCI runtime to use for running containers. func WithOCIRuntime(runtime string) RuntimeOption { return func(rt *Runtime) error { @@ -196,19 +179,6 @@ func WithConmonPath(path string) RuntimeOption { } } -// WithConmonEnv specifies the environment variable list for the conmon process. -func WithConmonEnv(environment []string) RuntimeOption { - return func(rt *Runtime) error { - if rt.valid { - return define.ErrRuntimeFinalized - } - - rt.config.Engine.ConmonEnvVars.Set(environment) - - return nil - } -} - // WithNetworkCmdPath specifies the path to the slirp4netns binary which manages the // runtime. func WithNetworkCmdPath(path string) RuntimeOption { @@ -382,20 +352,6 @@ func WithTmpDir(dir string) RuntimeOption { } } -// WithNoPivotRoot sets the runtime to use MS_MOVE instead of PIVOT_ROOT when -// starting containers. -func WithNoPivotRoot() RuntimeOption { - return func(rt *Runtime) error { - if rt.valid { - return define.ErrRuntimeFinalized - } - - rt.config.Engine.NoPivotRoot = true - - return nil - } -} - // WithNetworkConfigDir sets the network configuration directory. func WithNetworkConfigDir(dir string) RuntimeOption { return func(rt *Runtime) error { @@ -409,19 +365,6 @@ func WithNetworkConfigDir(dir string) RuntimeOption { } } -// WithCNIPluginDir sets the CNI plugins directory. -func WithCNIPluginDir(dir string) RuntimeOption { - return func(rt *Runtime) error { - if rt.valid { - return define.ErrRuntimeFinalized - } - - rt.config.Network.CNIPluginDirs.Set([]string{dir}) - - return nil - } -} - // WithNamespace sets the namespace for libpod. // Namespaces are used to create scopes to separate containers and pods // in the state. @@ -458,20 +401,6 @@ func WithVolumePath(volPath string) RuntimeOption { } } -// WithDefaultInfraCommand sets the command to -// run on pause container start up. -func WithDefaultInfraCommand(cmd string) RuntimeOption { - return func(rt *Runtime) error { - if rt.valid { - return define.ErrRuntimeFinalized - } - - rt.config.Engine.InfraCommand = cmd - - return nil - } -} - // WithReset tells Libpod that the runtime will be used to perform a system // reset. A number of checks at initialization are relaxed as the runtime is // going to be used to remove all containers, pods, volumes, images, and @@ -859,28 +788,6 @@ func WithIDMappings(idmappings storage.IDMappingOptions) CtrCreateOption { } } -// WithUTSNSFromPod indicates that the container should join the UTS namespace of -// its pod -func WithUTSNSFromPod(p *Pod) CtrCreateOption { - return func(ctr *Container) error { - if ctr.valid { - return define.ErrCtrFinalized - } - - if err := validPodNSOption(p, ctr.config.Pod); err != nil { - return err - } - - infraContainer, err := p.InfraContainerID() - if err != nil { - return err - } - ctr.config.UTSNsCtr = infraContainer - - return nil - } -} - // WithIPCNSFrom indicates that the container should join the IPC namespace of // the given container. // If the container has joined a pod, it can only join the namespaces of @@ -901,25 +808,6 @@ func WithIPCNSFrom(nsCtr *Container) CtrCreateOption { } } -// WithMountNSFrom indicates that the container should join the mount namespace -// of the given container. -// If the container has joined a pod, it can only join the namespaces of -// containers in the same pod. -func WithMountNSFrom(nsCtr *Container) CtrCreateOption { - return func(ctr *Container) error { - if ctr.valid { - return define.ErrCtrFinalized - } - - if err := checkDependencyContainer(nsCtr, ctr); err != nil { - return err - } - ctr.config.MountNsCtr = nsCtr.ID() - - return nil - } -} - // WithNetNSFrom indicates that the container should join the network namespace // of the given container. // If the container has joined a pod, it can only join the namespaces of @@ -1370,22 +1258,6 @@ func WithRootFS(rootfs string, overlay bool, mapping *string) CtrCreateOption { } } -// WithCtrNamespace sets the namespace the container will be created in. -// Namespaces are used to create separate views of Podman's state - runtimes can -// join a specific namespace and see only containers and pods in that namespace. -// Empty string namespaces are allowed, and correspond to a lack of namespace. -func WithCtrNamespace(ns string) CtrCreateOption { - return func(ctr *Container) error { - if ctr.valid { - return define.ErrCtrFinalized - } - - ctr.config.Namespace = ns - - return nil - } -} - // WithUseImageResolvConf tells the container not to bind-mount resolv.conf in. // This conflicts with other DNS-related options. func WithUseImageResolvConf() CtrCreateOption { @@ -2016,25 +1888,6 @@ func WithSelectedPasswordManagement(passwd *bool) CtrCreateOption { } } -// WithInfraConfig allows for inheritance of compatible config entities from the infra container -func WithInfraConfig(compatibleOptions InfraInherit) CtrCreateOption { - return func(ctr *Container) error { - if ctr.valid { - return define.ErrCtrFinalized - } - compatMarshal, err := json.Marshal(compatibleOptions) - if err != nil { - return errors.New("could not marshal compatible options") - } - - err = json.Unmarshal(compatMarshal, ctr.config) - if err != nil { - return errors.New("could not unmarshal compatible options into container config") - } - return nil - } -} - // WithStartupHealthcheck sets a startup healthcheck for the container. // Requires that a healthcheck must be set. func WithStartupHealthcheck(startupHC *define.StartupHealthCheck) CtrCreateOption { @@ -2152,18 +2005,6 @@ func WithPodHostname(hostname string) PodCreateOption { } } -// WithInfraConmonPidFile sets the path to a custom conmon PID file for the -// infra container. -func WithInfraConmonPidFile(path string, infraSpec *specgen.SpecGenerator) PodCreateOption { - return func(pod *Pod) error { - if pod.valid { - return define.ErrPodFinalized - } - infraSpec.ConmonPidFile = path - return nil - } -} - // WithPodLabels sets the labels of a pod. func WithPodLabels(labels map[string]string) PodCreateOption { return func(pod *Pod) error { @@ -2209,23 +2050,6 @@ func WithPodParent() PodCreateOption { } } -// WithPodNamespace sets the namespace for the created pod. -// Namespaces are used to create separate views of Podman's state - runtimes can -// join a specific namespace and see only containers and pods in that namespace. -// Empty string namespaces are allowed, and correspond to a lack of namespace. -// Containers must belong to the same namespace as the pod they join. -func WithPodNamespace(ns string) PodCreateOption { - return func(pod *Pod) error { - if pod.valid { - return define.ErrPodFinalized - } - - pod.config.Namespace = ns - - return nil - } -} - // WithPodIPC tells containers in this pod to use the ipc namespace // created for this pod. // Containers in a pod will inherit the kernel namespaces from the @@ -2258,24 +2082,6 @@ func WithPodNet() PodCreateOption { } } -// WithPodMount tells containers in this pod to use the mount namespace -// created for this pod. -// Containers in a pod will inherit the kernel namespaces from the -// first container added. -// TODO implement WithMountNSFrom, so WithMountNsFromPod functions properly -// Then this option can be added on the pod level -func WithPodMount() PodCreateOption { - return func(pod *Pod) error { - if pod.valid { - return define.ErrPodFinalized - } - - pod.config.UsePodMount = true - - return nil - } -} - // WithPodUser tells containers in this pod to use the user namespace // created for this pod. // Containers in a pod will inherit the kernel namespaces from the diff --git a/libpod/runtime.go b/libpod/runtime.go index 4944a2e1ca..4c874d33e0 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -176,15 +176,6 @@ func NewRuntime(ctx context.Context, options ...RuntimeOption) (*Runtime, error) return newRuntimeFromConfig(ctx, conf, options...) } -// NewRuntimeFromConfig creates a new container runtime using the given -// configuration file for its default configuration. Passed RuntimeOption -// functions can be used to mutate this configuration further. -// An error will be returned if the configuration file at the given path does -// not exist or cannot be loaded -func NewRuntimeFromConfig(ctx context.Context, userConfig *config.Config, options ...RuntimeOption) (*Runtime, error) { - return newRuntimeFromConfig(ctx, userConfig, options...) -} - func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...RuntimeOption) (*Runtime, error) { runtime := new(Runtime) diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index cf32d953e8..905ed207fc 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -6,8 +6,6 @@ import ( "context" "errors" "fmt" - "io" - "os" buildahDefine "github.com/containers/buildah/define" "github.com/containers/buildah/imagebuildah" @@ -15,7 +13,6 @@ import ( "github.com/containers/image/v5/docker/reference" "github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/libpod/events" - "github.com/containers/podman/v5/pkg/util" "github.com/sirupsen/logrus" ) @@ -130,22 +127,3 @@ func (r *Runtime) Build(ctx context.Context, options buildahDefine.BuildOptions, r.newImageBuildCompleteEvent(id) return id, ref, err } - -// DownloadFromFile reads all of the content from the reader and temporarily -// saves in it $TMPDIR/importxyz, which is deleted after the image is imported -func DownloadFromFile(reader *os.File) (string, error) { - outFile, err := os.CreateTemp(util.Tmpdir(), "import") - if err != nil { - return "", fmt.Errorf("creating file: %w", err) - } - defer outFile.Close() - - logrus.Debugf("saving %s to %s", reader.Name(), outFile.Name()) - - _, err = io.Copy(outFile, reader) - if err != nil { - return "", fmt.Errorf("saving %s to %s: %w", reader.Name(), outFile.Name(), err) - } - - return outFile.Name(), nil -} diff --git a/libpod/util.go b/libpod/util.go index c03fada4a9..5e5f1041ea 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -15,7 +15,6 @@ import ( "slices" "strconv" "strings" - "time" "github.com/containers/common/libnetwork/types" "github.com/containers/common/pkg/config" @@ -28,14 +27,6 @@ import ( "golang.org/x/sys/unix" ) -// FuncTimer helps measure the execution time of a function -// For debug purposes, do not leave in code -// used like defer FuncTimer("foo") -func FuncTimer(funcName string) { - elapsed := time.Since(time.Now()) - fmt.Printf("%s executed in %d ms\n", funcName, elapsed) -} - // MountExists returns true if dest exists in the list of mounts func MountExists(specMounts []spec.Mount, dest string) bool { for _, m := range specMounts { @@ -71,21 +62,6 @@ func sortMounts(m []spec.Mount) []spec.Mount { return m } -func validPodNSOption(p *Pod, ctrPod string) error { - if p == nil { - return fmt.Errorf("pod passed in was nil. Container may not be associated with a pod: %w", define.ErrInvalidArg) - } - - if ctrPod == "" { - return fmt.Errorf("container is not a member of any pod: %w", define.ErrInvalidArg) - } - - if ctrPod != p.ID() { - return fmt.Errorf("pod passed in is not the pod the container is associated with: %w", define.ErrInvalidArg) - } - return nil -} - // JSONDeepCopy performs a deep copy by performing a JSON encode/decode of the // given structures. From and To should be identically typed structs. func JSONDeepCopy(from, to interface{}) error {