@@ -106,23 +106,40 @@ func (h LifeCycleHandler) Handle(ctx context.Context, req reconcile.Request, dep
106106 return reconcile.Result {}, fmt .Errorf ("list resources in provisioning: %w" , err )
107107 }
108108 remainInProvisioning := len (resourcesInProvisioning )
109- if remainInProvisioning > 0 {
109+ if remainInProvisioning == 0 {
110+ // All provisioners are finished, switch DVCR to garbage collection.
111+ err = h .dvcrService .SwitchToGarbageCollectionMode (ctx )
112+ if err != nil {
113+ return reconcile.Result {}, fmt .Errorf ("switch to garbage collection mode: %w" , err )
114+ }
110115 dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
111116 dvcrdeploymentcondition .InProgress ,
112- "Wait for cvi/vi/vd finish provisioning: %d resources remain." , remainInProvisioning ,
117+ "Wait for garbage collection to finish." ,
113118 )
114- return reconcile.Result {RequeueAfter : time . Second * 20 }, nil
119+ return reconcile.Result {}, nil
115120 }
116- // All provisioners are finished, switch to garbage collection.
117- err = h .dvcrService .SwitchToGarbageCollectionMode (ctx )
118- if err != nil {
119- return reconcile.Result {}, fmt .Errorf ("switch to garbage collection mode: %w" , err )
121+
122+ // Cancel garbage collection if wait for provisioners for too long.
123+ hasCreationTimestamp := ! secret .GetCreationTimestamp ().Time .IsZero ()
124+ waitDuration := time .Since (secret .GetCreationTimestamp ().Time )
125+ if hasCreationTimestamp && waitDuration > dvcrtypes .WaitProvisionersTimeout {
126+ // Wait for provisionerStop garbage collection and report error.
127+ dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
128+ dvcrdeploymentcondition .Error ,
129+ "Wait for resources provisioners more than %s timeout: %s elapsed, garbage collection canceled" ,
130+ dvcrtypes .WaitProvisionersTimeout .String (),
131+ waitDuration .String (),
132+ )
133+ annotations .AddAnnotation (deploy , annotations .AnnDVCRGarbageCollectionResult , "" )
134+ return reconcile.Result {}, h .dvcrService .DeleteGarbageCollectionSecret (ctx )
120135 }
136+
137+ // Use requeue to wait for provisioners to finish.
121138 dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
122139 dvcrdeploymentcondition .InProgress ,
123- "Wait for garbage collection to finish." ,
140+ "Wait for cvi/vi/vd finish provisioning: %d resources remain." , remainInProvisioning ,
124141 )
125- return reconcile.Result {}, nil
142+ return reconcile.Result {RequeueAfter : time . Second * 20 }, nil
126143 }
127144
128145 return reconcile.Result {}, nil
0 commit comments