summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-05-03 11:30:51 +0200
committerGitHub <noreply@github.com>2019-05-03 11:30:51 +0200
commita7809fabe508e26c527490e700a1703ef923bd3b (patch)
tree2c3e83fa62f6b98b394123d1c73e321e40041c95 /pkg
parent4877e6a947beff12f7f927978f04cffc11377007 (diff)
parenta477a8ff755e2807d0745b207d6a5bf57de58e4c (diff)
downloadpodman-a7809fabe508e26c527490e700a1703ef923bd3b.tar.gz
podman-a7809fabe508e26c527490e700a1703ef923bd3b.tar.bz2
podman-a7809fabe508e26c527490e700a1703ef923bd3b.zip
Merge pull request #2905 from QiWang19/globalvar
Add variable for global flags to runlabel
Diffstat (limited to 'pkg')
-rw-r--r--pkg/util/utils.go31
-rw-r--r--pkg/varlinkapi/images.go2
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())
}