@@ -499,7 +499,7 @@ var _ = Describe("NodeReadinessRule Controller", func() {
499499 ruleName := "bootstrap-test-rule"
500500
501501 // Initially not completed
502- completed := readinessController .isBootstrapCompleted (nodeName , ruleName )
502+ completed := readinessController .isBootstrapCompleted (ctx , nodeName , ruleName )
503503 Expect (completed ).To (BeFalse ())
504504
505505 // Create a node for testing
@@ -516,9 +516,64 @@ var _ = Describe("NodeReadinessRule Controller", func() {
516516
517517 // Should now be completed
518518 Eventually (func () bool {
519- return readinessController .isBootstrapCompleted (nodeName , ruleName )
519+ return readinessController .isBootstrapCompleted (ctx , nodeName , ruleName )
520520 }).Should (BeTrue ())
521521 })
522+
523+ It ("should return false when context is cancelled" , func () {
524+ nodeName := "bootstrap-ctx-test-node"
525+ ruleName := "bootstrap-ctx-test-rule"
526+
527+ // Create a node with the bootstrap annotation already set
528+ node := & corev1.Node {
529+ ObjectMeta : metav1.ObjectMeta {
530+ Name : nodeName ,
531+ Annotations : map [string ]string {
532+ "readiness.k8s.io/bootstrap-completed-" + ruleName : "true" ,
533+ },
534+ },
535+ }
536+ Expect (k8sClient .Create (ctx , node )).To (Succeed ())
537+ defer func () { _ = k8sClient .Delete (ctx , node ) }()
538+
539+ // Verify it returns true with a valid context
540+ Expect (readinessController .isBootstrapCompleted (ctx , nodeName , ruleName )).To (BeTrue ())
541+
542+ // A cancelled context should cause the Get to fail, returning false
543+ cancelledCtx , cancel := context .WithCancel (ctx )
544+ cancel ()
545+ Expect (readinessController .isBootstrapCompleted (cancelledCtx , nodeName , ruleName )).To (BeFalse ())
546+ })
547+
548+ It ("should set bootstrap annotation via patch in markBootstrapCompleted" , func () {
549+ nodeName := "bootstrap-patch-test-node"
550+ ruleName := "bootstrap-patch-test-rule"
551+
552+ // Create a node with existing annotations that should be preserved
553+ node := & corev1.Node {
554+ ObjectMeta : metav1.ObjectMeta {
555+ Name : nodeName ,
556+ Annotations : map [string ]string {
557+ "existing-annotation" : "should-be-preserved" ,
558+ },
559+ },
560+ }
561+ Expect (k8sClient .Create (ctx , node )).To (Succeed ())
562+ defer func () { _ = k8sClient .Delete (ctx , node ) }()
563+
564+ // Mark bootstrap completed
565+ readinessController .markBootstrapCompleted (ctx , nodeName , ruleName )
566+
567+ // Verify annotation was added and existing annotation is preserved
568+ Eventually (func (g Gomega ) {
569+ updatedNode := & corev1.Node {}
570+ g .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : nodeName }, updatedNode )).To (Succeed ())
571+ g .Expect (updatedNode .Annotations ).To (HaveKeyWithValue (
572+ "readiness.k8s.io/bootstrap-completed-" + ruleName , "true" ))
573+ g .Expect (updatedNode .Annotations ).To (HaveKeyWithValue (
574+ "existing-annotation" , "should-be-preserved" ))
575+ }).Should (Succeed ())
576+ })
522577 })
523578
524579 Context ("when a new rule is created" , func () {
0 commit comments