summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/create.go34
-rw-r--r--cmd/podman/common/createparse.go21
-rw-r--r--cmd/podman/common/default.go121
-rw-r--r--cmd/podman/common/netflags.go98
-rw-r--r--cmd/podman/common/specgen.go9
5 files changed, 107 insertions, 176 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index 49a40dfa0..f256d9677 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -51,12 +51,12 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.CGroupsNS,
- "cgroupns", getDefaultCgroupNS(),
+ "cgroupns", containerConfig.CgroupNS(),
"cgroup namespace to use",
)
createFlags.StringVar(
&cf.CGroups,
- "cgroups", "enabled",
+ "cgroups", containerConfig.Cgroups(),
`control container cgroup configuration ("enabled"|"disabled"|"no-conmon")`,
)
createFlags.StringVar(
@@ -121,12 +121,12 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.DetachKeys,
- "detach-keys", GetDefaultDetachKeys(),
+ "detach-keys", containerConfig.DetachKeys(),
"Override the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-cf`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`",
)
createFlags.StringSliceVar(
&cf.Device,
- "device", getDefaultDevices(),
+ "device", containerConfig.Devices(),
fmt.Sprintf("Add a host device to the container"),
)
createFlags.StringSliceVar(
@@ -161,7 +161,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringArrayVarP(
&cf.env,
- "env", "e", getDefaultEnv(),
+ "env", "e", containerConfig.Env(),
"Set environment variables in container",
)
createFlags.BoolVar(
@@ -238,7 +238,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.InitPath,
- "init-path", getDefaultInitPath(),
+ "init-path", containerConfig.InitPath(),
// Do not use the Value field for setting the default value to determine user input (i.e., non-empty string)
fmt.Sprintf("Path to the container-init binary"),
)
@@ -249,7 +249,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.IPC,
- "ipc", getDefaultIPCNS(),
+ "ipc", containerConfig.IPCNS(),
"IPC namespace to use",
)
createFlags.StringVar(
@@ -331,13 +331,13 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
// markFlagHidden(createFlags, "override-os")
createFlags.StringVar(
&cf.PID,
- "pid", getDefaultPidNS(),
+ "pid", containerConfig.PidNS(),
"PID namespace to use",
)
createFlags.Int64Var(
&cf.PIDsLimit,
- "pids-limit", getDefaultPidsLimit(),
- getDefaultPidsDescription(),
+ "pids-limit", containerConfig.PidsLimit(),
+ "Tune container pids limit (set 0 for unlimited, -1 for server defaults)",
)
createFlags.StringVar(
&cf.Pod,
@@ -391,12 +391,12 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringArrayVar(
&cf.SecurityOpt,
- "security-opt", getDefaultSecurityOptions(),
+ "security-opt", containerConfig.SecurityOptions(),
"Security Options",
)
createFlags.StringVar(
&cf.ShmSize,
- "shm-size", getDefaultShmSize(),
+ "shm-size", containerConfig.ShmSize(),
"Size of /dev/shm "+sizeWithUnitFormat,
)
createFlags.StringVar(
@@ -427,7 +427,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
createFlags.StringSliceVar(
&cf.Sysctl,
- "sysctl", getDefaultSysctls(),
+ "sysctl", containerConfig.Sysctls(),
"Sysctl options",
)
createFlags.StringVar(
@@ -452,7 +452,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringSliceVar(
&cf.Ulimit,
- "ulimit", getDefaultUlimits(),
+ "ulimit", containerConfig.Ulimits(),
"Ulimit options",
)
createFlags.StringVarP(
@@ -462,12 +462,12 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.UserNS,
- "userns", getDefaultUserNS(),
+ "userns", containerConfig.Containers.UserNS,
"User namespace to use",
)
createFlags.StringVar(
&cf.UTS,
- "uts", getDefaultUTSNS(),
+ "uts", containerConfig.Containers.UTSNS,
"UTS namespace to use",
)
createFlags.StringArrayVar(
@@ -477,7 +477,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringArrayVarP(
&cf.Volume,
- "volume", "v", getDefaultVolumes(),
+ "volume", "v", containerConfig.Volumes(),
"Bind mount a volume into the container",
)
createFlags.StringSliceVar(
diff --git a/cmd/podman/common/createparse.go b/cmd/podman/common/createparse.go
index aca6f752e..fe6e322c2 100644
--- a/cmd/podman/common/createparse.go
+++ b/cmd/podman/common/createparse.go
@@ -1,7 +1,6 @@
package common
import (
- "github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
)
@@ -17,27 +16,7 @@ func (c *ContainerCLIOpts) validate() error {
if _, err := util.ValidatePullType(c.Pull); err != nil {
return err
}
- // Verify the additional hosts are in correct format
- for _, host := range c.Net.AddHosts {
- if _, err := parse.ValidateExtraHost(host); err != nil {
- return err
- }
- }
- if dnsSearches := c.Net.DNSSearch; len(dnsSearches) > 0 {
- // Validate domains are good
- for _, dom := range dnsSearches {
- if dom == "." {
- if len(dnsSearches) > 1 {
- return errors.Errorf("cannot pass additional search domains when also specifying '.'")
- }
- continue
- }
- if _, err := parse.ValidateDomain(dom); err != nil {
- return err
- }
- }
- }
var imageVolType = map[string]string{
"bind": "",
"tmpfs": "",
diff --git a/cmd/podman/common/default.go b/cmd/podman/common/default.go
index 853f87ab6..89316270b 100644
--- a/cmd/podman/common/default.go
+++ b/cmd/podman/common/default.go
@@ -1,18 +1,5 @@
package common
-import (
- "fmt"
- "os"
-
- "github.com/containers/buildah/pkg/parse"
- "github.com/containers/libpod/pkg/apparmor"
- "github.com/containers/libpod/pkg/cgroups"
- "github.com/containers/libpod/pkg/rootless"
- "github.com/containers/libpod/pkg/specgen"
- "github.com/containers/libpod/pkg/sysinfo"
- "github.com/opencontainers/selinux/go-selinux"
-)
-
var (
// DefaultHealthCheckInterval default value
DefaultHealthCheckInterval = "30s"
@@ -25,111 +12,3 @@ var (
// DefaultImageVolume default value
DefaultImageVolume = "bind"
)
-
-// TODO these options are directly embedded into many of the CLI cobra values, as such
-// this approach will not work in a remote client. so we will need to likely do something like a
-// supported and unsupported approach here and backload these options into the specgen
-// once we are "on" the host system.
-func getDefaultSecurityOptions() []string {
- securityOpts := []string{}
- if containerConfig.Containers.SeccompProfile != "" && containerConfig.Containers.SeccompProfile != parse.SeccompDefaultPath {
- securityOpts = append(securityOpts, fmt.Sprintf("seccomp=%s", containerConfig.Containers.SeccompProfile))
- }
- if apparmor.IsEnabled() && containerConfig.Containers.ApparmorProfile != "" {
- securityOpts = append(securityOpts, fmt.Sprintf("apparmor=%s", containerConfig.Containers.ApparmorProfile))
- }
- if selinux.GetEnabled() && !containerConfig.Containers.EnableLabeling {
- securityOpts = append(securityOpts, fmt.Sprintf("label=%s", selinux.DisableSecOpt()[0]))
- }
- return securityOpts
-}
-
-// getDefaultSysctls
-func getDefaultSysctls() []string {
- return containerConfig.Containers.DefaultSysctls
-}
-
-func getDefaultVolumes() []string {
- return containerConfig.Containers.Volumes
-}
-
-func getDefaultDevices() []string {
- return containerConfig.Containers.Devices
-}
-
-func getDefaultDNSServers() []string { //nolint
- return containerConfig.Containers.DNSServers
-}
-
-func getDefaultDNSSearches() []string { //nolint
- return containerConfig.Containers.DNSSearches
-}
-
-func getDefaultDNSOptions() []string { //nolint
- return containerConfig.Containers.DNSOptions
-}
-
-func getDefaultEnv() []string {
- return containerConfig.Containers.Env
-}
-
-func getDefaultInitPath() string {
- return containerConfig.Containers.InitPath
-}
-
-func getDefaultIPCNS() string {
- return containerConfig.Containers.IPCNS
-}
-
-func getDefaultPidNS() string {
- return containerConfig.Containers.PidNS
-}
-
-func getDefaultNetNS() string { //nolint
- if containerConfig.Containers.NetNS == string(specgen.Private) && rootless.IsRootless() {
- return string(specgen.Slirp)
- }
- return containerConfig.Containers.NetNS
-}
-
-func getDefaultCgroupNS() string {
- return containerConfig.Containers.CgroupNS
-}
-
-func getDefaultUTSNS() string {
- return containerConfig.Containers.UTSNS
-}
-
-func getDefaultShmSize() string {
- return containerConfig.Containers.ShmSize
-}
-
-func getDefaultUlimits() []string {
- return containerConfig.Containers.DefaultUlimits
-}
-
-func getDefaultUserNS() string {
- userns := os.Getenv("PODMAN_USERNS")
- if userns != "" {
- return userns
- }
- return containerConfig.Containers.UserNS
-}
-
-func getDefaultPidsLimit() int64 {
- if rootless.IsRootless() {
- cgroup2, _ := cgroups.IsCgroup2UnifiedMode()
- if cgroup2 {
- return containerConfig.Containers.PidsLimit
- }
- }
- return sysinfo.GetDefaultPidsLimit()
-}
-
-func getDefaultPidsDescription() string {
- return "Tune container pids limit (set 0 for unlimited)"
-}
-
-func GetDefaultDetachKeys() string {
- return containerConfig.Engine.DetachKeys
-}
diff --git a/cmd/podman/common/netflags.go b/cmd/podman/common/netflags.go
index 41eed2988..1a47733e7 100644
--- a/cmd/podman/common/netflags.go
+++ b/cmd/podman/common/netflags.go
@@ -3,7 +3,9 @@ package common
import (
"net"
+ "github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/pkg/domain/entities"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@@ -15,15 +17,15 @@ func GetNetFlags() *pflag.FlagSet {
"Add a custom host-to-IP mapping (host:ip) (default [])",
)
netFlags.StringSlice(
- "dns", getDefaultDNSServers(),
+ "dns", containerConfig.DNSServers(),
"Set custom DNS servers",
)
netFlags.StringSlice(
- "dns-opt", getDefaultDNSOptions(),
+ "dns-opt", containerConfig.DNSOptions(),
"Set custom DNS options",
)
netFlags.StringSlice(
- "dns-search", getDefaultDNSSearches(),
+ "dns-search", containerConfig.DNSSearches(),
"Set custom DNS search domains",
)
netFlags.String(
@@ -35,7 +37,7 @@ func GetNetFlags() *pflag.FlagSet {
"Container MAC address (e.g. 92:d0:c6:0a:29:33)",
)
netFlags.String(
- "network", getDefaultNetNS(),
+ "network", containerConfig.NetNS(),
"Connect a container to a network",
)
netFlags.StringSliceP(
@@ -58,20 +60,60 @@ func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) {
if err != nil {
return nil, err
}
- servers, err := cmd.Flags().GetStringSlice("dns")
- if err != nil {
- return nil, err
+ // Verify the additional hosts are in correct format
+ for _, host := range opts.AddHosts {
+ if _, err := parse.ValidateExtraHost(host); err != nil {
+ return nil, err
+ }
}
- for _, d := range servers {
- if d == "none" {
- opts.DNSHost = true
- break
+
+ if cmd.Flags().Changed("dns") {
+ servers, err := cmd.Flags().GetStringSlice("dns")
+ if err != nil {
+ return nil, err
+ }
+ for _, d := range servers {
+ if d == "none" {
+ opts.UseImageResolvConf = true
+ if len(servers) > 1 {
+ return nil, errors.Errorf("%s is not allowed to be specified with other DNS ip addresses", d)
+ }
+ break
+ }
+ dns := net.ParseIP(d)
+ if dns == nil {
+ return nil, errors.Errorf("%s is not an ip address", d)
+ }
+ opts.DNSServers = append(opts.DNSServers, dns)
}
- opts.DNSServers = append(opts.DNSServers, net.ParseIP(d))
}
- opts.DNSSearch, err = cmd.Flags().GetStringSlice("dns-search")
- if err != nil {
- return nil, err
+
+ if cmd.Flags().Changed("dns-opt") {
+ options, err := cmd.Flags().GetStringSlice("dns-opt")
+ if err != nil {
+ return nil, err
+ }
+ opts.DNSOptions = options
+ }
+
+ if cmd.Flags().Changed("dns-search") {
+ dnsSearches, err := cmd.Flags().GetStringSlice("dns-search")
+ if err != nil {
+ return nil, err
+ }
+ // Validate domains are good
+ for _, dom := range dnsSearches {
+ if dom == "." {
+ if len(dnsSearches) > 1 {
+ return nil, errors.Errorf("cannot pass additional search domains when also specifying '.'")
+ }
+ continue
+ }
+ if _, err := parse.ValidateDomain(dom); err != nil {
+ return nil, err
+ }
+ }
+ opts.DNSSearch = dnsSearches
}
m, err := cmd.Flags().GetString("mac-address")
@@ -85,6 +127,7 @@ func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) {
}
opts.StaticMAC = &mac
}
+
inputPorts, err := cmd.Flags().GetStringSlice("publish")
if err != nil {
return nil, err
@@ -95,6 +138,31 @@ func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) {
return nil, err
}
}
+
+ ip, err := cmd.Flags().GetString("ip")
+ if err != nil {
+ return nil, err
+ }
+ if ip != "" {
+ staticIP := net.ParseIP(ip)
+ if staticIP == nil {
+ return nil, errors.Errorf("%s is not an ip address", ip)
+ }
+ opts.StaticIP = &staticIP
+ }
+
opts.NoHosts, err = cmd.Flags().GetBool("no-hosts")
+
+ if cmd.Flags().Changed("network") {
+ network, err := cmd.Flags().GetString("network")
+ if err != nil {
+ return nil, err
+ }
+
+ return nil, errors.Errorf("network %s is not yet supported", network)
+ // TODO How do I convert a string network to a Specgen.Namespace?
+ // opts.Network = specgen.Namespace{NSMode: network}
+ }
+
return &opts, err
}
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 7550bf784..4e2ce1e34 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -268,6 +268,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
var command []string
+ s.Entrypoint = entrypoint
+
// Build the command
// If we have an entry point, it goes first
if len(entrypoint) > 0 {
@@ -292,9 +294,12 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
}
s.ShmSize = &shmSize
s.HostAdd = c.Net.AddHosts
- s.DNSServer = c.Net.DNSServers
+ s.UseImageResolvConf = c.Net.UseImageResolvConf
+ s.DNSServers = c.Net.DNSServers
s.DNSSearch = c.Net.DNSSearch
- s.DNSOption = c.Net.DNSOptions
+ s.DNSOptions = c.Net.DNSOptions
+ s.StaticIP = c.Net.StaticIP
+ s.StaticMAC = c.Net.StaticMAC
// deferred, must be added on libpod side
//var ImageVolumes map[string]struct{}