mirror of https://github.com/docker/compose.git
Fix resource limit defaults and make aci e2e tests pass
This commit is contained in:
parent
eda438aaed
commit
82ff8dcd7d
|
@ -21,6 +21,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -267,7 +268,9 @@ func (s serviceConfigAciHelper) getAciContainer(volumesCache map[string]bool) (c
|
||||||
memLimit := 1. // Default 1 Gb
|
memLimit := 1. // Default 1 Gb
|
||||||
var cpuLimit float64 = 1
|
var cpuLimit float64 = 1
|
||||||
if s.Deploy != nil && s.Deploy.Resources.Limits != nil {
|
if s.Deploy != nil && s.Deploy.Resources.Limits != nil {
|
||||||
memLimit = float64(bytesToGb(s.Deploy.Resources.Limits.MemoryBytes))
|
if s.Deploy.Resources.Limits.MemoryBytes != 0 {
|
||||||
|
memLimit = bytesToGb(s.Deploy.Resources.Limits.MemoryBytes)
|
||||||
|
}
|
||||||
if s.Deploy.Resources.Limits.NanoCPUs != "" {
|
if s.Deploy.Resources.Limits.NanoCPUs != "" {
|
||||||
cpuLimit, err = strconv.ParseFloat(s.Deploy.Resources.Limits.NanoCPUs, 0)
|
cpuLimit, err = strconv.ParseFloat(s.Deploy.Resources.Limits.NanoCPUs, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -295,8 +298,9 @@ func (s serviceConfigAciHelper) getAciContainer(volumesCache map[string]bool) (c
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func bytesToGb(b types.UnitBytes) int64 {
|
func bytesToGb(b types.UnitBytes) float64 {
|
||||||
return int64(b) / 1024 / 1024 / 1024 // from bytes to gigabytes
|
f := float64(b) / 1024 / 1024 / 1024 // from bytes to gigabytes
|
||||||
|
return math.Round(f*100) / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerGroupToContainer composes a Container from an ACI container definition
|
// ContainerGroupToContainer composes a Container from an ACI container definition
|
||||||
|
|
|
@ -213,6 +213,67 @@ func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerMultiplePorts
|
||||||
Expect(*groupPorts[1].Port).To(Equal(int32(8080)))
|
Expect(*groupPorts[1].Port).To(Equal(int32(8080)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerResourceLimits() {
|
||||||
|
_0_1Gb := 0.1 * 1024 * 1024 * 1024
|
||||||
|
project := compose.Project{
|
||||||
|
Name: "",
|
||||||
|
Config: types.Config{
|
||||||
|
Services: []types.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "service1",
|
||||||
|
Image: "image1",
|
||||||
|
Deploy: &types.DeployConfig{
|
||||||
|
Resources: types.Resources{
|
||||||
|
Limits: &types.Resource{
|
||||||
|
NanoCPUs: "0.1",
|
||||||
|
MemoryBytes: types.UnitBytes(_0_1Gb),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
group, err := ToContainerGroup(suite.ctx, project)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
container1 := (*group.Containers)[0]
|
||||||
|
limits := *container1.Resources.Limits
|
||||||
|
Expect(*limits.CPU).To(Equal(float64(0.1)))
|
||||||
|
Expect(*limits.MemoryInGB).To(Equal(float64(0.1)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerResourceLimitsDefaults() {
|
||||||
|
project := compose.Project{
|
||||||
|
Name: "",
|
||||||
|
Config: types.Config{
|
||||||
|
Services: []types.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "service1",
|
||||||
|
Image: "image1",
|
||||||
|
Deploy: &types.DeployConfig{
|
||||||
|
Resources: types.Resources{
|
||||||
|
Limits: &types.Resource{
|
||||||
|
NanoCPUs: "",
|
||||||
|
MemoryBytes: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
group, err := ToContainerGroup(suite.ctx, project)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
container1 := (*group.Containers)[0]
|
||||||
|
limits := *container1.Resources.Limits
|
||||||
|
Expect(*limits.CPU).To(Equal(float64(1)))
|
||||||
|
Expect(*limits.MemoryInGB).To(Equal(float64(1)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestConvertTestSuite(t *testing.T) {
|
func TestConvertTestSuite(t *testing.T) {
|
||||||
RegisterTestingT(t)
|
RegisterTestingT(t)
|
||||||
suite.Run(t, new(ConvertTestSuite))
|
suite.Run(t, new(ConvertTestSuite))
|
||||||
|
|
Loading…
Reference in New Issue