Skip to content

Commit

Permalink
Generate kube should'd add podman default environment vars
Browse files Browse the repository at this point in the history
Currently we add the default PATH, TERM and container from Podman
to every kubernetes.yaml file. These values should not be recorded
in the yaml files.

Signed-off-by: Daniel J Walsh <[email protected]>

<MH: Fixed cherry-pick conflicts>

Signed-off-by: Matthew Heon <[email protected]>
  • Loading branch information
rhatdan authored and mheon committed Sep 22, 2021
1 parent 909cbfe commit 72e19cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
5 changes: 5 additions & 0 deletions libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/env"
"github.com/containers/podman/v3/pkg/lookup"
"github.com/containers/podman/v3/pkg/namespaces"
"github.com/containers/podman/v3/pkg/specgen"
Expand Down Expand Up @@ -570,12 +571,16 @@ func ocicniPortMappingToContainerPort(portMappings []ocicni.PortMapping) ([]v1.C

// libpodEnvVarsToKubeEnvVars converts a key=value string slice to []v1.EnvVar
func libpodEnvVarsToKubeEnvVars(envs []string) ([]v1.EnvVar, error) {
defaultEnv := env.DefaultEnvVariables()
envVars := make([]v1.EnvVar, 0, len(envs))
for _, e := range envs {
split := strings.SplitN(e, "=", 2)
if len(split) != 2 {
return envVars, errors.Errorf("environment variable %s is malformed; should be key=value", e)
}
if defaultEnv[split[0]] == split[1] {
continue
}
ev := v1.EnvVar{
Name: split[0],
Value: split[1],
Expand Down
5 changes: 3 additions & 2 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const whiteSpaces = " \t"
// DefaultEnvVariables returns a default environment, with $PATH and $TERM set.
func DefaultEnvVariables() map[string]string {
return map[string]string{
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM": "xterm",
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM": "xterm",
"container": "podman",
}
}

Expand Down
24 changes: 0 additions & 24 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ spec:
- -d
- "1.5"
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: container
value: podman
- name: HOSTNAME
value: label-pod
image: quay.io/libpod/alpine:latest
Expand Down Expand Up @@ -171,12 +165,6 @@ spec:
- -d
- "1.5"
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: container
value: podman
- name: HOSTNAME
value: label-pod
image: quay.io/libpod/alpine:latest
Expand Down Expand Up @@ -287,13 +275,7 @@ spec:
- {{.}}
{{ end }}
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: HOSTNAME
- name: container
value: podman
{{ range .Env }}
- name: {{ .Name }}
{{ if (eq .ValueFrom "configmap") }}
Expand Down Expand Up @@ -453,13 +435,7 @@ spec:
- {{.}}
{{ end }}
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: HOSTNAME
- name: container
value: podman
image: {{ .Image }}
name: {{ .Name }}
imagePullPolicy: {{ .PullPolicy }}
Expand Down

0 comments on commit 72e19cf

Please sign in to comment.