diff options
author | Yaron Dayagi <ydayagi@redhat.com> | 2022-02-07 12:38:28 +0200 |
---|---|---|
committer | Yaron Dayagi <ydayagi@redhat.com> | 2022-02-23 11:00:09 +0200 |
commit | 5cba5cbfdb85d97094905586427d274bf7a24c0f (patch) | |
tree | feffa6906fb168bddfe9e66294ddcd750252bf50 /pkg/specgen/generate/kube/play_test.go | |
parent | 8b2432422fc188e15130c888a05e41fd881b8ca4 (diff) | |
download | podman-5cba5cbfdb85d97094905586427d274bf7a24c0f.tar.gz podman-5cba5cbfdb85d97094905586427d274bf7a24c0f.tar.bz2 podman-5cba5cbfdb85d97094905586427d274bf7a24c0f.zip |
play kube: set defaults to container resources
this fixes https://github.com/containers/podman/issues/13115
the change tries to immitate k8s behavior.
when limits are not set the container's limits are all CPU and all RAM
when requests are missing then they are equal to limits
Signed-off-by: Yaron Dayagi <ydayagi@redhat.com>
Diffstat (limited to 'pkg/specgen/generate/kube/play_test.go')
-rw-r--r-- | pkg/specgen/generate/kube/play_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/pkg/specgen/generate/kube/play_test.go b/pkg/specgen/generate/kube/play_test.go index 282324310..6798fdb1b 100644 --- a/pkg/specgen/generate/kube/play_test.go +++ b/pkg/specgen/generate/kube/play_test.go @@ -6,10 +6,12 @@ import ( "io/ioutil" "math" "os" + "runtime" "strconv" "testing" "github.com/containers/common/pkg/secrets" + "github.com/docker/docker/pkg/system" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -193,6 +195,11 @@ func TestEnvVarValue(t *testing.T) { assert.NoError(t, err) defer os.RemoveAll(d) secretsManager := createSecrets(t, d) + stringNumCPUs := strconv.Itoa(runtime.NumCPU()) + + mi, err := system.ReadMemInfo() + assert.Nil(t, err) + stringMemTotal := strconv.FormatInt(mi.MemTotal, 10) tests := []struct { name string @@ -694,6 +701,78 @@ func TestEnvVarValue(t *testing.T) { true, strconv.Itoa(int(float64(cpuInt) / 0.001)), }, + { + "ResourceFieldRefNoLimitMemory", + v1.EnvVar{ + Name: "FOO", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "limits.memory", + }, + }, + }, + CtrSpecGenOptions{ + Container: v1.Container{ + Name: "test", + }, + }, + true, + stringMemTotal, + }, + { + "ResourceFieldRefNoRequestMemory", + v1.EnvVar{ + Name: "FOO", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "requests.memory", + }, + }, + }, + CtrSpecGenOptions{ + Container: v1.Container{ + Name: "test", + }, + }, + true, + stringMemTotal, + }, + { + "ResourceFieldRefNoLimitCPU", + v1.EnvVar{ + Name: "FOO", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "limits.cpu", + }, + }, + }, + CtrSpecGenOptions{ + Container: v1.Container{ + Name: "test", + }, + }, + true, + stringNumCPUs, + }, + { + "ResourceFieldRefNoRequestCPU", + v1.EnvVar{ + Name: "FOO", + ValueFrom: &v1.EnvVarSource{ + ResourceFieldRef: &v1.ResourceFieldSelector{ + Resource: "requests.cpu", + }, + }, + }, + CtrSpecGenOptions{ + Container: v1.Container{ + Name: "test", + }, + }, + true, + stringNumCPUs, + }, } for _, test := range tests { |