@@ -480,6 +480,39 @@ func TestWaitForAutopilotPlan_WaitsForCompletion(t *testing.T) {
480480	assert .Equal (t , core .PlanCompleted , result .Status .State )
481481}
482482
483+ func  TestWaitForAutopilotPlan_LongRunningUpgrade (t  * testing.T ) {
484+ 	logger  :=  logrus .New ()
485+ 	logger .SetLevel (logrus .ErrorLevel )
486+ 
487+ 	scheme  :=  runtime .NewScheme ()
488+ 	require .NoError (t , apv1b2 .Install (scheme ))
489+ 
490+ 	// Simulate a long-running upgrade that takes more than 5 attempts 
491+ 	// This represents a real k0s infrastructure upgrade that takes several minutes 
492+ 	plan  :=  & apv1b2.Plan {
493+ 		ObjectMeta : metav1.ObjectMeta {
494+ 			Name : "autopilot" ,
495+ 		},
496+ 		Spec : apv1b2.PlanSpec {
497+ 			ID : "long-running-upgrade" ,
498+ 		},
499+ 		Status : apv1b2.PlanStatus {
500+ 			State : core .PlanSchedulable ,
501+ 		},
502+ 	}
503+ 
504+ 	cli  :=  & mockClientWithStateChange {
505+ 		Client :     fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (plan ).Build (),
506+ 		plan :       plan ,
507+ 		callsUntil : 10 , // Will complete after 10 calls - exceeds buggy 5-attempt limit 
508+ 	}
509+ 
510+ 	result , err  :=  waitForAutopilotPlan (t .Context (), cli , logger )
511+ 	require .NoError (t , err , "Should not timeout for long-running upgrades" )
512+ 	assert .Equal (t , "autopilot" , result .Name )
513+ 	assert .Equal (t , core .PlanCompleted , result .Status .State )
514+ }
515+ 
483516// Mock client that fails N times before succeeding 
484517type  mockClientWithRetries  struct  {
485518	client.Client 
0 commit comments