@@ -215,6 +215,34 @@ func TestUpgradePipelineStepReconciler(t *testing.T) {
215215 require .Nil (t , meta .FindStatusCondition (got .Status .Conditions , string (ConditionTypeError )))
216216 })
217217
218+ t .Run ("Clears stale readiness when remote step is missing and create requeues" , func (t * testing.T ) {
219+ step := newObjectFromYAML [v1alpha1.UpgradePipelineStep ](t , yamlUpgradePipelineStep )
220+ step .Generation = 1
221+ step .Status .ID = "stale-step"
222+ metav1 .SetMetaDataAnnotation (& step .ObjectMeta , processedGenerationAnnotation , "1" )
223+ metav1 .SetMetaDataAnnotation (& step .ObjectMeta , instanceIsRunningAnnotation , "true" )
224+
225+ avn := avngen .NewMockClient (t )
226+ avn .EXPECT ().
227+ UpgradePipelineStepList (mock .Anything , step .Spec .OrganizationID , listQuery (step )).
228+ Return (& upgradepipeline.UpgradePipelineStepListOut {}, nil ).Once ()
229+ avn .EXPECT ().
230+ UpgradePipelineStepCreate (mock .Anything , step .Spec .OrganizationID , mock .Anything ).
231+ Return (nil , newAivenError (404 , "service not found" )).Once ()
232+
233+ r , res , err := runScenario (t , step , avn )
234+ require .NoError (t , err )
235+ require .Equal (t , ctrlruntime.Result {RequeueAfter : requeueTimeout }, res )
236+
237+ got := & v1alpha1.UpgradePipelineStep {}
238+ require .NoError (t , r .Get (t .Context (), types.NamespacedName {Name : step .Name , Namespace : step .Namespace }, got ))
239+ require .False (t , IsReadyToUse (got ))
240+ require .NotContains (t , got .Annotations , instanceIsRunningAnnotation )
241+ condition := meta .FindStatusCondition (got .Status .Conditions , conditionTypeRunning )
242+ require .NotNil (t , condition )
243+ require .Equal (t , metav1 .ConditionFalse , condition .Status )
244+ })
245+
218246 t .Run ("Observes existing upgrade pipeline step by spec and refreshes stale status ID" , func (t * testing.T ) {
219247 step := newObjectFromYAML [v1alpha1.UpgradePipelineStep ](t , yamlUpgradePipelineStep )
220248 step .Generation = 1
@@ -516,6 +544,47 @@ func TestUpgradePipelineStepReconciler(t *testing.T) {
516544 require .Equal (t , "2" , got .Annotations [processedGenerationAnnotation ])
517545 })
518546
547+ t .Run ("Clears stale readiness when drifted step update requeues" , func (t * testing.T ) {
548+ step := newObjectFromYAML [v1alpha1.UpgradePipelineStep ](t , yamlUpgradePipelineStep )
549+ step .Generation = 1
550+ autoValidationDelayDays := 3
551+ step .Spec .AutoValidationDelayDays = & autoValidationDelayDays
552+ step .Status .ID = "stale-step"
553+ metav1 .SetMetaDataAnnotation (& step .ObjectMeta , processedGenerationAnnotation , "1" )
554+ metav1 .SetMetaDataAnnotation (& step .ObjectMeta , instanceIsRunningAnnotation , "true" )
555+
556+ avn := avngen .NewMockClient (t )
557+ avn .EXPECT ().
558+ UpgradePipelineStepList (mock .Anything , step .Spec .OrganizationID , listQuery (step )).
559+ Return (& upgradepipeline.UpgradePipelineStepListOut {
560+ Steps : []upgradepipeline.StepOut {
561+ {
562+ AutoValidationDelayDays : 7 ,
563+ DestinationProjectName : step .Spec .DestinationProjectName ,
564+ DestinationServiceName : step .Spec .DestinationServiceName ,
565+ SourceProjectName : step .Spec .SourceProjectName ,
566+ SourceServiceName : step .Spec .SourceServiceName ,
567+ StepId : "step-update" ,
568+ },
569+ },
570+ }, nil ).Once ()
571+ avn .EXPECT ().
572+ UpgradePipelineStepUpdate (mock .Anything , step .Spec .OrganizationID , "step-update" , mock .Anything ).
573+ Return (nil , newAivenError (404 , "step not found" )).Once ()
574+
575+ r , res , err := runScenario (t , step , avn )
576+ require .NoError (t , err )
577+ require .Equal (t , ctrlruntime.Result {RequeueAfter : requeueTimeout }, res )
578+
579+ got := & v1alpha1.UpgradePipelineStep {}
580+ require .NoError (t , r .Get (t .Context (), types.NamespacedName {Name : step .Name , Namespace : step .Namespace }, got ))
581+ require .False (t , IsReadyToUse (got ))
582+ require .NotContains (t , got .Annotations , instanceIsRunningAnnotation )
583+ condition := meta .FindStatusCondition (got .Status .Conditions , conditionTypeRunning )
584+ require .NotNil (t , condition )
585+ require .Equal (t , metav1 .ConditionFalse , condition .Status )
586+ })
587+
519588 t .Run ("Creates upgrade pipeline step when stale status ID isn't found by spec" , func (t * testing.T ) {
520589 step := newObjectFromYAML [v1alpha1.UpgradePipelineStep ](t , yamlUpgradePipelineStep )
521590 step .Generation = 2
0 commit comments