Skip to content

Commit dfcfd25

Browse files
committed
chore(module):dvcr gc provisioners waiting timeout
- Cancel garbage collection if wait for provisioners more than 2 hours. Signed-off-by: Ivan Mikheykin <[email protected]>
1 parent 2c3ed4e commit dfcfd25

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

images/virtualization-artifact/pkg/controller/dvcr-garbage-collection/internal/life_cycle.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

images/virtualization-artifact/pkg/controller/dvcr-garbage-collection/types/const.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ limitations under the License.
1616

1717
package types
1818

19-
import "k8s.io/apimachinery/pkg/types"
19+
import (
20+
"time"
21+
22+
"k8s.io/apimachinery/pkg/types"
23+
)
2024

2125
const (
2226
ModuleNamespace = "d8-virtualization"
@@ -25,6 +29,8 @@ const (
2529
DVCRGarbageCollectionSecretName = "dvcr-garbage-collection"
2630
CronSourceNamespace = "__cron_source__"
2731
CronSourceRunGC = "run-gc"
32+
33+
WaitProvisionersTimeout = time.Hour * 2
2834
)
2935

3036
func DVCRDeploymentKey() types.NamespacedName {

0 commit comments

Comments
 (0)