summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorcdoern <cbdoer23@g.holycross.edu>2022-04-11 22:54:08 -0400
committercdoern <cdoern@redhat.com>2022-04-18 15:38:24 -0400
commitbe0da4a22265ade11c603fb847531a080d844a06 (patch)
tree3430ac7e1125e02ed6c3413e3f887ac017e874fe /pkg/api/handlers
parentd6f47e692bc694d3ec4f3505acaccf7fa0b73231 (diff)
downloadpodman-be0da4a22265ade11c603fb847531a080d844a06.tar.gz
podman-be0da4a22265ade11c603fb847531a080d844a06.tar.bz2
podman-be0da4a22265ade11c603fb847531a080d844a06.zip
Translate Memory Limit to Swap in API
in specgen, CLI path uses the given memory limit to define the swap value (if not already specified) add a route to this piece of code from within the api handlers resolves #13145 Signed-off-by: cdoern <cdoern@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/libpod/containers_create.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/containers_create.go b/pkg/api/handlers/libpod/containers_create.go
index 4f9dc008d..1043dec4d 100644
--- a/pkg/api/handlers/libpod/containers_create.go
+++ b/pkg/api/handlers/libpod/containers_create.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
+ "strconv"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/pkg/api/handlers/utils"
@@ -11,6 +12,7 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgen/generate"
+ "github.com/containers/podman/v4/pkg/specgenutil"
"github.com/pkg/errors"
)
@@ -39,6 +41,20 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
t := true
sg.Passwd = &t
}
+
+ // need to check for memory limit to adjust swap
+ if sg.ResourceLimits != nil && sg.ResourceLimits.Memory != nil {
+ s := ""
+ var l int64 = 0
+ if sg.ResourceLimits.Memory.Swap != nil {
+ s = strconv.Itoa(int(*sg.ResourceLimits.Memory.Swap))
+ }
+ if sg.ResourceLimits.Memory.Limit != nil {
+ l = *sg.ResourceLimits.Memory.Limit
+ }
+ specgenutil.LimitToSwap(sg.ResourceLimits.Memory, s, l)
+ }
+
warn, err := generate.CompleteSpec(r.Context(), runtime, &sg)
if err != nil {
utils.InternalServerError(w, err)
@@ -54,6 +70,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, err)
return
}
+
response := entities.ContainerCreateResponse{ID: ctr.ID(), Warnings: warn}
utils.WriteJSON(w, http.StatusCreated, response)
}