diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/main_local.go | 2 | ||||
-rw-r--r-- | cmd/podman/play_kube.go | 8 | ||||
-rw-r--r-- | cmd/podman/shared/create.go | 40 | ||||
-rw-r--r-- | cmd/podman/utils.go | 26 |
4 files changed, 23 insertions, 53 deletions
diff --git a/cmd/podman/main_local.go b/cmd/podman/main_local.go index e008a4617..2915659f1 100644 --- a/cmd/podman/main_local.go +++ b/cmd/podman/main_local.go @@ -103,7 +103,7 @@ func profileOff(cmd *cobra.Command) error { } func setupRootless(cmd *cobra.Command, args []string) error { - if os.Geteuid() == 0 || cmd == _searchCommand || cmd == _versionCommand || strings.HasPrefix(cmd.Use, "help") { + if os.Geteuid() == 0 || cmd == _searchCommand || cmd == _versionCommand || cmd == _mountCommand || strings.HasPrefix(cmd.Use, "help") { return nil } podmanCmd := cliconfig.PodmanCommand{ diff --git a/cmd/podman/play_kube.go b/cmd/podman/play_kube.go index cbe961279..942794cbe 100644 --- a/cmd/podman/play_kube.go +++ b/cmd/podman/play_kube.go @@ -236,7 +236,6 @@ func getPodPorts(containers []v1.Container) []ocicni.PortMapping { func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container, runtime *libpod.Runtime, newImage *image.Image, namespaces map[string]string, volumes map[string]string) (*createconfig.CreateConfig, error) { var ( containerConfig createconfig.CreateConfig - envs map[string]string ) // The default for MemorySwappiness is -1, not 0 @@ -298,9 +297,10 @@ func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container if len(containerConfig.WorkDir) == 0 { containerConfig.WorkDir = "/" } - if len(containerYAML.Env) > 0 { - envs = make(map[string]string) - } + + // Set default environment variables and incorporate data from image, if necessary + envs := shared.EnvVariablesFromData(imageData) + // Environment Variables for _, e := range containerYAML.Env { envs[e.Name] = e.Value diff --git a/cmd/podman/shared/create.go b/cmd/podman/shared/create.go index d694027db..3f54e193f 100644 --- a/cmd/podman/shared/create.go +++ b/cmd/podman/shared/create.go @@ -19,7 +19,6 @@ import ( ann "github.com/containers/libpod/pkg/annotations" "github.com/containers/libpod/pkg/inspect" ns "github.com/containers/libpod/pkg/namespaces" - "github.com/containers/libpod/pkg/rootless" cc "github.com/containers/libpod/pkg/spec" "github.com/containers/libpod/pkg/util" "github.com/docker/docker/pkg/signal" @@ -392,16 +391,6 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod. } if c.IsSet("pod") { if strings.HasPrefix(originalPodName, "new:") { - if rootless.IsRootless() { - // To create a new pod, we must immediately create the userns. - became, ret, err := rootless.BecomeRootInUserNS() - if err != nil { - return nil, err - } - if became { - os.Exit(ret) - } - } // pod does not exist; lets make it var podOptions []libpod.PodCreateOption podOptions = append(podOptions, libpod.WithPodName(podName), libpod.WithInfraContainer(), libpod.WithPodCgroups()) @@ -489,17 +478,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod. } // ENVIRONMENT VARIABLES - env := defaultEnvVariables - if data != nil { - for _, e := range data.Config.Env { - split := strings.SplitN(e, "=", 2) - if len(split) > 1 { - env[split[0]] = split[1] - } else { - env[split[0]] = "" - } - } - } + env := EnvVariablesFromData(data) if err := parse.ReadKVStrings(env, c.StringSlice("env-file"), c.StringArray("env")); err != nil { return nil, errors.Wrapf(err, "unable to process environment variables") } @@ -781,6 +760,23 @@ var defaultEnvVariables = map[string]string{ "TERM": "xterm", } +// EnvVariablesFromData gets sets the default environment variables +// for containers, and reads the variables from the image data, if present. +func EnvVariablesFromData(data *inspect.ImageData) map[string]string { + env := defaultEnvVariables + if data != nil { + for _, e := range data.Config.Env { + split := strings.SplitN(e, "=", 2) + if len(split) > 1 { + env[split[0]] = split[1] + } else { + env[split[0]] = "" + } + } + } + return env +} + func makeHealthCheckFromCli(c *GenericCLIResults) (*manifest.Schema2HealthConfig, error) { inCommand := c.String("healthcheck-command") inInterval := c.String("healthcheck-interval") diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go index 81bd02faa..986db469e 100644 --- a/cmd/podman/utils.go +++ b/cmd/podman/utils.go @@ -51,29 +51,3 @@ func markFlagHiddenForRemoteClient(flagName string, flags *pflag.FlagSet) { flags.MarkHidden(flagName) } } - -// TODO: remove when adapter package takes over this functionality -// func joinContainerOrCreateRootlessUserNS(runtime *libpod.Runtime, ctr *libpod.Container) (bool, int, error) { -// if os.Geteuid() == 0 { -// return false, 0, nil -// } -// s, err := ctr.State() -// if err != nil { -// return false, -1, err -// } -// opts := rootless.Opts{ -// Argument: ctr.ID(), -// } -// if s == libpod.ContainerStateRunning || s == libpod.ContainerStatePaused { -// data, err := ioutil.ReadFile(ctr.Config().ConmonPidFile) -// if err != nil { -// return false, -1, errors.Wrapf(err, "cannot read conmon PID file %q", ctr.Config().ConmonPidFile) -// } -// conmonPid, err := strconv.Atoi(string(data)) -// if err != nil { -// return false, -1, errors.Wrapf(err, "cannot parse PID %q", data) -// } -// return rootless.JoinDirectUserAndMountNSWithOpts(uint(conmonPid), &opts) -// } -// return rootless.BecomeRootInUserNSWithOpts(&opts) -// } |