@@ -324,7 +324,7 @@ func ValidateDiskParameters(disk *CloudDisk, params common.DiskParameters) error
324
324
func (cloud * CloudProvider ) InsertDisk (ctx context.Context , project string , volKey * meta.Key , params common.DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string , volumeContentSourceVolumeID string , multiWriter bool ) error {
325
325
klog .V (5 ).Infof ("Inserting disk %v" , volKey )
326
326
327
- description , err := encodeDiskTags (params .Tags )
327
+ description , err := encodeTags (params .Tags )
328
328
if err != nil {
329
329
return err
330
330
}
@@ -848,18 +848,40 @@ func (cloud *CloudProvider) DeleteSnapshot(ctx context.Context, project, snapsho
848
848
849
849
func (cloud * CloudProvider ) CreateSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters ) (* computev1.Snapshot , error ) {
850
850
klog .V (5 ).Infof ("Creating snapshot %s for volume %v" , snapshotName , volKey )
851
+
852
+ description , err := encodeTags (snapshotParams .Tags )
853
+ if err != nil {
854
+ return nil , err
855
+ }
856
+
851
857
switch volKey .Type () {
852
858
case meta .Zonal :
853
- return cloud .createZonalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
859
+ if description == "" {
860
+ description = "Snapshot created by GCE-PD CSI Driver"
861
+ }
862
+ return cloud .createZonalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
854
863
case meta .Regional :
855
- return cloud .createRegionalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
864
+ if description == "" {
865
+ description = "Regional Snapshot created by GCE-PD CSI Driver"
866
+ }
867
+ return cloud .createRegionalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
856
868
default :
857
869
return nil , fmt .Errorf ("could not create snapshot, key was neither zonal nor regional, instead got: %v" , volKey .String ())
858
870
}
859
871
}
860
872
861
873
func (cloud * CloudProvider ) CreateImage (ctx context.Context , project string , volKey * meta.Key , imageName string , snapshotParams common.SnapshotParameters ) (* computev1.Image , error ) {
862
874
klog .V (5 ).Infof ("Creating image %s for source %v" , imageName , volKey )
875
+
876
+ description , err := encodeTags (snapshotParams .Tags )
877
+ if err != nil {
878
+ return nil , err
879
+ }
880
+
881
+ if description == "" {
882
+ description = "Image created by GCE-PD CSI Driver"
883
+ }
884
+
863
885
diskID , err := common .KeyToVolumeID (volKey , project )
864
886
if err != nil {
865
887
return nil , err
@@ -869,6 +891,7 @@ func (cloud *CloudProvider) CreateImage(ctx context.Context, project string, vol
869
891
Family : snapshotParams .ImageFamily ,
870
892
Name : imageName ,
871
893
StorageLocations : snapshotParams .StorageLocations ,
894
+ Description : description ,
872
895
}
873
896
874
897
_ , err = cloud .service .Images .Insert (project , image ).Context (ctx ).Do ()
@@ -1013,10 +1036,11 @@ func (cloud *CloudProvider) resizeRegionalDisk(ctx context.Context, project stri
1013
1036
return requestGb , nil
1014
1037
}
1015
1038
1016
- func (cloud * CloudProvider ) createZonalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters ) (* computev1.Snapshot , error ) {
1039
+ func (cloud * CloudProvider ) createZonalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters , description string ) (* computev1.Snapshot , error ) {
1017
1040
snapshotToCreate := & computev1.Snapshot {
1018
1041
Name : snapshotName ,
1019
1042
StorageLocations : snapshotParams .StorageLocations ,
1043
+ Description : description ,
1020
1044
}
1021
1045
1022
1046
_ , err := cloud .service .Disks .CreateSnapshot (project , volKey .Zone , volKey .Name , snapshotToCreate ).Context (ctx ).Do ()
@@ -1028,10 +1052,11 @@ func (cloud *CloudProvider) createZonalDiskSnapshot(ctx context.Context, project
1028
1052
return cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1029
1053
}
1030
1054
1031
- func (cloud * CloudProvider ) createRegionalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters ) (* computev1.Snapshot , error ) {
1055
+ func (cloud * CloudProvider ) createRegionalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters , description string ) (* computev1.Snapshot , error ) {
1032
1056
snapshotToCreate := & computev1.Snapshot {
1033
1057
Name : snapshotName ,
1034
1058
StorageLocations : snapshotParams .StorageLocations ,
1059
+ Description : description ,
1035
1060
}
1036
1061
1037
1062
_ , err := cloud .service .RegionDisks .CreateSnapshot (project , volKey .Region , volKey .Name , snapshotToCreate ).Context (ctx ).Do ()
@@ -1088,17 +1113,17 @@ func removeCryptoKeyVersion(kmsKey string) string {
1088
1113
return kmsKey
1089
1114
}
1090
1115
1091
- // encodeDiskTags encodes requested volume tags into JSON string, as GCE does
1092
- // not support tags on GCE PDs and we use Description field as fallback .
1093
- func encodeDiskTags (tags map [string ]string ) (string , error ) {
1116
+ // encodeTags encodes requested volume or snapshot tags into JSON string, suitable for putting into
1117
+ // the PD or Snapshot Description field.
1118
+ func encodeTags (tags map [string ]string ) (string , error ) {
1094
1119
if len (tags ) == 0 {
1095
1120
// No tags -> empty JSON
1096
1121
return "" , nil
1097
1122
}
1098
1123
1099
1124
enc , err := json .Marshal (tags )
1100
1125
if err != nil {
1101
- return "" , fmt .Errorf ("failed to encodeDiskTags %v: %v" , tags , err )
1126
+ return "" , fmt .Errorf ("failed to encodeTags %v: %v" , tags , err )
1102
1127
}
1103
1128
return string (enc ), nil
1104
1129
}
0 commit comments