@@ -94,6 +94,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
94
94
diskType := "pd-standard"
95
95
// Start process for creating a new disk
96
96
replicationType := replicationTypeNone
97
+ diskEncryptionKmsKey := ""
97
98
for k , v := range req .GetParameters () {
98
99
if k == "csiProvisionerSecretName" || k == "csiProvisionerSecretNamespace" {
99
100
// 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
105
106
diskType = v
106
107
case common .ParameterKeyReplicationType :
107
108
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
108
112
default :
109
113
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("CreateVolume invalid option %q" , k ))
110
114
}
@@ -172,15 +176,15 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
172
176
if len (zones ) != 1 {
173
177
return nil , status .Errorf (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones ))
174
178
}
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 )
176
180
if err != nil {
177
181
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to create single zonal disk %#v: %v" , name , err ))
178
182
}
179
183
case replicationTypeRegionalPD :
180
184
if len (zones ) != 2 {
181
185
return nil , status .Errorf (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a 2 zones for creating regional disk, instead got: %v" , zones ))
182
186
}
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 )
184
188
if err != nil {
185
189
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to create regional disk %#v: %v" , name , err ))
186
190
}
@@ -888,7 +892,7 @@ func cleanSelfLink(selfLink string) string {
888
892
return strings .TrimPrefix (temp , gce .GCEComputeBetaAPIEndpoint )
889
893
}
890
894
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 ) {
892
896
region , err := common .GetRegionFromZones (zones )
893
897
if err != nil {
894
898
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
900
904
fullyQualifiedReplicaZones , cloudProvider .GetReplicaZoneURI (replicaZone ))
901
905
}
902
906
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 )
904
908
if err != nil {
905
909
return nil , fmt .Errorf ("failed to insert regional disk: %v" , err )
906
910
}
@@ -914,12 +918,12 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
914
918
return disk , nil
915
919
}
916
920
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 ) {
918
922
if len (zones ) != 1 {
919
923
return nil , fmt .Errorf ("got wrong number of zones for zonal create volume: %v" , len (zones ))
920
924
}
921
925
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 )
923
927
if err != nil {
924
928
return nil , fmt .Errorf ("failed to insert zonal disk: %v" , err )
925
929
}
0 commit comments