nfs: store the calling Context in NFSVolume

NFSVolume instances are short lived, they only extist for a certain gRPC
procedure. It is easier to store the calling Context in the NFSVolume
struct, than to pass it to some of the functions that require it.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2022-03-18 10:49:03 +01:00 committed by mergify[bot]
parent 3d0c4e0659
commit 010fd816dd
2 changed files with 10 additions and 6 deletions

View File

@ -91,7 +91,7 @@ func (cs *Server) CreateVolume(
}
defer cr.DeleteCredentials()
nfsVolume, err := NewNFSVolume(backend.VolumeId)
nfsVolume, err := NewNFSVolume(ctx, backend.VolumeId)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@ -128,7 +128,7 @@ func (cs *Server) DeleteVolume(
}
defer cr.DeleteCredentials()
nfsVolume, err := NewNFSVolume(req.GetVolumeId())
nfsVolume, err := NewNFSVolume(ctx, req.GetVolumeId())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

View File

@ -30,6 +30,9 @@ import (
// modify and delete the NFS-exported CephFS volume. Instances of this struct
// are short lived, they only exist as long as a CSI-procedure is active.
type NFSVolume struct {
// ctx is the context for this short living volume object
ctx context.Context
volumeID string
clusterID string
mons string
@ -41,7 +44,7 @@ type NFSVolume struct {
// NewNFSVolume create a new NFSVolume instance for the currently executing
// CSI-procedure.
func NewNFSVolume(volumeID string) (*NFSVolume, error) {
func NewNFSVolume(ctx context.Context, volumeID string) (*NFSVolume, error) {
// TODO: validate volume.VolumeContext parameters
vi := util.CSIIdentifier{}
@ -51,6 +54,7 @@ func NewNFSVolume(volumeID string) (*NFSVolume, error) {
}
return &NFSVolume{
ctx: ctx,
volumeID: volumeID,
}, nil
}
@ -117,7 +121,7 @@ func (nv *NFSVolume) CreateExport(backend *csi.Volume) error {
}
// TODO: use new go-ceph API
_, stderr, err := util.ExecCommand(context.TODO(), "ceph", args...)
_, stderr, err := util.ExecCommand(nv.ctx, "ceph", args...)
if err != nil {
return fmt.Errorf("executing ceph export command failed (%w): %s", err, stderr)
}
@ -142,7 +146,7 @@ func (nv *NFSVolume) getNFSCluster() (string, error) {
"ls",
}
nfsCluster, _, err := util.ExecCommand(context.TODO(), "ceph", args...)
nfsCluster, _, err := util.ExecCommand(nv.ctx, "ceph", args...)
if err != nil {
return "", fmt.Errorf("executing ceph export command failed: %w", err)
}
@ -174,7 +178,7 @@ func (nv *NFSVolume) DeleteExport() error {
}
// TODO: use new go-ceph API
_, stderr, err := util.ExecCommand(context.TODO(), "ceph", args...)
_, stderr, err := util.ExecCommand(nv.ctx, "ceph", args...)
if err != nil {
return fmt.Errorf("executing ceph export command failed (%w): %s", err, stderr)
}