Skip to content

Commit e5f633f

Browse files
committed
internal: reslist: rename functions for clarity
AddCoreResources -> AddInPlace SubCoreResources -> SubInPlace the new names are both more concise and more expressive. trivial rename only. Signed-off-by: Francesco Romani <fromani@redhat.com>
1 parent 0a1fbb0 commit e5f633f

6 files changed

Lines changed: 17 additions & 17 deletions

File tree

internal/baseload/baseload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ func (nl Load) String() string {
8989
// Apply adjust the given ResourceList with the current node load by mutating
9090
// the parameter in place
9191
func (nl Load) Apply(res corev1.ResourceList) {
92-
resourcelist.AddCoreResources(res, nl.Resources)
92+
resourcelist.AddInPlace(res, nl.Resources)
9393
}
9494

9595
// Deduct subtract the current node load from the given ResourceList by mutating
9696
// the parameter in place
9797
func (nl Load) Deduct(res corev1.ResourceList) error {
98-
return resourcelist.SubCoreResources(res, nl.Resources)
98+
return resourcelist.SubInPlace(res, nl.Resources)
9999
}
100100

101101
func (nl Load) CPU() resource.Quantity {

internal/resourcelist/resourcelist.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ func FromContainerRequests(containers []corev1.Container) corev1.ResourceList {
8888
return res
8989
}
9090

91-
func AddCoreResources(res, resToAdd corev1.ResourceList) {
91+
func AddInPlace(res, resToAdd corev1.ResourceList) {
9292
for resName, resQty := range resToAdd {
9393
qty := res[resName]
9494
qty.Add(resQty)
9595
res[resName] = qty
9696
}
9797
}
9898

99-
func SubCoreResources(res, resToSub corev1.ResourceList) error {
99+
func SubInPlace(res, resToSub corev1.ResourceList) error {
100100
for resName, resQty := range resToSub {
101101
if resQty.Cmp(res[resName]) > 0 {
102102
return fmt.Errorf("cannot subtract resource %q because it is not found in the current resources", resName)

internal/resourcelist/resourcelist_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestToString(t *testing.T) {
7676
}
7777
}
7878

79-
func TestAddCoreResources(t *testing.T) {
79+
func TestAddInPlace(t *testing.T) {
8080
type testCase struct {
8181
res corev1.ResourceList
8282
resToAdd corev1.ResourceList
@@ -108,7 +108,7 @@ func TestAddCoreResources(t *testing.T) {
108108
for _, tc := range testCases {
109109
t.Run(ToString(tc.expected), func(t *testing.T) {
110110
res := tc.res.DeepCopy()
111-
AddCoreResources(res, tc.resToAdd)
111+
AddInPlace(res, tc.resToAdd)
112112
// comparing strings it just easier
113113
got := ToString(res)
114114
expected := ToString(tc.expected)
@@ -119,7 +119,7 @@ func TestAddCoreResources(t *testing.T) {
119119
}
120120
}
121121

122-
func TestSubCoreResources(t *testing.T) {
122+
func TestSubInPlace(t *testing.T) {
123123
type testCase struct {
124124
res corev1.ResourceList
125125
resToSub corev1.ResourceList
@@ -168,7 +168,7 @@ func TestSubCoreResources(t *testing.T) {
168168
for _, tc := range testCases {
169169
t.Run(ToString(tc.expected), func(t *testing.T) {
170170
res := tc.res.DeepCopy()
171-
err := SubCoreResources(res, tc.resToSub)
171+
err := SubInPlace(res, tc.resToSub)
172172
if err != nil {
173173
t.Errorf("Error while calculating resources: %s", err.Error())
174174
}

test/e2e/serial/tests/non_regression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload placeme
390390
corev1.ResourceCPU: resource.MustParse("1"),
391391
corev1.ResourceMemory: resource.MustParse("100Mi"),
392392
}
393-
e2ereslist.AddCoreResources(requiredRes, minRes)
393+
e2ereslist.AddInPlace(requiredRes, minRes)
394394

395395
pod := objects.NewTestPodPause(fxt.Namespace.Name, "testpod")
396396
pod.Spec.SchedulerName = serialconfig.Config.SchedulerName

test/e2e/serial/tests/workload_overhead.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload overhea
164164
klog.Infof("kubernetes pod fixed overhead rounded to: %s", resourcelist.ToString(podFixedOverhead))
165165

166166
zoneRequiredResources := podResources.DeepCopy()
167-
resourcelist.AddCoreResources(zoneRequiredResources, podFixedOverhead)
168-
resourcelist.AddCoreResources(zoneRequiredResources, minRes)
167+
resourcelist.AddInPlace(zoneRequiredResources, podFixedOverhead)
168+
resourcelist.AddInPlace(zoneRequiredResources, minRes)
169169

170170
resStr := resourcelist.ToString(zoneRequiredResources)
171171
klog.Infof("kubernetes final zone required resources: %s", resStr)
@@ -251,7 +251,7 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload overhea
251251
Expect(pods).ToNot(BeEmpty(), "cannot find any pods for DP %s/%s", deployment.Namespace, deployment.Name)
252252

253253
podResourcesWithOverhead := podResources.DeepCopy()
254-
resourcelist.AddCoreResources(podResourcesWithOverhead, podFixedOverhead)
254+
resourcelist.AddInPlace(podResourcesWithOverhead, podFixedOverhead)
255255

256256
for _, pod := range pods {
257257
Expect(pod.Spec.NodeName).To(Equal(targetNodeName))
@@ -328,8 +328,8 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload overhea
328328
klog.Infof("kubernetes pod fixed overhead rounded to: %s", resourcelist.ToString(podFixedOverhead))
329329

330330
zoneRequiredResources := podResources.DeepCopy()
331-
resourcelist.AddCoreResources(zoneRequiredResources, podFixedOverhead)
332-
resourcelist.AddCoreResources(zoneRequiredResources, minRes)
331+
resourcelist.AddInPlace(zoneRequiredResources, podFixedOverhead)
332+
resourcelist.AddInPlace(zoneRequiredResources, minRes)
333333

334334
resStr := resourcelist.ToString(zoneRequiredResources)
335335
klog.Infof("kubernetes final zone required resources: %s", resStr)

test/e2e/serial/tests/workload_placement.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload placeme
635635
dataAfter, err := yaml.Marshal(nrtPostCreate)
636636
Expect(err).ToNot(HaveOccurred())
637637
// Adding resources of both the replicas
638-
e2ereslist.AddCoreResources(rl0, rl1)
638+
e2ereslist.AddInPlace(rl0, rl1)
639639

640640
match, err := checkConsumedRes(*nrtInitial, *nrtPostCreate, rl0, corev1qos.GetPodQOS(&updatedPod0))
641641
Expect(err).ToNot(HaveOccurred())
@@ -649,7 +649,7 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload placeme
649649
corev1.ResourceMemory: resource.MustParse("100Mi"),
650650
}
651651

652-
err = e2ereslist.SubCoreResources(reqResources, resourceDiff)
652+
err = e2ereslist.SubInPlace(reqResources, resourceDiff)
653653
Expect(err).ToNot(HaveOccurred())
654654

655655
updatedDp.Spec.Template.Spec.Containers[0].Resources.Requests = reqResources
@@ -701,7 +701,7 @@ var _ = Describe("[serial][disruptive][scheduler] numaresources workload placeme
701701
dataAfterUpdate, err := yaml.Marshal(nrtPostUpdate)
702702
Expect(err).ToNot(HaveOccurred())
703703
// Adding resources of both the replicas
704-
e2ereslist.AddCoreResources(rl0, rl1)
704+
e2ereslist.AddInPlace(rl0, rl1)
705705
match, err = checkConsumedRes(*nrtInitial, *nrtPostUpdate, rl0, corev1qos.GetPodQOS(&updatedPod0))
706706
Expect(err).ToNot(HaveOccurred())
707707
Expect(match).ToNot(BeEmpty(), "inconsistent accounting: no resources consumed by the running pod,\nNRT before test's pod: %s \nNRT after: %s \n total required resources: %s", dataBefore, dataAfterUpdate, e2ereslist.ToString(rl0))

0 commit comments

Comments
 (0)