diff options
author | baude <bbaude@redhat.com> | 2017-11-01 13:59:11 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2017-11-01 14:19:19 -0500 |
commit | 8cf07b2ad1ed8c6646c48a74e9ecbb2bfeecb322 (patch) | |
tree | 625fdeaf51ffced387b4ba2e48d93288f3f1b9b2 /cmd/kpod/create_cli.go | |
parent | f5019df3f5da9030ce21e5c8ad3d3921a6585e7f (diff) | |
download | podman-8cf07b2ad1ed8c6646c48a74e9ecbb2bfeecb322.tar.gz podman-8cf07b2ad1ed8c6646c48a74e9ecbb2bfeecb322.tar.bz2 podman-8cf07b2ad1ed8c6646c48a74e9ecbb2bfeecb322.zip |
libpod create and run
patched version of the same code that went into crio
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/kpod/create_cli.go')
-rw-r--r-- | cmd/kpod/create_cli.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cmd/kpod/create_cli.go b/cmd/kpod/create_cli.go new file mode 100644 index 000000000..996155ba0 --- /dev/null +++ b/cmd/kpod/create_cli.go @@ -0,0 +1,52 @@ +package main + +import ( + "strings" + + "github.com/pkg/errors" + "github.com/urfave/cli" +) + +func getAllLabels(cli *cli.Context) (map[string]string, error) { + var labelValues []string + labels := make(map[string]string) + labelValues, labelErr := readKVStrings(cli.StringSlice("label-file"), cli.StringSlice("label")) + if labelErr != nil { + return labels, errors.Wrapf(labelErr, "unable to process labels from --label and label-file") + } + // Process KEY=VALUE stringslice in string map for WithLabels func + if len(labelValues) > 0 { + for _, i := range labelValues { + spliti := strings.Split(i, "=") + if len(spliti) > 1 { + return labels, errors.Errorf("labels must be in KEY=VALUE format: %s is invalid", i) + } + labels[spliti[0]] = spliti[1] + } + } + return labels, nil +} + +func getAllEnvironmentVariables(cli *cli.Context) ([]string, error) { + env, err := readKVStrings(cli.StringSlice("env-file"), cli.StringSlice("env")) + if err != nil { + return []string{}, errors.Wrapf(err, "unable to process variables from --env and --env-file") + } + // Add default environment variables if nothing defined + if len(env) == 0 { + env = append(env, defaultEnvVariables...) + } + return env, nil +} + +func convertStringSliceToMap(strSlice []string, delimiter string) (map[string]string, error) { + sysctl := make(map[string]string) + for _, inputSysctl := range strSlice { + values := strings.Split(inputSysctl, delimiter) + if len(values) < 2 { + return sysctl, errors.Errorf("%s in an invalid sysctl value", inputSysctl) + } + sysctl[values[0]] = values[1] + } + return sysctl, nil +} |