aboutsummaryrefslogtreecommitdiff
path: root/pkg/specgen
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/specgen')
-rw-r--r--pkg/specgen/generate/container.go36
-rw-r--r--pkg/specgen/generate/validate.go6
-rw-r--r--pkg/specgen/specgen.go3
3 files changed, 38 insertions, 7 deletions
diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go
index ec85f0f79..d57efa0d1 100644
--- a/pkg/specgen/generate/container.go
+++ b/pkg/specgen/generate/container.go
@@ -19,6 +19,7 @@ import (
"github.com/containers/podman/v4/pkg/signal"
"github.com/containers/podman/v4/pkg/specgen"
spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/openshift/imagebuilder"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
@@ -131,6 +132,17 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
defaultEnvs = envLib.Join(envLib.DefaultEnvVariables(), envLib.Join(defaultEnvs, envs))
}
+ for _, e := range s.EnvMerge {
+ processedWord, err := imagebuilder.ProcessWord(e, envLib.Slice(defaultEnvs))
+ if err != nil {
+ return nil, fmt.Errorf("unable to process variables for --env-merge %s: %w", e, err)
+ }
+ splitWord := strings.Split(processedWord, "=")
+ if _, ok := defaultEnvs[splitWord[0]]; ok {
+ defaultEnvs[splitWord[0]] = splitWord[1]
+ }
+ }
+
for _, e := range s.UnsetEnv {
delete(defaultEnvs, e)
}
@@ -140,10 +152,8 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}
// First transform the os env into a map. We need it for the labels later in
// any case.
- osEnv, err := envLib.ParseSlice(os.Environ())
- if err != nil {
- return nil, fmt.Errorf("error parsing host environment variables: %w", err)
- }
+ osEnv := envLib.Map(os.Environ())
+
// Caller Specified defaults
if s.EnvHost {
defaultEnvs = envLib.Join(defaultEnvs, osEnv)
@@ -347,9 +357,21 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, contaierID s
conf.Systemd = tmpSystemd
conf.Mounts = tmpMounts
- if conf.Spec != nil && conf.Spec.Linux != nil && conf.Spec.Linux.Resources != nil {
- if specg.ResourceLimits == nil {
- specg.ResourceLimits = conf.Spec.Linux.Resources
+ if conf.Spec != nil {
+ if conf.Spec.Linux != nil && conf.Spec.Linux.Resources != nil {
+ if specg.ResourceLimits == nil {
+ specg.ResourceLimits = conf.Spec.Linux.Resources
+ }
+ }
+ if conf.Spec.Process != nil && conf.Spec.Process.Env != nil {
+ env := make(map[string]string)
+ for _, entry := range conf.Spec.Process.Env {
+ split := strings.Split(entry, "=")
+ if len(split) == 2 {
+ env[split[0]] = split[1]
+ }
+ }
+ specg.Env = env
}
}
diff --git a/pkg/specgen/generate/validate.go b/pkg/specgen/generate/validate.go
index 9c933d747..3c5d5fb96 100644
--- a/pkg/specgen/generate/validate.go
+++ b/pkg/specgen/generate/validate.go
@@ -9,6 +9,7 @@ import (
"github.com/containers/common/pkg/cgroups"
"github.com/containers/common/pkg/sysinfo"
+ "github.com/containers/podman/v4/pkg/rootless"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/utils"
)
@@ -19,6 +20,11 @@ func verifyContainerResourcesCgroupV1(s *specgen.SpecGenerator) ([]string, error
sysInfo := sysinfo.New(true)
+ if s.ResourceLimits != nil && rootless.IsRootless() {
+ s.ResourceLimits = nil
+ warnings = append(warnings, "Resource limits are not supported and ignored on cgroups V1 rootless systems")
+ }
+
if s.ResourceLimits == nil {
return warnings, nil
}
diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go
index b90f07ef8..51b6736a9 100644
--- a/pkg/specgen/specgen.go
+++ b/pkg/specgen/specgen.go
@@ -204,6 +204,9 @@ type ContainerBasicConfig struct {
// The execution domain system allows Linux to provide limited support
// for binaries compiled under other UNIX-like operating systems.
Personality *spec.LinuxPersonality `json:"personality,omitempty"`
+ // EnvMerge takes the specified environment variables from image and preprocess them before injecting them into the
+ // container.
+ EnvMerge []string `json:"envmerge,omitempty"`
// UnsetEnv unsets the specified default environment variables from the image or from buildin or containers.conf
// Optional.
UnsetEnv []string `json:"unsetenv,omitempty"`