Skip to content

Commit 22f372b

Browse files
authored
fix: bind request annotations are not written (#300)
1 parent f2fdb97 commit 22f372b

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

pkg/scheduler/framework/session_plugins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (ssn *Session) IsRestrictNodeSchedulingEnabled() bool {
366366
func (ssn *Session) MutateBindRequestAnnotations(pod *pod_info.PodInfo, nodeName string) map[string]string {
367367
annotations := map[string]string{}
368368
for _, fn := range ssn.BindRequestMutateFns {
369-
maps.Copy(fn(pod, nodeName), annotations)
369+
maps.Copy(annotations, fn(pod, nodeName))
370370
}
371371
return annotations
372372
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Copyright 2023 NVIDIA CORPORATION
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package framework
7+
8+
import (
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
13+
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api"
14+
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/pod_info"
15+
)
16+
17+
func TestMutateBindRequestAnnotations(t *testing.T) {
18+
tests := []struct {
19+
name string
20+
mutateFns []api.BindRequestMutateFn
21+
expectedAnnotations map[string]string
22+
}{
23+
{
24+
name: "no mutate functions",
25+
mutateFns: []api.BindRequestMutateFn{},
26+
expectedAnnotations: map[string]string{},
27+
},
28+
{
29+
name: "single mutate function",
30+
mutateFns: []api.BindRequestMutateFn{
31+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
32+
return map[string]string{"key1": "value1"}
33+
},
34+
},
35+
expectedAnnotations: map[string]string{"key1": "value1"},
36+
},
37+
{
38+
name: "multiple mutate functions with different keys",
39+
mutateFns: []api.BindRequestMutateFn{
40+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
41+
return map[string]string{"key1": "value1"}
42+
},
43+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
44+
return map[string]string{"key2": "value2"}
45+
},
46+
},
47+
expectedAnnotations: map[string]string{"key1": "value1", "key2": "value2"},
48+
},
49+
{
50+
name: "multiple mutate functions with overlapping keys - later should override",
51+
mutateFns: []api.BindRequestMutateFn{
52+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
53+
return map[string]string{"key1": "value1", "common": "first"}
54+
},
55+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
56+
return map[string]string{"key2": "value2", "common": "second"}
57+
},
58+
},
59+
expectedAnnotations: map[string]string{"key1": "value1", "key2": "value2", "common": "second"},
60+
},
61+
{
62+
name: "mutate function returns nil map",
63+
mutateFns: []api.BindRequestMutateFn{
64+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
65+
return map[string]string{"key1": "value1"}
66+
},
67+
func(pod *pod_info.PodInfo, nodeName string) map[string]string {
68+
return nil
69+
},
70+
},
71+
expectedAnnotations: map[string]string{"key1": "value1"},
72+
},
73+
}
74+
75+
for _, tt := range tests {
76+
t.Run(tt.name, func(t *testing.T) {
77+
ssn := &Session{
78+
BindRequestMutateFns: tt.mutateFns,
79+
}
80+
pod := &pod_info.PodInfo{
81+
Name: "test-pod",
82+
}
83+
nodeName := "test-node"
84+
annotations := ssn.MutateBindRequestAnnotations(pod, nodeName)
85+
assert.Equal(t, tt.expectedAnnotations, annotations)
86+
})
87+
}
88+
}

0 commit comments

Comments
 (0)