mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Incorporate image and default environment variables in play kube
Also put Environment variable parsing from image data into a helper function Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
@ -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
|
||||
|
@ -489,17 +489,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 +771,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")
|
||||
|
Reference in New Issue
Block a user