@@ -26,16 +26,15 @@ import (
26
26
"github.com/containers/image/v5/docker/reference"
27
27
"github.com/samber/lo"
28
28
corev1 "k8s.io/api/core/v1"
29
+ "k8s.io/apimachinery/pkg/api/errors"
29
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
-
31
31
"k8s.io/apimachinery/pkg/runtime"
32
32
ctrl "sigs.k8s.io/controller-runtime"
33
33
"sigs.k8s.io/controller-runtime/pkg/client"
34
34
"sigs.k8s.io/controller-runtime/pkg/log"
35
35
36
- criruntime "github.com/baizeai/kube-snapshot/internal/controller/runtime"
37
-
38
36
snapshotpodv1alpha1 "github.com/baizeai/kube-snapshot/api/v1alpha1"
37
+ criruntime "github.com/baizeai/kube-snapshot/internal/controller/runtime"
39
38
)
40
39
41
40
const (
@@ -148,6 +147,9 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
148
147
spt := snapshotpodv1alpha1.SnapshotPodTask {}
149
148
err := r .Client .Get (ctx , req .NamespacedName , & spt )
150
149
if err != nil {
150
+ if errors .IsNotFound (err ) {
151
+ return ctrl.Result {}, nil
152
+ }
151
153
return ctrl.Result {}, err
152
154
}
153
155
if spt .Spec .NodeName != r .NodeName {
@@ -196,6 +198,10 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
196
198
logger .Error (err , "run reconcile task error" , "type" , rec .typ , "namespace" , spt .Namespace , "name" , spt .Name )
197
199
spt .Status .Conditions [i ].Status = metav1 .ConditionFalse
198
200
spt .Status .Conditions [i ].Message = err .Error ()
201
+ // Update status immediately after error
202
+ if updateErr := r .Status ().Update (ctx , & spt ); updateErr != nil {
203
+ return ctrl.Result {}, updateErr
204
+ }
199
205
break
200
206
} else {
201
207
spt .Status .Conditions [i ].Status = metav1 .ConditionTrue
@@ -205,7 +211,13 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
205
211
// update LastTransitionTime if condition changed.
206
212
spt .Status .Conditions [i ].LastTransitionTime = metav1 .Now ()
207
213
}
214
+ // Update status after each successful step
215
+ if updateErr := r .Status ().Update (ctx , & spt ); updateErr != nil {
216
+ return ctrl.Result {}, updateErr
217
+ }
208
218
}
219
+
220
+ // Update phase based on conditions
209
221
switch {
210
222
case lo .EveryBy (spt .Status .Conditions , func (item metav1.Condition ) bool {
211
223
return item .Status == metav1 .ConditionTrue
@@ -220,9 +232,11 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
220
232
spt .Status .Phase = snapshotpodv1alpha1 .SnapshotPodTaskPhaseCreated
221
233
}
222
234
235
+ // Final status update for phase change
223
236
if err := r .Status ().Update (ctx , & spt ); err != nil {
224
237
return ctrl.Result {}, err
225
238
}
239
+
226
240
switch spt .Status .Phase {
227
241
case snapshotpodv1alpha1 .SnapshotPodTaskPhaseFailed , snapshotpodv1alpha1 .SnapshotPodTaskPhaseCompleted :
228
242
return ctrl.Result {}, nil
0 commit comments