Skip to content

Commit

Permalink
Merge pull request #1259 from equinor/master
Browse files Browse the repository at this point in the history
Release new memory limit rules
  • Loading branch information
Richard87 authored Dec 20, 2024
2 parents 00d0827 + 20d238b commit 5fd11e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.48.1
appVersion: 1.68.1
version: 1.48.2
appVersion: 1.68.2
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
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 5fd11e9

Please sign in to comment.