Skip to content

Added a waitforattach verification at the end of ControllerPublishVolume #44

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

Merged
merged 1 commit into from
Jul 3, 2018
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
6 changes: 6 additions & 0 deletions pkg/gce-cloud-provider/fake-gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type FakeCloudProvider struct {
instances map[string]*compute.Instance
}

var _ GCECompute = &FakeCloudProvider{}

func FakeCreateCloudProvider(project, zone string) (*FakeCloudProvider, error) {
return &FakeCloudProvider{
project: project,
Expand Down Expand Up @@ -156,6 +158,10 @@ func (cloud *FakeCloudProvider) GetDiskTypeURI(zone, diskType string) string {
return ""
}

func (cloud *FakeCloudProvider) WaitForAttach(ctx context.Context, zone, diskName, instanceName string) error {
return nil
}

// Instance Methods
func (cloud *FakeCloudProvider) InsertInstance(instance *compute.Instance, instanceName string) {
cloud.instances[instanceName] = instance
Expand Down
22 changes: 22 additions & 0 deletions pkg/gce-cloud-provider/gce-compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type GCECompute interface {
DetachDisk(ctx context.Context, volumeZone, instanceName, volumeName string) (*compute.Operation, error)
GetDiskSourceURI(disk *compute.Disk, zone string) string
GetDiskTypeURI(zone, diskType string) string
WaitForAttach(ctx context.Context, zone, diskName, instanceName string) error
// Instance Methods
GetInstanceOrError(ctx context.Context, instanceZone, instanceName string) (*compute.Instance, error)
// Operation Methods
Expand Down Expand Up @@ -158,6 +159,27 @@ func (cloud *CloudProvider) WaitForOp(ctx context.Context, op *compute.Operation
})
}

func (cloud *CloudProvider) WaitForAttach(ctx context.Context, zone, diskName, instanceName string) error {
return wait.Poll(5*time.Second, 2*time.Minute, func() (bool, error) {
disk, err := cloud.GetDiskOrError(ctx, zone, diskName)
if err != nil {
glog.Errorf("GetDiskOrError failed to get disk: %v", err)
return false, err
}

if disk == nil {
return false, fmt.Errorf("Disk %v could not be found in zone %v", diskName, zone)
}

for _, user := range disk.Users {
if strings.Contains(user, instanceName) && strings.Contains(user, zone) {
return true, nil
}
}
return false, nil
})
}

func opIsDone(op *compute.Operation) bool {
return op != nil && op.Status == "DONE"
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/gce-cloud-provider/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type CloudProvider struct {
zone string
}

var _ GCECompute = &CloudProvider{}

func CreateCloudProvider() (*CloudProvider, error) {
svc, err := createCloudService()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/gce-pd-csi-driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
return nil, status.Error(codes.Internal, fmt.Sprintf("unknown Attach operation error: %v", err))
}

err = gceCS.CloudProvider.WaitForAttach(ctx, volumeZone, disk.Name, nodeID)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("unknown WaitForAttach error: %v", err))
}

glog.Infof("Disk %v attached to instance %v successfully", disk.Name, nodeID)
return pubVolResp, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/gce-pd-csi-driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func TestCreateVolumeArguments(t *testing.T) {
}

// Test volume already exists

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmmm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#46

// Test volume with op pending

// Test DeleteVolume
Expand Down