@@ -25,9 +25,10 @@ import (
2525 "sigs.k8s.io/controller-runtime/pkg/client"
2626 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2727
28+ "github.com/deckhouse/virtualization-controller/pkg/common/annotations"
2829 dvcrcondition "github.com/deckhouse/virtualization-controller/pkg/controller/dvcr-garbage-collection/condition"
2930 dvcrtypes "github.com/deckhouse/virtualization-controller/pkg/controller/dvcr-garbage-collection/types"
30- dvcr_deployment_condition "github.com/deckhouse/virtualization/api/core/v1alpha2/dvcr-deployment-condition"
31+ dvcrdeploymentcondition "github.com/deckhouse/virtualization/api/core/v1alpha2/dvcr-deployment-condition"
3132)
3233
3334type LifeCycleHandler struct {
@@ -51,7 +52,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, req reconcile.Request, dep
5152
5253 if req .Namespace == dvcrtypes .CronSourceNamespace && req .Name == dvcrtypes .CronSourceRunGC {
5354 dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
54- dvcr_deployment_condition .InProgress ,
55+ dvcrdeploymentcondition .InProgress ,
5556 "Garbage collection initiated." ,
5657 )
5758 return reconcile.Result {}, h .dvcrService .InitiateGarbageCollectionMode (ctx )
@@ -78,16 +79,21 @@ func (h LifeCycleHandler) Handle(ctx context.Context, req reconcile.Request, dep
7879 }
7980
8081 if h .dvcrService .IsGarbageCollectionDone (secret ) {
81- dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
82- dvcr_deployment_condition .Done ,
83- "%s" , string (secret .Data ["result" ]),
84- )
82+ // Extract error or success message from the result.
83+ reason , msg , err := h .dvcrService .ParseGarbageCollectionResult (secret )
84+ if err != nil {
85+ return reconcile.Result {}, err
86+ }
87+ dvcrcondition .UpdateGarbageCollectionCondition (deploy , reason , "%s" , msg )
88+ // Put full result JSON into annotation on deployment.
89+ annotations .AddAnnotation (deploy , annotations .AnnDVCRGarbageCollectionResult , h .dvcrService .GetGarbageCollectionResult (secret ))
90+ // It is now possible to delete a secret.
8591 return reconcile.Result {}, h .dvcrService .DeleteGarbageCollectionSecret (ctx )
8692 }
8793
8894 if h .dvcrService .IsGarbageCollectionStarted (secret ) {
8995 dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
90- dvcr_deployment_condition .InProgress ,
96+ dvcrdeploymentcondition .InProgress ,
9197 "Wait for garbage collection to finish." ,
9298 )
9399 // Wait for done annotation.
@@ -102,7 +108,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, req reconcile.Request, dep
102108 remainInProvisioning := len (resourcesInProvisioning )
103109 if remainInProvisioning > 0 {
104110 dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
105- dvcr_deployment_condition .InProgress ,
111+ dvcrdeploymentcondition .InProgress ,
106112 "Wait for cvi/vi/vd finish provisioning: %d resources remain." , remainInProvisioning ,
107113 )
108114 return reconcile.Result {RequeueAfter : time .Second * 20 }, nil
@@ -113,7 +119,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, req reconcile.Request, dep
113119 return reconcile.Result {}, fmt .Errorf ("switch to garbage collection mode: %w" , err )
114120 }
115121 dvcrcondition .UpdateGarbageCollectionCondition (deploy ,
116- dvcr_deployment_condition .InProgress ,
122+ dvcrdeploymentcondition .InProgress ,
117123 "Wait for garbage collection to finish." ,
118124 )
119125 return reconcile.Result {}, nil
0 commit comments