From 940907951b5c071319ac9ec44958f03d074fb3d6 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Sun, 26 Jul 2020 22:14:49 +0200 Subject: [PATCH] Support ulimits in docker stack deploy This is related to moby/moby 40639. Signed-off-by: Albin Kerouanton Signed-off-by: Sebastiaan van Stijn --- cli/compose/convert/service.go | 29 +++++++++++++++++++++++++++++ cli/compose/types/types.go | 1 - 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 1b15fa36ca..b0095f19be 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" + "github.com/docker/go-units" "github.com/pkg/errors" ) @@ -151,6 +152,7 @@ func Service( Sysctls: service.Sysctls, CapabilityAdd: capAdd, CapabilityDrop: capDrop, + Ulimits: convertUlimits(service.Ulimits), }, LogDriver: logDriver, Resources: resources, @@ -680,3 +682,30 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec } return &swarmCredSpec, nil } + +func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*units.Ulimit { + newUlimits := make(map[string]*units.Ulimit) + for name, u := range origUlimits { + if u.Single != 0 { + newUlimits[name] = &units.Ulimit{ + Name: name, + Soft: int64(u.Single), + Hard: int64(u.Single), + } + } else { + newUlimits[name] = &units.Ulimit{ + Name: name, + Soft: int64(u.Soft), + Hard: int64(u.Hard), + } + } + } + var ulimits []*units.Ulimit + for _, ulimit := range newUlimits { + ulimits = append(ulimits, ulimit) + } + sort.SliceStable(ulimits, func(i, j int) bool { + return ulimits[i].Name < ulimits[j].Name + }) + return ulimits +} diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index fd748d62b2..19423ce002 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -23,7 +23,6 @@ var UnsupportedProperties = []string{ "restart", "security_opt", "shm_size", - "ulimits", "userns_mode", }