Add volume snapshot ref details to group snapshot
This commit is contained in:
@@ -301,7 +301,8 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
|
|||||||
// 1) groupSnapshot.Status is nil
|
// 1) groupSnapshot.Status is nil
|
||||||
// 2) groupSnapshot.Status.ReadyToUse is false
|
// 2) groupSnapshot.Status.ReadyToUse is false
|
||||||
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
|
// 3) groupSnapshot.Status.IsBoundVolumeGroupSnapshotContentNameSet is not set
|
||||||
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) {
|
// 4) groupSnapshot.Status.IsVolumeSnapshotRefListSet is not set
|
||||||
|
if !utils.IsGroupSnapshotReady(groupSnapshot) || !utils.IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot) || !utils.IsVolumeSnapshotRefListSet(groupSnapshot) {
|
||||||
return ctrl.syncUnreadyGroupSnapshot(groupSnapshot)
|
return ctrl.syncUnreadyGroupSnapshot(groupSnapshot)
|
||||||
}
|
}
|
||||||
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
|
return ctrl.syncReadyGroupSnapshot(groupSnapshot)
|
||||||
@@ -368,13 +369,13 @@ func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(groupSnapshot
|
|||||||
|
|
||||||
// Pre-provisioned snapshot
|
// Pre-provisioned snapshot
|
||||||
if groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName != nil {
|
if groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName != nil {
|
||||||
content, err := ctrl.getPreprovisionedGroupSnapshotContentFromStore(groupSnapshot)
|
groupSnapshotContent, err := ctrl.getPreprovisionedGroupSnapshotContentFromStore(groupSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no content found yet, update status and return
|
// if no group snapshot content found yet, update status and return
|
||||||
if content == nil {
|
if groupSnapshotContent == nil {
|
||||||
// can not find the desired VolumeSnapshotContent from cache store
|
// can not find the desired VolumeSnapshotContent from cache store
|
||||||
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotContentMissing", "VolumeGroupSnapshotContent is missing")
|
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotContentMissing", "VolumeGroupSnapshotContent is missing")
|
||||||
klog.V(4).Infof("syncUnreadyGroupSnapshot[%s]: group snapshot content %q requested but not found, will try again", utils.GroupSnapshotKey(groupSnapshot), *groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName)
|
klog.V(4).Infof("syncUnreadyGroupSnapshot[%s]: group snapshot content %q requested but not found, will try again", utils.GroupSnapshotKey(groupSnapshot), *groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName)
|
||||||
@@ -383,16 +384,16 @@ func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(groupSnapshot
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set VolumeGroupSnapshotRef UID
|
// Set VolumeGroupSnapshotRef UID
|
||||||
newContent, err := ctrl.checkAndBindGroupSnapshotContent(groupSnapshot, content)
|
newGroupSnapshotContent, err := ctrl.checkAndBindGroupSnapshotContent(groupSnapshot, groupSnapshotContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// group snapshot is bound but content is not bound to group snapshot correctly
|
// group snapshot is bound but content is not bound to group snapshot correctly
|
||||||
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotBindFailed", fmt.Sprintf("GroupSnapshot failed to bind VolumeGroupSnapshotContent, %v", err))
|
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotBindFailed", fmt.Sprintf("GroupSnapshot failed to bind VolumeGroupSnapshotContent, %v", err))
|
||||||
return fmt.Errorf("group snapshot %s is bound, but VolumeGroupSnapshotContent %s is not bound to the VolumeGroupSnapshot correctly, %v", uniqueGroupSnapshotName, content.Name, err)
|
return fmt.Errorf("group snapshot %s is bound, but VolumeGroupSnapshotContent %s is not bound to the VolumeGroupSnapshot correctly, %v", uniqueGroupSnapshotName, groupSnapshotContent.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update group snapshot status
|
// update group snapshot status
|
||||||
klog.V(5).Infof("syncUnreadyGroupSnapshot [%s]: trying to update group snapshot status", utils.GroupSnapshotKey(groupSnapshot))
|
klog.V(5).Infof("syncUnreadyGroupSnapshot [%s]: trying to update group snapshot status", utils.GroupSnapshotKey(groupSnapshot))
|
||||||
if _, err = ctrl.updateGroupSnapshotStatus(groupSnapshot, newContent); err != nil {
|
if _, err = ctrl.updateGroupSnapshotStatus(groupSnapshot, newGroupSnapshotContent); err != nil {
|
||||||
// update group snapshot status failed
|
// update group snapshot status failed
|
||||||
klog.V(4).Infof("failed to update group snapshot %s status: %v", utils.GroupSnapshotKey(groupSnapshot), err)
|
klog.V(4).Infof("failed to update group snapshot %s status: %v", utils.GroupSnapshotKey(groupSnapshot), err)
|
||||||
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, false, v1.EventTypeWarning, "GroupSnapshotStatusUpdateFailed", fmt.Sprintf("GroupSnapshot status update failed, %v", err))
|
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, false, v1.EventTypeWarning, "GroupSnapshotStatusUpdateFailed", fmt.Sprintf("GroupSnapshot status update failed, %v", err))
|
||||||
@@ -416,6 +417,7 @@ func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(groupSnapshot
|
|||||||
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotHandleSet", fmt.Sprintf("GroupSnapshot handle should not be set in content %s for dynamic provisioning", uniqueGroupSnapshotName))
|
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotHandleSet", fmt.Sprintf("GroupSnapshot handle should not be set in content %s for dynamic provisioning", uniqueGroupSnapshotName))
|
||||||
return fmt.Errorf("VolumeGroupSnapshotHandle should not be set in the content for dynamic provisioning for group snapshot %s", uniqueGroupSnapshotName)
|
return fmt.Errorf("VolumeGroupSnapshotHandle should not be set in the content for dynamic provisioning for group snapshot %s", uniqueGroupSnapshotName)
|
||||||
}
|
}
|
||||||
|
|
||||||
newGroupSnapshot, err := ctrl.bindandUpdateVolumeGroupSnapshot(contentObj, groupSnapshot)
|
newGroupSnapshot, err := ctrl.bindandUpdateVolumeGroupSnapshot(contentObj, groupSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.V(4).Infof("bindandUpdateVolumeGroupSnapshot[%s]: failed to bind content [%s] to group snapshot %v", uniqueGroupSnapshotName, contentObj.Name, err)
|
klog.V(4).Infof("bindandUpdateVolumeGroupSnapshot[%s]: failed to bind content [%s] to group snapshot %v", uniqueGroupSnapshotName, contentObj.Name, err)
|
||||||
@@ -531,25 +533,36 @@ func (ctrl *csiSnapshotCommonController) checkAndBindGroupSnapshotContent(groupS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateGroupSnapshotStatus updates group snapshot status based on group content status
|
// updateGroupSnapshotStatus updates group snapshot status based on group content status
|
||||||
func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot, content *crdv1alpha1.VolumeGroupSnapshotContent) (*crdv1alpha1.VolumeGroupSnapshot, error) {
|
func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot, groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent) (*crdv1alpha1.VolumeGroupSnapshot, error) {
|
||||||
klog.V(5).Infof("updateGroupSnapshotStatus[%s]", utils.GroupSnapshotKey(groupSnapshot))
|
klog.V(5).Infof("updateGroupSnapshotStatus[%s]", utils.GroupSnapshotKey(groupSnapshot))
|
||||||
|
|
||||||
boundContentName := content.Name
|
boundContentName := groupSnapshotContent.Name
|
||||||
var createdAt *time.Time
|
var createdAt *time.Time
|
||||||
if content.Status != nil && content.Status.CreationTime != nil {
|
if groupSnapshotContent.Status != nil && groupSnapshotContent.Status.CreationTime != nil {
|
||||||
unixTime := time.Unix(0, *content.Status.CreationTime)
|
unixTime := time.Unix(0, *groupSnapshotContent.Status.CreationTime)
|
||||||
createdAt = &unixTime
|
createdAt = &unixTime
|
||||||
}
|
}
|
||||||
var readyToUse bool
|
var readyToUse bool
|
||||||
if content.Status != nil && content.Status.ReadyToUse != nil {
|
if groupSnapshotContent.Status != nil && groupSnapshotContent.Status.ReadyToUse != nil {
|
||||||
readyToUse = *content.Status.ReadyToUse
|
readyToUse = *groupSnapshotContent.Status.ReadyToUse
|
||||||
}
|
}
|
||||||
var volumeSnapshotErr *crdv1.VolumeSnapshotError
|
var volumeSnapshotErr *crdv1.VolumeSnapshotError
|
||||||
if content.Status != nil && content.Status.Error != nil {
|
if groupSnapshotContent.Status != nil && groupSnapshotContent.Status.Error != nil {
|
||||||
volumeSnapshotErr = content.Status.Error.DeepCopy()
|
volumeSnapshotErr = groupSnapshotContent.Status.Error.DeepCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(5).Infof("updateGroupSnapshotStatus: updating VolumeGroupSnapshot [%+v] based on VolumeGroupSnapshotContentStatus [%+v]", groupSnapshot, content.Status)
|
var volumeSnapshotRefList []v1.ObjectReference
|
||||||
|
if groupSnapshotContent.Status != nil && len(groupSnapshotContent.Status.VolumeSnapshotContentRefList) != 0 {
|
||||||
|
for _, contentRef := range groupSnapshotContent.Status.VolumeSnapshotContentRefList {
|
||||||
|
content, err := ctrl.contentLister.Get(contentRef.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get content %s from content store: %v", contentRef.Name, err)
|
||||||
|
}
|
||||||
|
volumeSnapshotRefList = append(volumeSnapshotRefList, content.Spec.VolumeSnapshotRef)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
klog.V(5).Infof("updateGroupSnapshotStatus: updating VolumeGroupSnapshot [%+v] based on VolumeGroupSnapshotContentStatus [%+v]", groupSnapshot, groupSnapshotContent.Status)
|
||||||
|
|
||||||
groupSnapshotObj, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshots(groupSnapshot.Namespace).Get(context.TODO(), groupSnapshot.Name, metav1.GetOptions{})
|
groupSnapshotObj, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshots(groupSnapshot.Namespace).Get(context.TODO(), groupSnapshot.Name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -569,7 +582,9 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
|
|||||||
if volumeSnapshotErr != nil {
|
if volumeSnapshotErr != nil {
|
||||||
newStatus.Error = volumeSnapshotErr
|
newStatus.Error = volumeSnapshotErr
|
||||||
}
|
}
|
||||||
// TODO: Add ref details
|
if len(volumeSnapshotRefList) == 0 {
|
||||||
|
newStatus.VolumeSnapshotRefList = volumeSnapshotRefList
|
||||||
|
}
|
||||||
|
|
||||||
updated = true
|
updated = true
|
||||||
} else {
|
} else {
|
||||||
@@ -593,6 +608,10 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
|
|||||||
newStatus.Error = volumeSnapshotErr
|
newStatus.Error = volumeSnapshotErr
|
||||||
updated = true
|
updated = true
|
||||||
}
|
}
|
||||||
|
if len(newStatus.VolumeSnapshotRefList) == 0 {
|
||||||
|
newStatus.VolumeSnapshotRefList = volumeSnapshotRefList
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated {
|
if updated {
|
||||||
|
@@ -517,6 +517,13 @@ func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1alpha1.VolumeG
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool {
|
||||||
|
if groupSnapshot.Status == nil || len(groupSnapshot.Status.VolumeSnapshotRefList) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func IsVolumeGroupSnapshotRefSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot, content *crdv1alpha1.VolumeGroupSnapshotContent) bool {
|
func IsVolumeGroupSnapshotRefSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot, content *crdv1alpha1.VolumeGroupSnapshotContent) bool {
|
||||||
if content.Spec.VolumeGroupSnapshotRef.Name == groupSnapshot.Name &&
|
if content.Spec.VolumeGroupSnapshotRef.Name == groupSnapshot.Name &&
|
||||||
content.Spec.VolumeGroupSnapshotRef.Namespace == groupSnapshot.Namespace &&
|
content.Spec.VolumeGroupSnapshotRef.Namespace == groupSnapshot.Namespace &&
|
||||||
|
Reference in New Issue
Block a user