mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
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:
parent
3d0c4e0659
commit
010fd816dd
@ -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())
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user