Skip to content

Commit c368b21

Browse files
committed
fix: avoid removing finalizers on configmap in snapshot processing when configmap is already deleted
Make qosClass immmutable in podSyncer
1 parent cc00c9d commit c368b21

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

pkg/controllers/resources/pods/syncer.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,18 @@ func (s *podSyncer) Sync(ctx *synccontext.SyncContext, event *synccontext.SyncEv
377377
// NewSyncerPatcher() is called so that there are no
378378
// differences found in host QOSClass and virtual QOSClass and
379379
// a patch event for this field is not created
380-
event.Host.Status.QOSClass = event.VirtualOld.Status.QOSClass
380+
virtualQOS := event.Virtual.Status.QOSClass
381+
if event.VirtualOld != nil {
382+
virtualQOS = event.VirtualOld.Status.QOSClass
383+
}
384+
// Set both Host and Virtual to the same QOSClass value to prevent patching
385+
event.Host.Status.QOSClass = virtualQOS
381386
if event.HostOld != nil {
382-
event.Virtual.Status.QOSClass = event.HostOld.Status.QOSClass
387+
event.HostOld.Status.QOSClass = virtualQOS
388+
}
389+
event.Virtual.Status.QOSClass = virtualQOS
390+
if event.VirtualOld != nil {
391+
event.VirtualOld.Status.QOSClass = virtualQOS
383392
}
384393

385394
// patch objects

pkg/snapshot/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ func (c *Reconciler) updateRequest(ctx context.Context, previousConfigMapState c
475475
// patch snapshot request ConfigMap
476476
err = c.client().Patch(ctx, configMap, previousConfigMapState)
477477
if err != nil {
478+
if kerrors.IsNotFound(err) {
479+
// request was deleted while reconciling; nothing to update
480+
c.logger.Infof("Snapshot request configMap %s/%s not found", configMap.Namespace, configMap.Name)
481+
return nil
482+
}
478483
return fmt.Errorf("failed to patch snapshot request ConfigMap %s/%s: %w", configMap.Namespace, configMap.Name, err)
479484
}
480485
c.logger.Debugf("Patched snapshot request %s/%s", configMap.Namespace, configMap.Name)

pkg/snapshot/controllerbase.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func (c *reconcilerBase) removeFinalizer(ctx context.Context, configMap *corev1.
108108
// patch the object
109109
err := c.client().Patch(ctx, configMap, oldConfigMap)
110110
if err != nil {
111+
if kerrors.IsNotFound(err) {
112+
// request was deleted while reconciling; nothing to update
113+
c.logger.Infof("failed to remove finalizer, configMap %s/%s not found", configMap.Namespace, configMap.Name)
114+
return nil
115+
}
111116
return fmt.Errorf("failed to patch %s request ConfigMap %s/%s finalizers: %w", c.kind, configMap.Namespace, configMap.Name, err)
112117
}
113118

pkg/snapshot/volumes/csi/snapshothandler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,13 @@ func (h *snapshotHandler) deleteVolumeSnapshotResources(
255255
h.logger.Debugf("Delete VolumeSnapshot %s/%s", volumeSnapshot.Namespace, volumeSnapshot.Name)
256256
err := h.snapshotsClient.SnapshotV1().VolumeSnapshots(volumeSnapshot.Namespace).Delete(ctx, volumeSnapshot.Name, metav1.DeleteOptions{})
257257
if err != nil && !kerrors.IsNotFound(err) {
258-
return fmt.Errorf("failed to delete VolumeSnapshot %s/%s: %w", volumeSnapshot.Namespace, volumeSnapshot.Name, err)
258+
// If the error is a conflict (e.g., controller is adding finalizers),
259+
// it means the snapshot is being processed
260+
if kerrors.IsConflict(err) {
261+
h.logger.Debugf("VolumeSnapshot %s/%s deletion conflicted (likely being processed by controller), will retry", volumeSnapshot.Namespace, volumeSnapshot.Name)
262+
} else {
263+
return fmt.Errorf("failed to delete VolumeSnapshot %s/%s: %w", volumeSnapshot.Namespace, volumeSnapshot.Name, err)
264+
}
259265
}
260266
}
261267
if volumeSnapshotContent != nil &&

0 commit comments

Comments
 (0)