Skip to content

Commit ff6709c

Browse files
YashasG98l-technicore
authored andcommitted
Made error handling changes in FSS GetPrivateIP flow
1 parent 5d9d386 commit ff6709c

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

pkg/csi/driver/bv_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ func (c *MockVirtualNetworkClient) UpdateNetworkSecurityGroupSecurityRules(ctx c
449449

450450
// GetPrivateIp mocks the VirtualNetwork GetPrivateIp implementation
451451
func (c *MockVirtualNetworkClient) GetPrivateIp(ctx context.Context, id string) (*core.PrivateIp, error) {
452+
if id == "private-ip-fetch-error" {
453+
return nil, errors.New("private IP fetch failed")
454+
}
452455
privateIpAddress := "10.0.20.1"
453456
return &core.PrivateIp{
454457
IpAddress: &privateIpAddress,

pkg/csi/driver/fss_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/oracle/oci-cloud-controller-manager/pkg/metrics"
2828
"github.com/oracle/oci-cloud-controller-manager/pkg/oci/client"
2929
"github.com/oracle/oci-cloud-controller-manager/pkg/util"
30+
"github.com/oracle/oci-go-sdk/v65/core"
3031
fss "github.com/oracle/oci-go-sdk/v65/filestorage"
3132
authv1 "k8s.io/api/authentication/v1"
3233
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -462,19 +463,21 @@ func (d *FSSControllerDriver) getOrCreateMountTarget(ctx context.Context, storag
462463
var ipType string
463464
// TODO: Uncomment after SDK Supports Ipv6 - 10 lines
464465
//if len(activeMountTarget.MountTargetIpv6Ids) > 0 {
465-
// ipType = "ipv6"
466466
// // Ipv6 Mount Target
467+
// var ipv6IpObject *core.Ipv6
468+
// ipType = "ipv6"
467469
// mountTargetIpId = activeMountTarget.MountTargetIpv6Ids[0]
468470
// log.With("mountTargetIpId", mountTargetIpId).Infof("Getting Ipv6 IP of mount target")
469-
// if ipv6IpObject, err := networkingClient.GetIpv6(ctx, mountTargetIpId); err == nil {
471+
// if ipv6IpObject, err = networkingClient.GetIpv6(ctx, mountTargetIpId); err == nil {
470472
// mountTargetIp = *ipv6IpObject.IpAddress
471473
// }
472474
//} else {
473475
// Ipv4 Mount Target
476+
var privateIpObject *core.PrivateIp
474477
mountTargetIpId = activeMountTarget.PrivateIpIds[0]
475478
ipType = "privateIp"
476479
log.With("mountTargetIpId", mountTargetIpId).Infof("Getting private IP of mount target")
477-
if privateIpObject, err := networkingClient.GetPrivateIp(ctx, mountTargetIpId); err == nil {
480+
if privateIpObject, err = networkingClient.GetPrivateIp(ctx, mountTargetIpId); err == nil {
478481
mountTargetIp = *privateIpObject.IpAddress
479482
}
480483
//}

pkg/csi/driver/fss_controller_test.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ var (
5555
AvailabilityDomain: common.String("NWuj:PHX-AD-2"),
5656
Id: common.String("mount-target-stuck-creating"),
5757
},
58+
"private-ip-fetch-error": {
59+
DisplayName: common.String("private-ip-fetch-error"),
60+
LifecycleState: fss.MountTargetLifecycleStateActive,
61+
AvailabilityDomain: common.String("NWuj:PHX-AD-2"),
62+
Id: common.String("private-ip-fetch-error"),
63+
PrivateIpIds: []string{"private-ip-fetch-error"},
64+
},
5865
}
5966

6067
fileSystems = map[string]*fss.FileSystem{
@@ -360,18 +367,7 @@ func (c *MockFileStorageClient) AwaitMountTargetActive(ctx context.Context, logg
360367
}, ctx.Done()); err != nil {
361368
return nil, err
362369
}
363-
idMt := "oc1.mounttarget.xxxx"
364-
ad := "zkJl:US-ASHBURN-AD-1"
365-
privateIpIds := []string{"10.0.20.1"}
366-
displayName := "mountTarget"
367-
idEx := "oc1.export.xxxx"
368-
return &filestorage.MountTarget{
369-
Id: &idMt,
370-
AvailabilityDomain: &ad,
371-
DisplayName: &displayName,
372-
PrivateIpIds: privateIpIds,
373-
ExportSetId: &idEx,
374-
}, nil
370+
return mt, nil
375371
}
376372

377373
// CreateMountTarget mocks the FileStorage CreateMountTarget implementation.
@@ -545,6 +541,24 @@ func TestFSSControllerDriver_CreateVolume(t *testing.T) {
545541
want: nil,
546542
wantErr: errors.New("Neither Mount Target Ocid nor Mount Target Subnet Ocid provided in storage class"),
547543
},
544+
{
545+
name: "Error during mount target IP fetch",
546+
fields: fields{},
547+
args: args{
548+
ctx: context.Background(),
549+
req: &csi.CreateVolumeRequest{
550+
Name: "private-ip-fetch-error",
551+
Parameters: map[string]string{"availabilityDomain": "US-ASHBURN-AD-1", "mountTargetSubnetOcid": "oc1.subnet.xxxx"},
552+
VolumeCapabilities: []*csi.VolumeCapability{{
553+
AccessMode: &csi.VolumeCapability_AccessMode{
554+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
555+
},
556+
}},
557+
},
558+
},
559+
want: nil,
560+
wantErr: errors.New("Failed to get mount target privateIp ip from ip id"),
561+
},
548562
{
549563
name: "Time out during file system idempotency check",
550564
fields: fields{},

pkg/oci/client/networking.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ func (c *client) GetPrivateIp(ctx context.Context, id string) (*core.PrivateIp,
241241
RequestMetadata: c.requestMetadata,
242242
})
243243
if resp.OpcRequestId != nil {
244-
c.logger.With("service", "Networking", "verb", getVerb).
244+
c.logger.With("service", "Networking", "verb", getVerb, "mountTargetIpId", id).
245245
With("OpcRequestId", *(resp.OpcRequestId)).With("statusCode", util.GetHttpStatusCode(err)).
246-
Info("OPC Request ID recorded for GetIpv6GetPrivateIp call.")
246+
Info("OPC Request ID recorded for GetPrivateIp call.")
247247
}
248248
incRequestCounter(err, getVerb, privateIPResource)
249249

250250
if err != nil {
251-
c.logger.With(id).Infof("GetPrivateIp failed %s", pointer.StringDeref(resp.OpcRequestId, ""))
251+
c.logger.With("mountTargetIpId", id).Infof("GetPrivateIp failed %s", pointer.StringDeref(resp.OpcRequestId, ""))
252252
return nil, errors.WithStack(err)
253253
}
254254

0 commit comments

Comments
 (0)