Add reference details to volume group snapshot content status
This commit is contained in:
@@ -425,7 +425,7 @@ func (ctrl *csiSnapshotCommonController) syncUnreadyGroupSnapshot(groupSnapshot
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach here, it is a dynamically provisioned group snapshot, and the volumeGroupSnapshotContent object is not yet created.
|
// If we reach here, it is a dynamically provisioned group snapshot, and the VolumeGroupSnapshotContent object is not yet created.
|
||||||
var content *crdv1alpha1.VolumeGroupSnapshotContent
|
var content *crdv1alpha1.VolumeGroupSnapshotContent
|
||||||
if content, err = ctrl.createGroupSnapshotContent(groupSnapshot); err != nil {
|
if content, err = ctrl.createGroupSnapshotContent(groupSnapshot); err != nil {
|
||||||
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotContentCreationFailed", fmt.Sprintf("failed to create group snapshot content with error %v", err))
|
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotContentCreationFailed", fmt.Sprintf("failed to create group snapshot content with error %v", err))
|
||||||
@@ -569,6 +569,8 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot
|
|||||||
if volumeSnapshotErr != nil {
|
if volumeSnapshotErr != nil {
|
||||||
newStatus.Error = volumeSnapshotErr
|
newStatus.Error = volumeSnapshotErr
|
||||||
}
|
}
|
||||||
|
// TODO: Add ref details
|
||||||
|
|
||||||
updated = true
|
updated = true
|
||||||
} else {
|
} else {
|
||||||
newStatus = groupSnapshotObj.Status.DeepCopy()
|
newStatus = groupSnapshotObj.Status.DeepCopy()
|
||||||
|
@@ -571,6 +571,8 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
|
|||||||
60*time.Second,
|
60*time.Second,
|
||||||
"snapshot",
|
"snapshot",
|
||||||
-1,
|
-1,
|
||||||
|
"groupsnapshot",
|
||||||
|
-1,
|
||||||
true,
|
true,
|
||||||
workqueue.NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Minute),
|
workqueue.NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Minute),
|
||||||
false,
|
false,
|
||||||
|
@@ -258,6 +258,7 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create individual snapshots and snapshot contents
|
// Create individual snapshots and snapshot contents
|
||||||
|
var snapshotContentNames []string
|
||||||
for _, snapshot := range snapshots {
|
for _, snapshot := range snapshots {
|
||||||
volumeSnapshotContentName := GetSnapshotContentNameForVolumeGroupSnapshotContent(groupSnapshotContent)
|
volumeSnapshotContentName := GetSnapshotContentNameForVolumeGroupSnapshotContent(groupSnapshotContent)
|
||||||
volumeSnapshotName := GetSnapshotNameForVolumeGroupSnapshotContent(groupSnapshotContent)
|
volumeSnapshotName := GetSnapshotNameForVolumeGroupSnapshotContent(groupSnapshotContent)
|
||||||
@@ -280,12 +281,17 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
|
|||||||
// TODO: Populate this field when volume mode conversion is enabled by default
|
// TODO: Populate this field when volume mode conversion is enabled by default
|
||||||
SourceVolumeMode: nil,
|
SourceVolumeMode: nil,
|
||||||
},
|
},
|
||||||
|
Status: &crdv1.VolumeSnapshotContentStatus{
|
||||||
|
VolumeGroupSnapshotContentName: &groupSnapshotContent.Name,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
label := make(map[string]string)
|
||||||
|
label["volumeGroupSnapshotName"] = groupSnapshotContent.Spec.VolumeGroupSnapshotRef.Name
|
||||||
volumeSnapshot := &crdv1.VolumeSnapshot{
|
volumeSnapshot := &crdv1.VolumeSnapshot{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: volumeSnapshotName,
|
Name: volumeSnapshotName,
|
||||||
Namespace: volumeSnapshotNamespace,
|
Namespace: volumeSnapshotNamespace,
|
||||||
|
Labels: label,
|
||||||
},
|
},
|
||||||
Spec: crdv1.VolumeSnapshotSpec{
|
Spec: crdv1.VolumeSnapshotSpec{
|
||||||
Source: crdv1.VolumeSnapshotSource{
|
Source: crdv1.VolumeSnapshotSource{
|
||||||
@@ -293,10 +299,11 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Create(context.TODO(), volumeSnapshotContent, metav1.CreateOptions{})
|
vsc, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Create(context.TODO(), volumeSnapshotContent, metav1.CreateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return groupSnapshotContent, err
|
return groupSnapshotContent, err
|
||||||
}
|
}
|
||||||
|
snapshotContentNames = append(snapshotContentNames, vsc.Name)
|
||||||
|
|
||||||
_, err = ctrl.clientset.SnapshotV1().VolumeSnapshots(volumeSnapshotNamespace).Create(context.TODO(), volumeSnapshot, metav1.CreateOptions{})
|
_, err = ctrl.clientset.SnapshotV1().VolumeSnapshots(volumeSnapshotNamespace).Create(context.TODO(), volumeSnapshot, metav1.CreateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -304,7 +311,7 @@ func (ctrl *csiSnapshotSideCarController) createGroupSnapshotWrapper(groupSnapsh
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
newGroupSnapshotContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano())
|
newGroupSnapshotContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano(), snapshotContentNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("error updating status for volume group snapshot content %s: %v.", groupSnapshotContent.Name, err)
|
klog.Errorf("error updating status for volume group snapshot content %s: %v.", groupSnapshotContent.Name, err)
|
||||||
return groupSnapshotContent, fmt.Errorf("error updating status for volume group snapshot content %s: %v", groupSnapshotContent.Name, err)
|
return groupSnapshotContent, fmt.Errorf("error updating status for volume group snapshot content %s: %v", groupSnapshotContent.Name, err)
|
||||||
@@ -444,7 +451,8 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
|
|||||||
groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent,
|
groupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent,
|
||||||
groupSnapshotHandle string,
|
groupSnapshotHandle string,
|
||||||
readyToUse bool,
|
readyToUse bool,
|
||||||
createdAt int64) (*crdv1alpha1.VolumeGroupSnapshotContent, error) {
|
createdAt int64,
|
||||||
|
snapshotContentNames []string) (*crdv1alpha1.VolumeGroupSnapshotContent, error) {
|
||||||
klog.V(5).Infof("updateSnapshotContentStatus: updating VolumeGroupSnapshotContent [%s], groupSnapshotHandle %s, readyToUse %v, createdAt %v", groupSnapshotContent.Name, groupSnapshotHandle, readyToUse, createdAt)
|
klog.V(5).Infof("updateSnapshotContentStatus: updating VolumeGroupSnapshotContent [%s], groupSnapshotHandle %s, readyToUse %v, createdAt %v", groupSnapshotContent.Name, groupSnapshotHandle, readyToUse, createdAt)
|
||||||
|
|
||||||
groupSnapshotContentObj, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshotContents().Get(context.TODO(), groupSnapshotContent.Name, metav1.GetOptions{})
|
groupSnapshotContentObj, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshotContents().Get(context.TODO(), groupSnapshotContent.Name, metav1.GetOptions{})
|
||||||
@@ -460,6 +468,12 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
|
|||||||
ReadyToUse: &readyToUse,
|
ReadyToUse: &readyToUse,
|
||||||
CreationTime: &createdAt,
|
CreationTime: &createdAt,
|
||||||
}
|
}
|
||||||
|
for _, name := range snapshotContentNames {
|
||||||
|
newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{
|
||||||
|
Kind: "VolumeSnapshotContent",
|
||||||
|
Name: name,
|
||||||
|
})
|
||||||
|
}
|
||||||
updated = true
|
updated = true
|
||||||
} else {
|
} else {
|
||||||
newStatus = groupSnapshotContentObj.Status.DeepCopy()
|
newStatus = groupSnapshotContentObj.Status.DeepCopy()
|
||||||
@@ -478,6 +492,15 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
|
|||||||
newStatus.CreationTime = &createdAt
|
newStatus.CreationTime = &createdAt
|
||||||
updated = true
|
updated = true
|
||||||
}
|
}
|
||||||
|
if len(newStatus.VolumeSnapshotContentRefList) == 0 {
|
||||||
|
for _, name := range snapshotContentNames {
|
||||||
|
newStatus.VolumeSnapshotContentRefList = append(newStatus.VolumeSnapshotContentRefList, v1.ObjectReference{
|
||||||
|
Kind: "VolumeSnapshotContent",
|
||||||
|
Name: name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated {
|
if updated {
|
||||||
@@ -597,7 +620,7 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateGroupSnapshotContentStat
|
|||||||
var snapshotterListCredentials map[string]string
|
var snapshotterListCredentials map[string]string
|
||||||
|
|
||||||
if groupSnapshotContent.Spec.Source.VolumeGroupSnapshotHandle != nil {
|
if groupSnapshotContent.Spec.Source.VolumeGroupSnapshotHandle != nil {
|
||||||
klog.V(5).Infof("checkandUpdateGroupSnapshotContentStatusOperation: call GetGroupSnapshotStatus for group snapshot which is pre-bound to groupSnapshotContent [%s]", groupSnapshotContent.Name)
|
klog.V(5).Infof("checkandUpdateGroupSnapshotContentStatusOperation: call GetGroupSnapshotStatus for group snapshot which is pre-bound to group snapshot content [%s]", groupSnapshotContent.Name)
|
||||||
|
|
||||||
if groupSnapshotContent.Spec.VolumeGroupSnapshotClassName != nil {
|
if groupSnapshotContent.Spec.VolumeGroupSnapshotClassName != nil {
|
||||||
class, err := ctrl.getGroupSnapshotClass(*groupSnapshotContent.Spec.VolumeGroupSnapshotClassName)
|
class, err := ctrl.getGroupSnapshotClass(*groupSnapshotContent.Spec.VolumeGroupSnapshotClassName)
|
||||||
@@ -634,7 +657,8 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateGroupSnapshotContentStat
|
|||||||
creationTime = time.Now()
|
creationTime = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano())
|
// TODO: Get a reference to snapshot contents for this volume group snapshot
|
||||||
|
updatedContent, err := ctrl.updateGroupSnapshotContentStatus(groupSnapshotContent, groupSnapshotID, readyToUse, creationTime.UnixNano(), []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return groupSnapshotContent, err
|
return groupSnapshotContent, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user