@@ -94,6 +94,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
9494 diskType := "pd-standard"
9595 // Start process for creating a new disk
9696 replicationType := replicationTypeNone
97+ diskEncryptionKmsKey := ""
9798 for k , v := range req .GetParameters () {
9899 if k == "csiProvisionerSecretName" || k == "csiProvisionerSecretNamespace" {
99100 // These are hardcoded secrets keys required to function but not needed by GCE PD
@@ -105,6 +106,9 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
105106 diskType = v
106107 case common .ParameterKeyReplicationType :
107108 replicationType = strings .ToLower (v )
109+ case common .ParameterKeyDiskEncryptionKmsKey :
110+ // Resource names (e.g. "keyRings", "cryptoKeys", etc.) are case sensitive, so do not change case
111+ diskEncryptionKmsKey = v
108112 default :
109113 return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("CreateVolume invalid option %q" , k ))
110114 }
@@ -172,15 +176,15 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
172176 if len (zones ) != 1 {
173177 return nil , status .Errorf (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones ))
174178 }
175- disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId )
179+ disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId , diskEncryptionKmsKey )
176180 if err != nil {
177181 return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to create single zonal disk %#v: %v" , name , err ))
178182 }
179183 case replicationTypeRegionalPD :
180184 if len (zones ) != 2 {
181185 return nil , status .Errorf (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a 2 zones for creating regional disk, instead got: %v" , zones ))
182186 }
183- disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId )
187+ disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId , diskEncryptionKmsKey )
184188 if err != nil {
185189 return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to create regional disk %#v: %v" , name , err ))
186190 }
@@ -888,7 +892,7 @@ func cleanSelfLink(selfLink string) string {
888892 return strings .TrimPrefix (temp , gce .GCEComputeBetaAPIEndpoint )
889893}
890894
891- func createRegionalDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotId string ) (* gce.CloudDisk , error ) {
895+ func createRegionalDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotId , diskEncryptionKmsKey string ) (* gce.CloudDisk , error ) {
892896 region , err := common .GetRegionFromZones (zones )
893897 if err != nil {
894898 return nil , fmt .Errorf ("failed to get region from zones: %v" , err )
@@ -900,7 +904,7 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
900904 fullyQualifiedReplicaZones , cloudProvider .GetReplicaZoneURI (replicaZone ))
901905 }
902906
903- err = cloudProvider .InsertDisk (ctx , meta .RegionalKey (name , region ), diskType , capBytes , capacityRange , fullyQualifiedReplicaZones , snapshotId )
907+ err = cloudProvider .InsertDisk (ctx , meta .RegionalKey (name , region ), diskType , capBytes , capacityRange , fullyQualifiedReplicaZones , snapshotId , diskEncryptionKmsKey )
904908 if err != nil {
905909 return nil , fmt .Errorf ("failed to insert regional disk: %v" , err )
906910 }
@@ -914,12 +918,12 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
914918 return disk , nil
915919}
916920
917- func createSingleZoneDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotId string ) (* gce.CloudDisk , error ) {
921+ func createSingleZoneDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotId , diskEncryptionKmsKey string ) (* gce.CloudDisk , error ) {
918922 if len (zones ) != 1 {
919923 return nil , fmt .Errorf ("got wrong number of zones for zonal create volume: %v" , len (zones ))
920924 }
921925 diskZone := zones [0 ]
922- err := cloudProvider .InsertDisk (ctx , meta .ZonalKey (name , diskZone ), diskType , capBytes , capacityRange , nil , snapshotId )
926+ err := cloudProvider .InsertDisk (ctx , meta .ZonalKey (name , diskZone ), diskType , capBytes , capacityRange , nil , snapshotId , diskEncryptionKmsKey )
923927 if err != nil {
924928 return nil , fmt .Errorf ("failed to insert zonal disk: %v" , err )
925929 }
0 commit comments