@@ -178,6 +178,96 @@ var _ = Describe("SkyhookNode", func() {
178178 })
179179 })
180180
181+ Context ("Cordon" , func () {
182+ It ("should initialize annotations if the node has none" , func () {
183+ myCordonKey := cordonAnnotationKey ("my-skyhook" )
184+ node := & corev1.Node {
185+ ObjectMeta : metav1.ObjectMeta {
186+ Name : "test-node" ,
187+ },
188+ }
189+
190+ sn , err := NewSkyhookNodeOnly (node , "my-skyhook" )
191+ Expect (err ).ToNot (HaveOccurred ())
192+
193+ sn .Cordon ()
194+
195+ Expect (node .Spec .Unschedulable ).To (BeTrue ())
196+ Expect (node .Annotations ).To (HaveKeyWithValue (myCordonKey , "true" ))
197+ Expect (sn .Changed ()).To (BeTrue ())
198+ })
199+ })
200+
201+ Context ("Uncordon" , func () {
202+ myCordonKey := cordonAnnotationKey ("my-skyhook" )
203+ otherCordonKey := cordonAnnotationKey ("other-skyhook" )
204+
205+ It ("should make the node schedulable if this Skyhook owns the only cordon" , func () {
206+ node := & corev1.Node {
207+ ObjectMeta : metav1.ObjectMeta {
208+ Name : "test-node" ,
209+ Annotations : map [string ]string {
210+ myCordonKey : "true" ,
211+ },
212+ },
213+ Spec : corev1.NodeSpec {Unschedulable : true },
214+ }
215+
216+ sn , err := NewSkyhookNodeOnly (node , "my-skyhook" )
217+ Expect (err ).ToNot (HaveOccurred ())
218+
219+ sn .Uncordon ()
220+
221+ Expect (node .Spec .Unschedulable ).To (BeFalse ())
222+ Expect (node .Annotations ).ToNot (HaveKey (myCordonKey ))
223+ Expect (sn .Changed ()).To (BeTrue ())
224+ })
225+
226+ It ("should keep the node unschedulable if another Skyhook still owns a cordon" , func () {
227+ node := & corev1.Node {
228+ ObjectMeta : metav1.ObjectMeta {
229+ Name : "test-node" ,
230+ Annotations : map [string ]string {
231+ myCordonKey : "true" ,
232+ otherCordonKey : "true" ,
233+ },
234+ },
235+ Spec : corev1.NodeSpec {Unschedulable : true },
236+ }
237+
238+ sn , err := NewSkyhookNodeOnly (node , "my-skyhook" )
239+ Expect (err ).ToNot (HaveOccurred ())
240+
241+ sn .Uncordon ()
242+
243+ Expect (node .Spec .Unschedulable ).To (BeTrue ())
244+ Expect (node .Annotations ).ToNot (HaveKey (myCordonKey ))
245+ Expect (node .Annotations ).To (HaveKeyWithValue (otherCordonKey , "true" ))
246+ Expect (sn .Changed ()).To (BeTrue ())
247+ })
248+
249+ It ("should not change the node if this Skyhook does not own a cordon" , func () {
250+ node := & corev1.Node {
251+ ObjectMeta : metav1.ObjectMeta {
252+ Name : "test-node" ,
253+ Annotations : map [string ]string {
254+ otherCordonKey : "true" ,
255+ },
256+ },
257+ Spec : corev1.NodeSpec {Unschedulable : true },
258+ }
259+
260+ sn , err := NewSkyhookNodeOnly (node , "my-skyhook" )
261+ Expect (err ).ToNot (HaveOccurred ())
262+
263+ sn .Uncordon ()
264+
265+ Expect (node .Spec .Unschedulable ).To (BeTrue ())
266+ Expect (node .Annotations ).To (HaveKeyWithValue (otherCordonKey , "true" ))
267+ Expect (sn .Changed ()).To (BeFalse ())
268+ })
269+ })
270+
181271 Context ("CleanupSCRMetadata" , func () {
182272 It ("should remove matching keys and preserve others" , func () {
183273 node := & corev1.Node {
0 commit comments