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

fix: nil context on volume detach and state change #50

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

SLH335
Copy link
Member

@SLH335 SLH335 commented Dec 12, 2024

This PR fixes the functions detachVolume and waitOnVolumeState. These functions currently return an error due to a nil logger context being passed to the network request. This PR changes these functions to use a new empty context instead.

plugin.go Outdated
@@ -385,9 +385,9 @@ func (d plugin) getByName(name string) (*volumes.Volume, error) {
return volume, err
}

func (d plugin) detachVolume(ctx context.Context, vol *volumes.Volume) (*volumes.Volume, error) {
Copy link
Member

Choose a reason for hiding this comment

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

How about we keep context.Context as an argument to all internal functions, and pass a single context.TODO() from the main functions?

func (d plugin) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
    ctx := context.TODO()
    ...
        if vol, err = d.waitOnVolumeState(ctx, vol, "available"); err != nil {
    ...
        if vol, err = d.detachVolume(ctx, vol); err != nil {
    ...

This way, we would be able to e.g. pass a cancelable context later if needed (https://pkg.go.dev/context).

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea. Should the same instance of context.TODO() be passed to the other functions using their own instance of it at the moment?

Like in this line, for example:
https://github.com/SLH335/docker-plugin-cinder/blob/93cab39892abd699b64a6b3f67d38d5be2bed382/plugin.go#L192

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that sounds about right! 👍

@jgraichen jgraichen self-assigned this Dec 13, 2024
Copy link
Member

@jgraichen jgraichen left a comment

Choose a reason for hiding this comment

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

🤩 looks excellent!

@jgraichen jgraichen merged commit a2ee495 into openhpi-cloud:main Dec 13, 2024
1 check passed
@SLH335 SLH335 deleted the fix-context branch December 13, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants