@@ -504,6 +504,12 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
504
504
return groupSnapshotContent , nil
505
505
}
506
506
507
+ // No volume group snapshot handle is present.
508
+ // Let's wait for the snapshotter sidecar to fill it.
509
+ if groupSnapshotContent .Status .VolumeGroupSnapshotHandle == nil {
510
+ return groupSnapshotContent , nil
511
+ }
512
+
507
513
// The contents of the volume group snapshot class are needed to set the
508
514
// metadata containing the secrets to recover the snapshots
509
515
if groupSnapshot .Spec .VolumeGroupSnapshotClassName == nil {
@@ -557,6 +563,9 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
557
563
volumeSnapshotContent := & crdv1.VolumeSnapshotContent {
558
564
ObjectMeta : metav1.ObjectMeta {
559
565
Name : volumeSnapshotContentName ,
566
+ Labels : map [string ]string {
567
+ utils .VolumeGroupSnapshotHandleLabel : * groupSnapshotContent .Status .VolumeGroupSnapshotHandle ,
568
+ },
560
569
},
561
570
Spec : crdv1.VolumeSnapshotContentSpec {
562
571
VolumeSnapshotRef : v1.ObjectReference {
@@ -567,7 +576,7 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
567
576
DeletionPolicy : groupSnapshotContent .Spec .DeletionPolicy ,
568
577
Driver : groupSnapshotContent .Spec .Driver ,
569
578
Source : crdv1.VolumeSnapshotContentSource {
570
- SnapshotHandle : & snapshotHandle ,
579
+ VolumeHandle : & volumeHandle ,
571
580
},
572
581
},
573
582
// The status will be set by VolumeSnapshotContent reconciler
@@ -586,24 +595,28 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
586
595
metav1 .SetMetaDataAnnotation (& volumeSnapshotContent .ObjectMeta , utils .AnnDeletionSecretRefNamespace , groupSnapshotSecret .Namespace )
587
596
}
588
597
589
- label := make (map [string ]string )
590
- label [utils .VolumeGroupSnapshotNameLabel ] = groupSnapshotContent .Spec .VolumeGroupSnapshotRef .Name
591
598
volumeSnapshot := & crdv1.VolumeSnapshot {
592
599
ObjectMeta : metav1.ObjectMeta {
593
- Name : volumeSnapshotName ,
594
- Namespace : volumeSnapshotNamespace ,
595
- Labels : label ,
596
- Finalizers : []string {utils .VolumeSnapshotInGroupFinalizer },
597
- },
598
- Spec : crdv1.VolumeSnapshotSpec {
599
- Source : crdv1.VolumeSnapshotSource {
600
- PersistentVolumeClaimName : & pv .Spec .ClaimRef .Name ,
600
+ Name : volumeSnapshotName ,
601
+ Namespace : volumeSnapshotNamespace ,
602
+ Labels : map [string ]string {
603
+ utils .VolumeGroupSnapshotNameLabel : groupSnapshotContent .Spec .VolumeGroupSnapshotRef .Name ,
601
604
},
605
+ Finalizers : []string {utils .VolumeSnapshotInGroupFinalizer },
602
606
},
607
+ // The spec stanza is set immediately
603
608
// The status will be set by VolumeSnapshot reconciler
604
609
}
605
610
606
- _ , err = ctrl .clientset .SnapshotV1 ().VolumeSnapshotContents ().Create (ctx , volumeSnapshotContent , metav1.CreateOptions {})
611
+ if pv != nil {
612
+ volumeSnapshot .Spec .Source .PersistentVolumeClaimName = & pv .Spec .ClaimRef .Name
613
+ } else {
614
+ // If no persistent volume was found, set the PVC name to empty
615
+ var emptyString string
616
+ volumeSnapshot .Spec .Source .PersistentVolumeClaimName = & emptyString
617
+ }
618
+
619
+ createdVolumeSnapshotContent , err := ctrl .clientset .SnapshotV1 ().VolumeSnapshotContents ().Create (ctx , volumeSnapshotContent , metav1.CreateOptions {})
607
620
if err != nil && ! apierrs .IsAlreadyExists (err ) {
608
621
return groupSnapshotContent , fmt .Errorf (
609
622
"createSnapshotsForGroupSnapshotContent: creating volumesnapshotcontent %w" , err )
@@ -648,6 +661,32 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
648
661
return groupSnapshotContent , fmt .Errorf (
649
662
"createSnapshotsForGroupSnapshotContent: binding volumesnapshot to volumesnapshotcontent %w" , err )
650
663
}
664
+
665
+ // set the snapshot handle and the group snapshot handle
666
+ // inside the volume snapshot content to allow
667
+ // the CSI Snapshotter sidecar to reconcile its status
668
+ _ , err = utils .PatchVolumeSnapshotContent (createdVolumeSnapshotContent , []utils.PatchOp {
669
+ {
670
+ Op : "replace" ,
671
+ Path : "/status" ,
672
+ Value : & crdv1.VolumeSnapshotContentStatus {},
673
+ },
674
+ {
675
+ Op : "replace" ,
676
+ Path : "/status/snapshotHandle" ,
677
+ Value : snapshotHandle ,
678
+ },
679
+ {
680
+ Op : "replace" ,
681
+ Path : "/status/volumeGroupSnapshotHandle" ,
682
+ Value : groupSnapshotContent .Status .VolumeGroupSnapshotHandle ,
683
+ },
684
+ }, ctrl .clientset , "status" )
685
+ if err != nil {
686
+ return groupSnapshotContent , fmt .Errorf (
687
+ "createSnapshotsForGroupSnapshotContent: setting snapshotHandle in volumesnapshotcontent %w" , err )
688
+ }
689
+
651
690
}
652
691
653
692
return groupSnapshotContent , nil
0 commit comments