@@ -504,6 +504,12 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
504504 return groupSnapshotContent , nil
505505 }
506506
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+
507513 // The contents of the volume group snapshot class are needed to set the
508514 // metadata containing the secrets to recover the snapshots
509515 if groupSnapshot .Spec .VolumeGroupSnapshotClassName == nil {
@@ -561,6 +567,9 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
561567 volumeSnapshotContent := & crdv1.VolumeSnapshotContent {
562568 ObjectMeta : metav1.ObjectMeta {
563569 Name : volumeSnapshotContentName ,
570+ Labels : map [string ]string {
571+ utils .VolumeGroupSnapshotHandleLabel : * groupSnapshotContent .Status .VolumeGroupSnapshotHandle ,
572+ },
564573 },
565574 Spec : crdv1.VolumeSnapshotContentSpec {
566575 VolumeSnapshotRef : v1.ObjectReference {
@@ -571,7 +580,7 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
571580 DeletionPolicy : groupSnapshotContent .Spec .DeletionPolicy ,
572581 Driver : groupSnapshotContent .Spec .Driver ,
573582 Source : crdv1.VolumeSnapshotContentSource {
574- SnapshotHandle : & snapshotHandle ,
583+ VolumeHandle : & volumeHandle ,
575584 },
576585 },
577586 // The status will be set by VolumeSnapshotContent reconciler
@@ -590,24 +599,28 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
590599 metav1 .SetMetaDataAnnotation (& volumeSnapshotContent .ObjectMeta , utils .AnnDeletionSecretRefNamespace , groupSnapshotSecret .Namespace )
591600 }
592601
593- label := make (map [string ]string )
594- label [utils .VolumeGroupSnapshotNameLabel ] = groupSnapshotContent .Spec .VolumeGroupSnapshotRef .Name
595602 volumeSnapshot := & crdv1.VolumeSnapshot {
596603 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 ,
605608 },
609+ Finalizers : []string {utils .VolumeSnapshotInGroupFinalizer },
606610 },
611+ // The spec stanza is set immediately
607612 // The status will be set by VolumeSnapshot reconciler
608613 }
609614
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 {})
611624 if err != nil && ! apierrs .IsAlreadyExists (err ) {
612625 return groupSnapshotContent , fmt .Errorf (
613626 "createSnapshotsForGroupSnapshotContent: creating volumesnapshotcontent %w" , err )
@@ -663,6 +676,32 @@ func (ctrl *csiSnapshotCommonController) createSnapshotsForGroupSnapshotContent(
663676 return groupSnapshotContent , fmt .Errorf (
664677 "createSnapshotsForGroupSnapshotContent: binding volumesnapshot to volumesnapshotcontent %w" , err )
665678 }
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+
666705 }
667706
668707 // Phase 2: set the backlinks
0 commit comments