diff options
author | Qi Wang <qiwan@redhat.com> | 2019-04-11 15:59:30 -0400 |
---|---|---|
committer | Qi Wang <qiwan@redhat.com> | 2019-05-02 12:14:51 -0400 |
commit | a477a8ff755e2807d0745b207d6a5bf57de58e4c (patch) | |
tree | a7a6f479c733c42ddc7aca2a30b1c753cf9238bb /pkg | |
parent | 7d05ff3fc772a7be4860ed4a3cd59a62f8bb893a (diff) | |
download | podman-a477a8ff755e2807d0745b207d6a5bf57de58e4c.tar.gz podman-a477a8ff755e2807d0745b207d6a5bf57de58e4c.tar.bz2 podman-a477a8ff755e2807d0745b207d6a5bf57de58e4c.zip |
Add variable for global flags to runlabel
use $GLOBAL_OPTS to pass global flags to the runlabel command.
Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/util/utils.go | 31 | ||||
-rw-r--r-- | pkg/varlinkapi/images.go | 2 |
2 files changed, 32 insertions, 1 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 14b0c2b55..2a52e5129 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -10,10 +10,12 @@ import ( "github.com/BurntSushi/toml" "github.com/containers/image/types" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/storage" "github.com/containers/storage/pkg/idtools" "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" + "github.com/spf13/pflag" "golang.org/x/crypto/ssh/terminal" ) @@ -252,3 +254,32 @@ func ParseInputTime(inputTime string) (time.Time, error) { } return time.Now().Add(-duration), nil } + +// 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/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index cecddf6b3..20f82a1c6 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -728,7 +728,7 @@ func (i *LibpodAPI) ContainerRunlabel(call iopodman.VarlinkCall, input iopodman. return call.ReplyErrorOccurred(fmt.Sprintf("%s does not contain the label %s", input.Image, input.Label)) } - cmd, env, err := shared.GenerateRunlabelCommand(runLabel, imageName, input.Name, input.Opts, input.ExtraArgs) + cmd, env, err := shared.GenerateRunlabelCommand(runLabel, imageName, input.Name, input.Opts, input.ExtraArgs, "") if err != nil { return call.ReplyErrorOccurred(err.Error()) } |