summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/runlabel.go33
-rw-r--r--cmd/podmanV2/common/create.go11
-rw-r--r--cmd/podmanV2/common/default.go13
3 files changed, 49 insertions, 8 deletions
diff --git a/cmd/podman/runlabel.go b/cmd/podman/runlabel.go
index 1ec4da650..193cc5aec 100644
--- a/cmd/podman/runlabel.go
+++ b/cmd/podman/runlabel.go
@@ -13,11 +13,11 @@ import (
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/image"
- "github.com/containers/libpod/pkg/util"
"github.com/containers/libpod/utils"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
var (
@@ -157,7 +157,7 @@ func runlabelCmd(c *cliconfig.RunlabelValues) error {
return errors.Errorf("%s does not have a label of %s", runlabelImage, label)
}
- globalOpts := util.GetGlobalOpts(c)
+ globalOpts := GetGlobalOpts(c)
cmd, env, err := shared.GenerateRunlabelCommand(runLabel, imageName, c.Name, opts, extraArgs, globalOpts)
if err != nil {
return err
@@ -193,3 +193,32 @@ func runlabelCmd(c *cliconfig.RunlabelValues) error {
return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...)
}
+
+// GetGlobalOpts checks all global flags and generates the command string
+func GetGlobalOpts(c *cliconfig.RunlabelValues) string {
+ globalFlags := map[string]bool{
+ "cgroup-manager": true, "cni-config-dir": true, "conmon": true, "default-mounts-file": true,
+ "hooks-dir": true, "namespace": true, "root": true, "runroot": true,
+ "runtime": true, "storage-driver": true, "storage-opt": true, "syslog": true,
+ "trace": true, "network-cmd-path": true, "config": true, "cpu-profile": true,
+ "log-level": true, "tmpdir": true}
+ const stringSliceType string = "stringSlice"
+
+ var optsCommand []string
+ c.PodmanCommand.Command.Flags().VisitAll(func(f *pflag.Flag) {
+ if !f.Changed {
+ return
+ }
+ if _, exist := globalFlags[f.Name]; exist {
+ if f.Value.Type() == stringSliceType {
+ flagValue := strings.TrimSuffix(strings.TrimPrefix(f.Value.String(), "["), "]")
+ for _, value := range strings.Split(flagValue, ",") {
+ optsCommand = append(optsCommand, fmt.Sprintf("--%s %s", f.Name, value))
+ }
+ } else {
+ optsCommand = append(optsCommand, fmt.Sprintf("--%s %s", f.Name, f.Value.String()))
+ }
+ }
+ })
+ return strings.Join(optsCommand, " ")
+}
diff --git a/cmd/podmanV2/common/create.go b/cmd/podmanV2/common/create.go
index e2eb8cbda..ecaaf38fb 100644
--- a/cmd/podmanV2/common/create.go
+++ b/cmd/podmanV2/common/create.go
@@ -6,7 +6,6 @@ import (
buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/common/pkg/config"
- "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
@@ -214,22 +213,22 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.HealthInterval,
- "health-interval", cliconfig.DefaultHealthCheckInterval,
+ "health-interval", DefaultHealthCheckInterval,
"set an interval for the healthchecks (a value of disable results in no automatic timer setup)",
)
createFlags.UintVar(
&cf.HealthRetries,
- "health-retries", cliconfig.DefaultHealthCheckRetries,
+ "health-retries", DefaultHealthCheckRetries,
"the number of retries allowed before a healthcheck is considered to be unhealthy",
)
createFlags.StringVar(
&cf.HealthStartPeriod,
- "health-start-period", cliconfig.DefaultHealthCheckStartPeriod,
+ "health-start-period", DefaultHealthCheckStartPeriod,
"the initialization time needed for a container to bootstrap",
)
createFlags.StringVar(
&cf.HealthTimeout,
- "health-timeout", cliconfig.DefaultHealthCheckTimeout,
+ "health-timeout", DefaultHealthCheckTimeout,
"the maximum time allowed to complete the healthcheck before an interval is considered failed",
)
createFlags.StringVarP(
@@ -244,7 +243,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
)
createFlags.StringVar(
&cf.ImageVolume,
- "image-volume", cliconfig.DefaultImageVolume,
+ "image-volume", DefaultImageVolume,
`Tells podman how to handle the builtin image volumes ("bind"|"tmpfs"|"ignore")`,
)
createFlags.BoolVar(
diff --git a/cmd/podmanV2/common/default.go b/cmd/podmanV2/common/default.go
index b71fcb6f0..bd793f168 100644
--- a/cmd/podmanV2/common/default.go
+++ b/cmd/podmanV2/common/default.go
@@ -12,6 +12,19 @@ import (
"github.com/opencontainers/selinux/go-selinux"
)
+var (
+ // DefaultHealthCheckInterval default value
+ DefaultHealthCheckInterval = "30s"
+ // DefaultHealthCheckRetries default value
+ DefaultHealthCheckRetries uint = 3
+ // DefaultHealthCheckStartPeriod default value
+ DefaultHealthCheckStartPeriod = "0s"
+ // DefaultHealthCheckTimeout default value
+ DefaultHealthCheckTimeout = "30s"
+ // 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