Skip to content

Commit 3ff8e10

Browse files
NSG Support with mount target creation
1 parent 710e776 commit 3ff8e10

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

pkg/csi/driver/fss_controller.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ type StorageClassParameters struct {
8383
encryptInTransit string
8484
// tags
8585
scTags *config.TagConfig
86+
// NsgOcids
87+
nsgOcids []string
8688
}
8789

8890
type SecretParameters struct {
@@ -659,6 +661,22 @@ func extractStorageClassParameters(ctx context.Context, d *FSSControllerDriver,
659661
log = log.With("mountTargetSubnetOcid", mountTargetSubnetOcid)
660662
log.Info("Mount Target Ocid not provided, to be created")
661663
storageClassParameters.mountTargetSubnetOcid = mountTargetSubnetOcid
664+
665+
nsgOcidsStr, ok := parameters["nsgOcids"]
666+
if !ok {
667+
log.Infof("No NSG Ocids provided to associate with new mount target creation")
668+
} else {
669+
var nsgOcids []string
670+
err := json.Unmarshal([]byte(nsgOcidsStr), &nsgOcids)
671+
if err != nil {
672+
log.Errorf("Failed to parse nsgOcids provided in storage class. Please provide valid input.")
673+
dimensionsMap[metrics.ComponentDimension] = util.GetMetricDimensionForComponent(util.ErrValidation, util.CSIStorageType)
674+
metrics.SendMetricData(d.metricPusher, metrics.MTProvision, time.Since(startTime).Seconds(), dimensionsMap)
675+
return log, nil, nil, status.Errorf(codes.InvalidArgument, "Failed to parse nsgOcids provided in storage class. Please provide valid input."), true
676+
}
677+
log.With("nsgOcids", nsgOcids)
678+
storageClassParameters.nsgOcids = nsgOcids
679+
}
662680
} else {
663681
storageClassParameters.mountTargetOcid = mountTargetOcid
664682
log = log.With("mountTargetOcid", mountTargetOcid)
@@ -775,6 +793,7 @@ func provisionMountTarget(ctx context.Context, log *zap.SugaredLogger, c client.
775793
SubnetId: &storageClassParameters.mountTargetSubnetOcid,
776794
FreeformTags: storageClassParameters.scTags.FreeformTags,
777795
DefinedTags: storageClassParameters.scTags.DefinedTags,
796+
NsgIds: storageClassParameters.nsgOcids,
778797
}
779798
return fssClient.CreateMountTarget(ctx, createMountTargetDetails)
780799
}

pkg/csi/driver/fss_controller_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,24 @@ func TestFSSControllerDriver_CreateVolume(t *testing.T) {
542542
want: nil,
543543
wantErr: errors.New("Neither Mount Target Ocid nor Mount Target Subnet Ocid provided in storage class"),
544544
},
545+
{
546+
name: "Error when invalid JSON string provided for mount target NSGs",
547+
fields: fields{},
548+
args: args{
549+
ctx: context.Background(),
550+
req: &csi.CreateVolumeRequest{
551+
Name: "ut-volume",
552+
Parameters: map[string]string{"availabilityDomain": "US-ASHBURN-AD-1", "mountTargetSubnetOcid": "oc1.subnet.xxxx", "nsgOcids": ""},
553+
VolumeCapabilities: []*csi.VolumeCapability{{
554+
AccessMode: &csi.VolumeCapability_AccessMode{
555+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
556+
},
557+
}},
558+
},
559+
},
560+
want: nil,
561+
wantErr: errors.New("Failed to parse nsgOcids provided in storage class. Please provide valid input."),
562+
},
545563
{
546564
name: "Error during mount target IP fetch",
547565
fields: fields{},

0 commit comments

Comments
 (0)