Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fix] AttachVolume error where volume region is empty #301

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/driver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *cs

// Check if the volume exists and is valid.
// If the volume is already attached to the specified instance, it returns its device path.
devicePath, err := cs.getAndValidateVolume(ctx, volumeID, instance, req.GetVolumeContext())
devicePath, err := cs.getAndValidateVolume(ctx, volumeID, instance)
if err != nil {
metrics.RecordMetrics(metrics.ControllerPublishVolumeTotal, metrics.ControllerPublishVolumeDuration, metrics.Failed, functionStartTime)
return resp, err
Expand Down
6 changes: 3 additions & 3 deletions internal/driver/controllerserver_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func (cs *ControllerServer) validateControllerPublishVolumeRequest(ctx context.C
//
// Additionally, it checks if the volume and instance are in the same region based on
// the provided volume context. If they are not in the same region, it returns an internal error.
func (cs *ControllerServer) getAndValidateVolume(ctx context.Context, volumeID int, instance *linodego.Instance, volContext map[string]string) (string, error) {
func (cs *ControllerServer) getAndValidateVolume(ctx context.Context, volumeID int, instance *linodego.Instance) (string, error) {
log := logger.GetLogger(ctx)
log.V(4).Info("Entering getAndValidateVolume()", "volumeID", volumeID, "linodeID", instance.ID)
defer log.V(4).Info("Exiting getAndValidateVolume()")
Expand All @@ -584,8 +584,8 @@ func (cs *ControllerServer) getAndValidateVolume(ctx context.Context, volumeID i
}

// check if the volume and instance are in the same region
if instance.Region != volContext[VolumeTopologyRegion] {
return "", errRegionMismatch(volContext[VolumeTopologyRegion], instance.Region)
if instance.Region != volume.Region {
return "", errRegionMismatch(volume.Region, instance.Region)
}

log.V(4).Info("Volume validated and is not attached to instance", "volume_id", volume.ID, "node_id", instance.ID)
Expand Down
7 changes: 2 additions & 5 deletions internal/driver/controllerserver_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,6 @@ func TestGetAndValidateVolume(t *testing.T) {
client: mockClient,
}

volContext := map[string]string{
VolumeTopologyRegion: "us-east",
}

testCases := []struct {
name string
volumeID int
Expand Down Expand Up @@ -715,6 +711,7 @@ func TestGetAndValidateVolume(t *testing.T) {
mockClient.EXPECT().GetVolume(gomock.Any(), 123).Return(&linodego.Volume{
ID: 123,
LinodeID: nil,
Region: "us-east",
}, nil)
},
expectedResult: "",
Expand Down Expand Up @@ -768,7 +765,7 @@ func TestGetAndValidateVolume(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
tc.setupMocks()

result, err := cs.getAndValidateVolume(context.Background(), tc.volumeID, tc.linode, volContext)
result, err := cs.getAndValidateVolume(context.Background(), tc.volumeID, tc.linode)

if err != nil && !reflect.DeepEqual(tc.expectedError, err) {
t.Errorf("expected error %v, got %v", tc.expectedError, err)
Expand Down
Loading