@@ -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 {
@@ -561,6 +567,9 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
561
567
volumeSnapshotContent := & crdv1.VolumeSnapshotContent {
562
568
ObjectMeta : metav1.ObjectMeta {
563
569
Name : volumeSnapshotContentName ,
570
+ Labels : map [string ]string {
571
+ utils .VolumeGroupSnapshotHandleLabel : * groupSnapshotContent .Status .VolumeGroupSnapshotHandle ,
572
+ },
564
573
},
565
574
Spec : crdv1.VolumeSnapshotContentSpec {
566
575
VolumeSnapshotRef : v1.ObjectReference {
@@ -571,7 +580,7 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
571
580
DeletionPolicy : groupSnapshotContent .Spec .DeletionPolicy ,
572
581
Driver : groupSnapshotContent .Spec .Driver ,
573
582
Source : crdv1.VolumeSnapshotContentSource {
574
- SnapshotHandle : & snapshotHandle ,
583
+ VolumeHandle : & volumeHandle ,
575
584
},
576
585
},
577
586
// The status will be set by VolumeSnapshotContent reconciler
@@ -590,24 +599,28 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
590
599
metav1 .SetMetaDataAnnotation (& volumeSnapshotContent .ObjectMeta , utils .AnnDeletionSecretRefNamespace , groupSnapshotSecret .Namespace )
591
600
}
592
601
593
- label := make (map [string ]string )
594
- label [utils .VolumeGroupSnapshotNameLabel ] = groupSnapshotContent .Spec .VolumeGroupSnapshotRef .Name
595
602
volumeSnapshot := & crdv1.VolumeSnapshot {
596
603
ObjectMeta : metav1.ObjectMeta {
597
- Name : volumeSnapshotName ,
598
- Namespace : volumeSnapshotNamespace ,
599
- Labels : label ,
600
- Finalizers : []string {utils .VolumeSnapshotInGroupFinalizer },
601
- },
602
- Spec : crdv1.VolumeSnapshotSpec {
603
- Source : crdv1.VolumeSnapshotSource {
604
- PersistentVolumeClaimName : & pv .Spec .ClaimRef .Name ,
604
+ Name : volumeSnapshotName ,
605
+ Namespace : volumeSnapshotNamespace ,
606
+ Labels : map [string ]string {
607
+ utils .VolumeGroupSnapshotNameLabel : groupSnapshotContent .Spec .VolumeGroupSnapshotRef .Name ,
605
608
},
609
+ Finalizers : []string {utils .VolumeSnapshotInGroupFinalizer },
606
610
},
611
+ // The spec stanza is set immediately
607
612
// The status will be set by VolumeSnapshot reconciler
608
613
}
609
614
610
- _ , err = ctrl .clientset .SnapshotV1 ().VolumeSnapshotContents ().Create (ctx , volumeSnapshotContent , metav1.CreateOptions {})
615
+ if pv != nil {
616
+ volumeSnapshot .Spec .Source .PersistentVolumeClaimName = & pv .Spec .ClaimRef .Name
617
+ } else {
618
+ // If no persistent volume was found, set the PVC name to empty
619
+ var emptyString string
620
+ volumeSnapshot .Spec .Source .PersistentVolumeClaimName = & emptyString
621
+ }
622
+
623
+ createdVolumeSnapshotContent , err := ctrl .clientset .SnapshotV1 ().VolumeSnapshotContents ().Create (ctx , volumeSnapshotContent , metav1.CreateOptions {})
611
624
if err != nil && ! apierrs .IsAlreadyExists (err ) {
612
625
return groupSnapshotContent , fmt .Errorf (
613
626
"createSnapshotsForGroupSnapshotContent: creating volumesnapshotcontent %w" , err )
@@ -663,6 +676,32 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
663
676
return groupSnapshotContent , fmt .Errorf (
664
677
"createSnapshotsForGroupSnapshotContent: binding volumesnapshot to volumesnapshotcontent %w" , err )
665
678
}
679
+
680
+ // set the snapshot handle and the group snapshot handle
681
+ // inside the volume snapshot content to allow
682
+ // the CSI Snapshotter sidecar to reconcile its status
683
+ _ , err = utils .PatchVolumeSnapshotContent (createdVolumeSnapshotContent , []utils.PatchOp {
684
+ {
685
+ Op : "replace" ,
686
+ Path : "/status" ,
687
+ Value : & crdv1.VolumeSnapshotContentStatus {},
688
+ },
689
+ {
690
+ Op : "replace" ,
691
+ Path : "/status/snapshotHandle" ,
692
+ Value : snapshotHandle ,
693
+ },
694
+ {
695
+ Op : "replace" ,
696
+ Path : "/status/volumeGroupSnapshotHandle" ,
697
+ Value : groupSnapshotContent .Status .VolumeGroupSnapshotHandle ,
698
+ },
699
+ }, ctrl .clientset , "status" )
700
+ if err != nil {
701
+ return groupSnapshotContent , fmt .Errorf (
702
+ "createSnapshotsForGroupSnapshotContent: setting snapshotHandle in volumesnapshotcontent %w" , err )
703
+ }
704
+
666
705
}
667
706
668
707
// Phase 2: set the backlinks
0 commit comments