@@ -2795,20 +2795,29 @@ func (m *defaultManager) createSnapshotWithImprovedIdempotencyCheck(ctx context.
2795
2795
// This function ensures that no orphaned snapshots are left behind on the vSphere backend
2796
2796
// in case of failures during the snapshot creation process
2797
2797
func (m * defaultManager ) createSnapshotWithTransaction (ctx context.Context , volumeID string ,
2798
- snapshotID string , extraParams interface {}) (* CnsSnapshotInfo , string , error ) {
2798
+ snapshotName string , extraParams interface {}) (* CnsSnapshotInfo , string , error ) {
2799
2799
log := logger .GetLogger (ctx )
2800
2800
var (
2801
2801
// Reference to the CreateSnapshot task on CNS.
2802
2802
createSnapshotsTask * object.Task
2803
2803
// Name of the CnsVolumeOperationRequest instance.
2804
- instanceName = snapshotID + "-" + volumeID
2804
+ instanceName = snapshotName + "-" + volumeID
2805
2805
// Local instance of CreateSnapshot details that needs to be persisted.
2806
2806
volumeOperationDetails * cnsvolumeoperationrequest.VolumeOperationRequestDetails
2807
2807
// error
2808
2808
err error
2809
2809
quotaInfo * cnsvolumeoperationrequest.QuotaDetails
2810
2810
isStorageQuotaM2FSSEnabled bool
2811
2811
)
2812
+ // By default, external-snapshotter sets the snapshot name prefix to "snapshot-".
2813
+ // This logic will break if the prefix configuration is changed.
2814
+ // In Supervisor deployments, we assume this configuration remains unchanged by admin/DevOps.
2815
+ // In Vanilla deployments, we publish the deployment manifest with the default configuration to ensure consistency.
2816
+ if ! strings .HasPrefix (snapshotName , "snapshot-" ) {
2817
+ return nil , csifault .CSIInternalFault ,
2818
+ logger .LogNewErrorf (log , "invalid snapshotName %q: must start with 'snapshot-'" , snapshotName )
2819
+ }
2820
+ snapshotID := strings .TrimPrefix (snapshotName , "snapshot-" )
2812
2821
if extraParams != nil {
2813
2822
createSnapParams , ok := extraParams .(* CreateSnapshotExtraParams )
2814
2823
if ! ok {
@@ -2888,8 +2897,20 @@ func (m *defaultManager) createSnapshotWithTransaction(ctx context.Context, volu
2888
2897
"from vCenter %q with err: %v" , m .virtualCenter .Config .Host , err )
2889
2898
}
2890
2899
log .Infof ("CreateSnapshots: VolumeID: %q, opId: %q" , volumeID , createSnapshotsTaskInfo .ActivationId )
2891
-
2892
- snapshotCreateResult := interface {}(createSnapshotsTaskInfo ).(* cnstypes.CnsSnapshotCreateResult )
2900
+ createSnapshotsTaskResult , err := cns .GetTaskResult (ctx , createSnapshotsTaskInfo )
2901
+ if err != nil || createSnapshotsTaskResult == nil {
2902
+ return nil , "" , logger .LogNewErrorf (log , "unable to find the task result for CreateSnapshots task: %q " +
2903
+ "from vCenter %q with err: %v" , createSnapshotsTaskInfo .Task .Value , m .virtualCenter .Config .Host , err )
2904
+ }
2905
+ snapshotCreateResult , ok := createSnapshotsTaskResult .(* cnstypes.CnsSnapshotCreateResult )
2906
+ if ! ok || snapshotCreateResult == nil {
2907
+ return nil , "" , logger .LogNewErrorf (log ,
2908
+ "invalid task result: got %T with value %+v" , createSnapshotsTaskResult , createSnapshotsTaskResult )
2909
+ }
2910
+ if snapshotCreateResult .Fault != nil {
2911
+ return nil , "" , logger .LogNewErrorf (log , "failed to create snapshot %q on volume %q with fault: %+v" ,
2912
+ instanceName , volumeID , snapshotCreateResult .Fault )
2913
+ }
2893
2914
cnsSnapshotInfo := & CnsSnapshotInfo {
2894
2915
SnapshotID : snapshotCreateResult .Snapshot .SnapshotId .Id ,
2895
2916
SourceVolumeID : snapshotCreateResult .Snapshot .VolumeId .Id ,
@@ -2947,14 +2968,15 @@ func (m *defaultManager) CreateSnapshot(
2947
2968
}
2948
2969
}
2949
2970
if createSnapParams != nil && createSnapParams .IsCSITransactionSupportEnabled {
2950
- var snapcontentPrefix = "snapcontent-"
2951
2971
cnssnapshotInfo , fault , err := m .createSnapshotWithTransaction (ctx , volumeID ,
2952
- strings . TrimPrefix ( snapshotName , snapcontentPrefix ) , extraParams )
2972
+ snapshotName , extraParams )
2953
2973
if err != nil {
2954
2974
if IsNotSupportedFaultType (ctx , fault ) {
2955
2975
log .Infof ("Creating Snapshot with Transaction is not supported. " +
2956
2976
"Re-creating Snapshot without setting Snapshot ID in the spec" )
2957
2977
return m .createSnapshotWithImprovedIdempotencyCheck (ctx , volumeID , snapshotName , extraParams )
2978
+ } else {
2979
+ return nil , logger .LogNewErrorf (log , "failed to create snapshot. error :%+v" , err )
2958
2980
}
2959
2981
}
2960
2982
return cnssnapshotInfo , nil
0 commit comments