summaryrefslogtreecommitdiff
path: root/cmd/podmanV2/common
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podmanV2/common')
-rw-r--r--cmd/podmanV2/common/create.go31
-rw-r--r--cmd/podmanV2/common/default.go51
-rw-r--r--cmd/podmanV2/common/netflags.go16
-rw-r--r--cmd/podmanV2/common/specgen.go4
4 files changed, 40 insertions, 62 deletions
diff --git a/cmd/podmanV2/common/create.go b/cmd/podmanV2/common/create.go
index ecaaf38fb..0b2f4532c 100644
--- a/cmd/podmanV2/common/create.go
+++ b/cmd/podmanV2/common/create.go
@@ -2,30 +2,15 @@ package common
import (
"fmt"
- "os"
buildahcli "github.com/containers/buildah/pkg/cli"
- "github.com/containers/common/pkg/config"
- "github.com/sirupsen/logrus"
+ "github.com/containers/libpod/cmd/podmanV2/registry"
"github.com/spf13/pflag"
)
-const (
- sizeWithUnitFormat = "(format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))"
-)
-
-var (
- defaultContainerConfig = getDefaultContainerConfig()
-)
+const sizeWithUnitFormat = "(format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))"
-func getDefaultContainerConfig() *config.Config {
- defaultContainerConfig, err := config.Default()
- if err != nil {
- logrus.Error(err)
- os.Exit(1)
- }
- return defaultContainerConfig
-}
+var containerConfig = registry.NewPodmanConfig()
func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
createFlags := pflag.FlagSet{}
@@ -337,13 +322,13 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
"override-arch", "",
"use `ARCH` instead of the architecture of the machine for choosing images",
)
- //markFlagHidden(createFlags, "override-arch")
+ // markFlagHidden(createFlags, "override-arch")
createFlags.StringVar(
&cf.OverrideOS,
"override-os", "",
"use `OS` instead of the running OS for choosing images",
)
- //markFlagHidden(createFlags, "override-os")
+ // markFlagHidden(createFlags, "override-os")
createFlags.StringVar(
&cf.PID,
"pid", getDefaultPidNS(),
@@ -407,7 +392,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
createFlags.StringArrayVar(
&cf.SecurityOpt,
"security-opt", getDefaultSecurityOptions(),
- fmt.Sprintf("Security Options"),
+ "Security Options",
)
createFlags.StringVar(
&cf.ShmSize,
@@ -421,7 +406,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.UintVar(
&cf.StopTimeout,
- "stop-timeout", defaultContainerConfig.Engine.StopTimeout,
+ "stop-timeout", containerConfig.Engine.StopTimeout,
"Timeout (in seconds) to stop a container. Default is 10",
)
createFlags.StringSliceVar(
@@ -513,7 +498,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
return &createFlags
}
-func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
+func AliasFlags(_ *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
case "healthcheck-command":
name = "health-cmd"
diff --git a/cmd/podmanV2/common/default.go b/cmd/podmanV2/common/default.go
index bd793f168..853f87ab6 100644
--- a/cmd/podmanV2/common/default.go
+++ b/cmd/podmanV2/common/default.go
@@ -8,6 +8,7 @@ import (
"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"
)
@@ -31,13 +32,13 @@ var (
// once we are "on" the host system.
func getDefaultSecurityOptions() []string {
securityOpts := []string{}
- if defaultContainerConfig.Containers.SeccompProfile != "" && defaultContainerConfig.Containers.SeccompProfile != parse.SeccompDefaultPath {
- securityOpts = append(securityOpts, fmt.Sprintf("seccomp=%s", defaultContainerConfig.Containers.SeccompProfile))
+ if containerConfig.Containers.SeccompProfile != "" && containerConfig.Containers.SeccompProfile != parse.SeccompDefaultPath {
+ securityOpts = append(securityOpts, fmt.Sprintf("seccomp=%s", containerConfig.Containers.SeccompProfile))
}
- if apparmor.IsEnabled() && defaultContainerConfig.Containers.ApparmorProfile != "" {
- securityOpts = append(securityOpts, fmt.Sprintf("apparmor=%s", defaultContainerConfig.Containers.ApparmorProfile))
+ if apparmor.IsEnabled() && containerConfig.Containers.ApparmorProfile != "" {
+ securityOpts = append(securityOpts, fmt.Sprintf("apparmor=%s", containerConfig.Containers.ApparmorProfile))
}
- if selinux.GetEnabled() && !defaultContainerConfig.Containers.EnableLabeling {
+ if selinux.GetEnabled() && !containerConfig.Containers.EnableLabeling {
securityOpts = append(securityOpts, fmt.Sprintf("label=%s", selinux.DisableSecOpt()[0]))
}
return securityOpts
@@ -45,66 +46,66 @@ func getDefaultSecurityOptions() []string {
// getDefaultSysctls
func getDefaultSysctls() []string {
- return defaultContainerConfig.Containers.DefaultSysctls
+ return containerConfig.Containers.DefaultSysctls
}
func getDefaultVolumes() []string {
- return defaultContainerConfig.Containers.Volumes
+ return containerConfig.Containers.Volumes
}
func getDefaultDevices() []string {
- return defaultContainerConfig.Containers.Devices
+ return containerConfig.Containers.Devices
}
func getDefaultDNSServers() []string { //nolint
- return defaultContainerConfig.Containers.DNSServers
+ return containerConfig.Containers.DNSServers
}
func getDefaultDNSSearches() []string { //nolint
- return defaultContainerConfig.Containers.DNSSearches
+ return containerConfig.Containers.DNSSearches
}
func getDefaultDNSOptions() []string { //nolint
- return defaultContainerConfig.Containers.DNSOptions
+ return containerConfig.Containers.DNSOptions
}
func getDefaultEnv() []string {
- return defaultContainerConfig.Containers.Env
+ return containerConfig.Containers.Env
}
func getDefaultInitPath() string {
- return defaultContainerConfig.Containers.InitPath
+ return containerConfig.Containers.InitPath
}
func getDefaultIPCNS() string {
- return defaultContainerConfig.Containers.IPCNS
+ return containerConfig.Containers.IPCNS
}
func getDefaultPidNS() string {
- return defaultContainerConfig.Containers.PidNS
+ return containerConfig.Containers.PidNS
}
func getDefaultNetNS() string { //nolint
- if defaultContainerConfig.Containers.NetNS == "private" && rootless.IsRootless() {
- return "slirp4netns"
+ if containerConfig.Containers.NetNS == string(specgen.Private) && rootless.IsRootless() {
+ return string(specgen.Slirp)
}
- return defaultContainerConfig.Containers.NetNS
+ return containerConfig.Containers.NetNS
}
func getDefaultCgroupNS() string {
- return defaultContainerConfig.Containers.CgroupNS
+ return containerConfig.Containers.CgroupNS
}
func getDefaultUTSNS() string {
- return defaultContainerConfig.Containers.UTSNS
+ return containerConfig.Containers.UTSNS
}
func getDefaultShmSize() string {
- return defaultContainerConfig.Containers.ShmSize
+ return containerConfig.Containers.ShmSize
}
func getDefaultUlimits() []string {
- return defaultContainerConfig.Containers.DefaultUlimits
+ return containerConfig.Containers.DefaultUlimits
}
func getDefaultUserNS() string {
@@ -112,14 +113,14 @@ func getDefaultUserNS() string {
if userns != "" {
return userns
}
- return defaultContainerConfig.Containers.UserNS
+ return containerConfig.Containers.UserNS
}
func getDefaultPidsLimit() int64 {
if rootless.IsRootless() {
cgroup2, _ := cgroups.IsCgroup2UnifiedMode()
if cgroup2 {
- return defaultContainerConfig.Containers.PidsLimit
+ return containerConfig.Containers.PidsLimit
}
}
return sysinfo.GetDefaultPidsLimit()
@@ -130,5 +131,5 @@ func getDefaultPidsDescription() string {
}
func GetDefaultDetachKeys() string {
- return defaultContainerConfig.Engine.DetachKeys
+ return containerConfig.Engine.DetachKeys
}
diff --git a/cmd/podmanV2/common/netflags.go b/cmd/podmanV2/common/netflags.go
index 758f155c8..41eed2988 100644
--- a/cmd/podmanV2/common/netflags.go
+++ b/cmd/podmanV2/common/netflags.go
@@ -4,18 +4,10 @@ import (
"net"
"github.com/containers/libpod/pkg/domain/entities"
- "github.com/containers/libpod/pkg/rootless"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
-func getDefaultNetwork() string {
- if rootless.IsRootless() {
- return "slirp4netns"
- }
- return "bridge"
-}
-
func GetNetFlags() *pflag.FlagSet {
netFlags := pflag.FlagSet{}
netFlags.StringSlice(
@@ -23,15 +15,15 @@ func GetNetFlags() *pflag.FlagSet {
"Add a custom host-to-IP mapping (host:ip) (default [])",
)
netFlags.StringSlice(
- "dns", []string{},
+ "dns", getDefaultDNSServers(),
"Set custom DNS servers",
)
netFlags.StringSlice(
- "dns-opt", []string{},
+ "dns-opt", getDefaultDNSOptions(),
"Set custom DNS options",
)
netFlags.StringSlice(
- "dns-search", []string{},
+ "dns-search", getDefaultDNSSearches(),
"Set custom DNS search domains",
)
netFlags.String(
@@ -43,7 +35,7 @@ func GetNetFlags() *pflag.FlagSet {
"Container MAC address (e.g. 92:d0:c6:0a:29:33)",
)
netFlags.String(
- "network", getDefaultNetwork(),
+ "network", getDefaultNetNS(),
"Connect a container to a network",
)
netFlags.StringSliceP(
diff --git a/cmd/podmanV2/common/specgen.go b/cmd/podmanV2/common/specgen.go
index 5245e206e..2232fb4ba 100644
--- a/cmd/podmanV2/common/specgen.go
+++ b/cmd/podmanV2/common/specgen.go
@@ -11,7 +11,7 @@ import (
"github.com/containers/image/v5/manifest"
"github.com/containers/libpod/cmd/podmanV2/parse"
- "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/define"
ann "github.com/containers/libpod/pkg/annotations"
envLib "github.com/containers/libpod/pkg/env"
ns "github.com/containers/libpod/pkg/namespaces"
@@ -324,7 +324,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if s.LogConfiguration == nil {
s.LogConfiguration = &specgen.LogConfig{}
}
- s.LogConfiguration.Driver = libpod.KubernetesLogging
+ s.LogConfiguration.Driver = define.KubernetesLogging
if ld := c.LogDriver; len(ld) > 0 {
s.LogConfiguration.Driver = ld
}