diff --git a/pkg/common-controller/snapshot_controller.go b/pkg/common-controller/snapshot_controller.go index 6faed3915..6dc5a0904 100644 --- a/pkg/common-controller/snapshot_controller.go +++ b/pkg/common-controller/snapshot_controller.go @@ -1205,7 +1205,10 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo } klog.V(5).Infof("updateSnapshotStatus: updating VolumeSnapshot [%+v] based on VolumeSnapshotContentStatus [%+v]", snapshot, content.Status) - + if content.Status != nil && snapshot != nil { + status := *content.Status + klog.V(5).Infof("VolumeSnapshotContentStatus for VolumeSnapshot [%+v] is: {SnapshotHandle: %s, ReadyToUse: %t, Error: %v}", snapshot.Name, *status.SnapshotHandle, *status.ReadyToUse, *status.Error) + } snapshotObj, err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshot.Namespace).Get(context.TODO(), snapshot.Name, metav1.GetOptions{}) if err != nil { return nil, fmt.Errorf("error get snapshot %s from api server: %v", utils.SnapshotKey(snapshot), err) @@ -1214,10 +1217,14 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo var newStatus *crdv1.VolumeSnapshotStatus updated := false if snapshotObj.Status == nil { + klog.V(5).Infof("Entered snapshotObj.Status == nil check for %s", snapshotObj.Name) + newStatus = &crdv1.VolumeSnapshotStatus{ BoundVolumeSnapshotContentName: &boundContentName, ReadyToUse: &readyToUse, } + klog.V(5).Infof("set newStatus for %s to have BoundVolumeSnapshotContentName: %s, and ReadyToUse: %t", snapshotObj.Name, boundContentName, readyToUse) + if createdAt != nil { newStatus.CreationTime = &metav1.Time{Time: *createdAt} } @@ -1225,6 +1232,7 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo newStatus.RestoreSize = resource.NewQuantity(*size, resource.BinarySI) } if volumeSnapshotErr != nil { + klog.V(5).Infof("set newStatus.Error for %s to %+v", snapshotObj.Name, *volumeSnapshotErr) newStatus.Error = volumeSnapshotErr } if groupSnapshotName != "" { @@ -1232,19 +1240,26 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo } updated = true } else { + klog.V(5).Infof("Entered else statement for %s", snapshotObj.Name) newStatus = snapshotObj.Status.DeepCopy() if newStatus.BoundVolumeSnapshotContentName == nil { + klog.V(5).Infof("newStatus.BoundVolumeSnapshotContentName == nil for %s", snapshotObj.Name) newStatus.BoundVolumeSnapshotContentName = &boundContentName updated = true } if newStatus.CreationTime == nil && createdAt != nil { + klog.V(5).Infof("newStatus.CreationTime == nil && createdAt != nil for %s", snapshotObj.Name) newStatus.CreationTime = &metav1.Time{Time: *createdAt} updated = true } if newStatus.ReadyToUse == nil || *newStatus.ReadyToUse != readyToUse { + klog.V(5).Infof("newStatus.ReadyToUse == nil : %t, for %s", newStatus.ReadyToUse == nil, snapshotObj.Name) + klog.V(5).Infof("*newStatus.ReadyToUse != readyToUse : %t, for %s", *newStatus.ReadyToUse != readyToUse, snapshotObj.Name) + newStatus.ReadyToUse = &readyToUse updated = true if readyToUse && newStatus.Error != nil { + klog.V(5).Infof("readyToUse && newStatus.Error != nil, for %s", snapshotObj.Name) newStatus.Error = nil } } @@ -1253,6 +1268,11 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo updated = true } if (newStatus.Error == nil && volumeSnapshotErr != nil) || (newStatus.Error != nil && volumeSnapshotErr != nil && newStatus.Error.Time != nil && volumeSnapshotErr.Time != nil && &newStatus.Error.Time != &volumeSnapshotErr.Time) || (newStatus.Error != nil && volumeSnapshotErr == nil) { + klog.V(5).Infof("entered long error statment for %s", snapshotObj.Name) + klog.V(5).Infof("newStatus.Error == nil && volumeSnapshotErr != nil : %t, for %s", newStatus.Error == nil && volumeSnapshotErr != nil, snapshotObj.Name) + klog.V(5).Infof("(newStatus.Error != nil && volumeSnapshotErr != nil && newStatus.Error.Time != nil && volumeSnapshotErr.Time != nil && &newStatus.Error.Time != &volumeSnapshotErr.Time) : %t, for %s", (newStatus.Error != nil && volumeSnapshotErr != nil && newStatus.Error.Time != nil && volumeSnapshotErr.Time != nil && &newStatus.Error.Time != &volumeSnapshotErr.Time), snapshotObj.Name) + klog.V(5).Infof("(newStatus.Error != nil && volumeSnapshotErr == nil) : %t, for %s", (newStatus.Error != nil && volumeSnapshotErr == nil), snapshotObj.Name) + newStatus.Error = volumeSnapshotErr updated = true } @@ -1262,7 +1282,11 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo } } + klog.V(5).Infof("Updated is %t for %s", updated, snapshotObj.Name) + if updated { + klog.V(5).Infof("Entered if updated for %s", snapshotObj.Name) + snapshotClone := snapshotObj.DeepCopy() snapshotClone.Status = newStatus @@ -1276,6 +1300,7 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo ctrl.metricsManager.RecordMetrics(createOperationKey, metrics.NewSnapshotOperationStatus(metrics.SnapshotStatusTypeSuccess), driverName) msg := fmt.Sprintf("Snapshot %s was successfully created by the CSI driver.", utils.SnapshotKey(snapshot)) ctrl.eventRecorder.Event(snapshot, v1.EventTypeNormal, "SnapshotCreated", msg) + klog.V(5).Infof("!utils.IsSnapshotCreated(snapshotObj) && utils.IsSnapshotCreated(snapshotClone) is %t for %s", !utils.IsSnapshotCreated(snapshotObj) && utils.IsSnapshotCreated(snapshotClone), snapshotObj.Name) } // Must meet the following criteria to emit a successful CreateSnapshotAndReady status @@ -1286,15 +1311,18 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotStatus(snapshot *crdv1.Vo ctrl.metricsManager.RecordMetrics(createAndReadyOperation, metrics.NewSnapshotOperationStatus(metrics.SnapshotStatusTypeSuccess), driverName) msg := fmt.Sprintf("Snapshot %s is ready to use.", utils.SnapshotKey(snapshot)) ctrl.eventRecorder.Event(snapshot, v1.EventTypeNormal, "SnapshotReady", msg) + klog.V(5).Infof("!utils.IsSnapshotReady(snapshotObj) && utils.IsSnapshotReady(snapshotClone) is %t for %s", !utils.IsSnapshotReady(snapshotObj) && utils.IsSnapshotReady(snapshotClone), snapshotObj.Name) + } newSnapshotObj, err := ctrl.clientset.SnapshotV1().VolumeSnapshots(snapshotClone.Namespace).UpdateStatus(context.TODO(), snapshotClone, metav1.UpdateOptions{}) if err != nil { return nil, newControllerUpdateError(utils.SnapshotKey(snapshot), err.Error()) } - + klog.V(5).Infof("returning newSnapshotObj %+v for %s", newSnapshotObj, snapshotObj.Name) return newSnapshotObj, nil } + klog.V(5).Infof("returning old snapshotObj %+v for %s", snapshotObj, snapshotObj.Name) return snapshotObj, nil }