@@ -37,19 +37,26 @@ var _ = Describe("NodeMonitor Controller", func() {
3737 var cqMonitor * SlackClusterQueueMonitor
3838 nodeGPUs := v1.ResourceList {v1 .ResourceName ("nvidia.com/gpu" ): resource .MustParse ("4" )}
3939
40- BeforeEach (func () {
41- for _ , nodeName := range []string {node1Name .Name , node2Name .Name } {
42- node := & v1.Node {
43- TypeMeta : metav1.TypeMeta {APIVersion : "v1" , Kind : "Node" },
44- ObjectMeta : metav1.ObjectMeta {Name : nodeName , Labels : map [string ]string {"key1" : "value1" }},
45- }
46- Expect (k8sClient .Create (ctx , node )).To (Succeed ())
47- node = getNode (nodeName )
48- node .Status .Capacity = nodeGPUs
49- Expect (k8sClient .Status ().Update (ctx , node )).To (Succeed ())
40+ createNode := func (nodeName string ) {
41+ node := & v1.Node {
42+ TypeMeta : metav1.TypeMeta {APIVersion : "v1" , Kind : "Node" },
43+ ObjectMeta : metav1.ObjectMeta {Name : nodeName , Labels : map [string ]string {"key1" : "value1" }},
5044 }
45+ Expect (k8sClient .Create (ctx , node )).To (Succeed ())
46+ node = getNode (nodeName )
47+ node .Status .Capacity = nodeGPUs
48+ Expect (k8sClient .Status ().Update (ctx , node )).To (Succeed ())
49+ }
50+
51+ deleteNode := func (nodeName string ) {
52+ Expect (k8sClient .Delete (ctx , & v1.Node {
53+ TypeMeta : metav1.TypeMeta {APIVersion : "v1" , Kind : "Node" },
54+ ObjectMeta : metav1.ObjectMeta {Name : nodeName },
55+ })).To (Succeed ())
56+ }
5157
52- // Create reconciller
58+ BeforeEach (func () {
59+ // Create reconcillers
5360 awConfig := config .NewAppWrapperConfig ()
5461 awConfig .SlackQueueName = slackQueueName
5562 conduit := make (chan event.GenericEvent , 1 )
@@ -66,18 +73,14 @@ var _ = Describe("NodeMonitor Controller", func() {
6673 })
6774
6875 AfterEach (func () {
69- Expect (k8sClient .Delete (ctx , & v1.Node {
70- TypeMeta : metav1.TypeMeta {APIVersion : "v1" , Kind : "Node" },
71- ObjectMeta : metav1.ObjectMeta {Name : node1Name .Name },
72- })).To (Succeed ())
73- Expect (k8sClient .Delete (ctx , & v1.Node {
74- TypeMeta : metav1.TypeMeta {APIVersion : "v1" , Kind : "Node" },
75- ObjectMeta : metav1.ObjectMeta {Name : node2Name .Name },
76- })).To (Succeed ())
7776 nodeMonitor = nil
77+ cqMonitor = nil
7878 })
7979
8080 It ("Autopilot Monitoring" , func () {
81+ createNode (node1Name .Name )
82+ createNode (node2Name .Name )
83+
8184 _ , err := nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node1Name })
8285 Expect (err ).NotTo (HaveOccurred ())
8386 _ , err = nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node2Name })
@@ -113,9 +116,15 @@ var _ = Describe("NodeMonitor Controller", func() {
113116 _ , err = nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node1Name })
114117 Expect (err ).NotTo (HaveOccurred ())
115118 Expect (len (noExecuteNodes )).Should (Equal (0 ))
119+
120+ deleteNode (node1Name .Name )
121+ deleteNode (node2Name .Name )
116122 })
117123
118124 It ("ClusterQueue Lending Adjustment" , func () {
125+ createNode (node1Name .Name )
126+ createNode (node2Name .Name )
127+
119128 _ , err := nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node1Name })
120129 Expect (err ).NotTo (HaveOccurred ())
121130 _ , err = nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node2Name })
@@ -188,7 +197,7 @@ var _ = Describe("NodeMonitor Controller", func() {
188197 Expect (k8sClient .Get (ctx , types.NamespacedName {Name : slackQueueName }, queue )).Should (Succeed ())
189198 Expect (queue .Spec .ResourceGroups [0 ].Flavors [0 ].Resources [0 ].LendingLimit .Value ()).Should (Equal (int64 (2 )))
190199
191- // Increase the slack cluster queue's quota by 2 and expect LedningLimit to increase by 2 to become 4
200+ // Increase the slack cluster queue's quota by 2 and expect LendngLimit to increase by 2 to become 4
192201 Expect (k8sClient .Get (ctx , types.NamespacedName {Name : slackQueueName }, queue )).Should (Succeed ())
193202 queue .Spec .ResourceGroups [0 ].Flavors [0 ].Resources [0 ].NominalQuota = resource .MustParse ("8" )
194203 Expect (k8sClient .Update (ctx , queue )).Should (Succeed ())
@@ -198,6 +207,26 @@ var _ = Describe("NodeMonitor Controller", func() {
198207 Expect (k8sClient .Get (ctx , types.NamespacedName {Name : slackQueueName }, queue )).Should (Succeed ())
199208 Expect (queue .Spec .ResourceGroups [0 ].Flavors [0 ].Resources [0 ].LendingLimit .Value ()).Should (Equal (int64 (4 )))
200209
210+ // Deleting a noncordoned node should not change the lending limit
211+ deleteNode (node2Name .Name )
212+ _ , err = nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node2Name })
213+ Expect (err ).NotTo (HaveOccurred ())
214+ _ , err = cqMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : dispatch })
215+ Expect (err ).NotTo (HaveOccurred ())
216+
217+ Expect (k8sClient .Get (ctx , types.NamespacedName {Name : slackQueueName }, queue )).Should (Succeed ())
218+ Expect (queue .Spec .ResourceGroups [0 ].Flavors [0 ].Resources [0 ].LendingLimit .Value ()).Should (Equal (int64 (4 )))
219+
220+ // Delete the cordoned node; lending limit should now by nil
221+ deleteNode (node1Name .Name )
222+ _ , err = nodeMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : node1Name })
223+ Expect (err ).NotTo (HaveOccurred ())
224+ _ , err = cqMonitor .Reconcile (ctx , reconcile.Request {NamespacedName : dispatch })
225+ Expect (err ).NotTo (HaveOccurred ())
226+
227+ Expect (k8sClient .Get (ctx , types.NamespacedName {Name : slackQueueName }, queue )).Should (Succeed ())
228+ Expect (queue .Spec .ResourceGroups [0 ].Flavors [0 ].Resources [0 ].LendingLimit ).Should (BeNil ())
229+
201230 Expect (k8sClient .Delete (ctx , queue )).To (Succeed ())
202231 })
203232})
0 commit comments