Skip to content

Commit

Permalink
Allow higher memory limit than request (#1257)
Browse files Browse the repository at this point in the history
* Allow higher memory limit than request

* added some test cases
  • Loading branch information
Richard87 authored Dec 19, 2024
1 parent f07283d commit f759b05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
15 changes: 12 additions & 3 deletions pkg/apis/pipeline/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@ func correctRadixApplication(ctx context.Context, ra *radixv1.RadixApplication)
func buildResource(component radixv1.RadixCommonComponent) radixv1.ResourceRequirements {
memoryReqName := corev1.ResourceMemory.String()
resources := component.GetResources()
delete(resources.Limits, memoryReqName)

if requestsMemory, ok := resources.Requests[memoryReqName]; ok {
memReq, hasMemReq := resources.Requests[memoryReqName]
memLimit, hasMemLimit := resources.Limits[memoryReqName]

if hasMemReq && !hasMemLimit {
if resources.Limits == nil {
resources.Limits = radixv1.ResourceList{}
}
resources.Limits[memoryReqName] = requestsMemory
resources.Limits[memoryReqName] = memReq
}

if !hasMemReq && hasMemLimit {
if resources.Requests == nil {
resources.Requests = radixv1.ResourceList{}
}
resources.Requests[memoryReqName] = memLimit
}
return resources
}
14 changes: 11 additions & 3 deletions pkg/apis/pipeline/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/equinor/radix-operator/pkg/apis/config/dnsalias"
"github.com/equinor/radix-operator/pkg/apis/pipeline/application"
validate "github.com/equinor/radix-operator/pkg/apis/radixvalidators"
"github.com/equinor/radix-operator/pkg/apis/utils"
radixfake "github.com/equinor/radix-operator/pkg/client/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
Expand All @@ -27,8 +28,15 @@ func Test_CreateRadixApplication_LimitMemoryIsTakenFromRequestsMemory(t *testing
require.NoError(t, err)
ra, err := application.CreateRadixApplication(context.Background(), radixClient, &dnsalias.DNSConfig{}, string(configFileContent))
require.NoError(t, err)
assert.Equal(t, "100Mi", ra.Spec.Components[0].Resources.Requests["memory"], "server1 invalid resource requests memory")
assert.Equal(t, "100Mi", ra.Spec.Components[0].Resources.Limits["memory"], "server1 invalid resource limits memory")
assert.Equal(t, "100Mi", ra.Spec.Components[1].Resources.Limits["memory"], "server2 invalid resource limits memory")
assert.Empty(t, ra.Spec.Components[2].Resources.Limits["memory"], "server3 not expected resource limits memory")
assert.Empty(t, ra.Spec.Components[3].Resources.Limits["memory"], "server4 not expected resource limits memory")
assert.Equal(t, "100Mi", ra.Spec.Components[1].Resources.Requests["memory"], "server2 invalid resource requests memory")
assert.Equal(t, "200Mi", ra.Spec.Components[1].Resources.Limits["memory"], "server2 invalid resource limits memory")
assert.Equal(t, "200Mi", ra.Spec.Components[2].Resources.Requests["memory"], "server3 invalid resource requests memory")
assert.Equal(t, "200Mi", ra.Spec.Components[2].Resources.Limits["memory"], "server3 invalid resource limits memory")
assert.Equal(t, "200Mi", ra.Spec.Components[3].Resources.Requests["memory"], "server4 invalid resource requests memory")
assert.Equal(t, "200Mi", ra.Spec.Components[3].Resources.Limits["memory"], "server4 invalid resource limits memory")

err = validate.CanRadixApplicationBeInserted(context.Background(), radixClient, ra, nil)
assert.NoError(t, err)
}

0 comments on commit f759b05

Please sign in to comment.