Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow higher memory limit than request #1257

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading