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

mounter/proxy: avoid deprecated func and cleanups #1275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 25 additions & 33 deletions pkg/mounter/proxy/server/ossfs/mount_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/proxy"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/proxy/server"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/mount-utils"
)
Expand All @@ -23,14 +22,14 @@ func init() {
}

type MountHandler struct {
pids *sync.Map
pids sync.Map
wg sync.WaitGroup
raw mount.Interface
}

func NewMountHandler() *MountHandler {
return &MountHandler{
pids: new(sync.Map),
pids: sync.Map{},
raw: mount.New(""),
}
}
Expand Down Expand Up @@ -72,8 +71,8 @@ func (h *MountHandler) Mount(ctx context.Context, req *proxy.MountRequest) error
klog.InfoS("Started ossfs", "pid", pid, "args", args)

ossfsExited := make(chan error, 1)
h.wg.Add(1)
go func() {
h.wg.Add(1)
defer h.wg.Done()

h.pids.Store(pid, cmd)
Expand All @@ -92,48 +91,41 @@ func (h *MountHandler) Mount(ctx context.Context, req *proxy.MountRequest) error
close(ossfsExited)
}()

err = wait.PollInfiniteWithContext(ctx, time.Second, func(ctx context.Context) (done bool, err error) {
for {
select {
case err := <-ossfsExited:
// TODO: collect ossfs outputs to return in error message
if err != nil {
return false, fmt.Errorf("ossfs exited: %w", err)
return fmt.Errorf("ossfs exited: %w", err)
}
return false, fmt.Errorf("ossfs exited")
default:
return fmt.Errorf("ossfs exited")
case <-ctx.Done():
// terminate ossfs process when timeout
terr := cmd.Process.Signal(syscall.SIGTERM)
if terr != nil {
klog.ErrorS(err, "Failed to terminate ossfs", "pid", pid)
}
select {
case <-ossfsExited:
case <-time.After(time.Second * 2):
kerr := cmd.Process.Kill()
if kerr != nil && !errors.Is(kerr, os.ErrProcessDone) {
klog.ErrorS(err, "Failed to kill ossfs", "pid", pid)
}
}
return ctx.Err()
case <-time.After(time.Second):
notMnt, err := h.raw.IsLikelyNotMountPoint(target)
if err != nil {
klog.ErrorS(err, "check mountpoint", "mountpoint", target)
return false, nil
continue
}
if !notMnt {
klog.InfoS("Successfully mounted", "mountpoint", target)
return true, nil
}
return false, nil
}
})

if err == nil {
return nil
}

if errors.Is(err, wait.ErrWaitTimeout) {
// terminate ossfs process when timeout
terr := cmd.Process.Signal(syscall.SIGTERM)
if terr != nil {
klog.ErrorS(err, "Failed to terminate ossfs", "pid", pid)
}
select {
case <-ossfsExited:
case <-time.After(time.Second * 2):
kerr := cmd.Process.Kill()
if kerr != nil && errors.Is(kerr, os.ErrProcessDone) {
klog.ErrorS(err, "Failed to kill ossfs", "pid", pid)
return nil
}
}
}
return err
}

func (h *MountHandler) Terminate() {
Expand All @@ -143,7 +135,7 @@ func (h *MountHandler) Terminate() {
if err != nil {
klog.ErrorS(err, "Failed to terminate ossfs", "pid", key)
}
klog.V(4).InfoS("Sended sigterm", "pid", key)
klog.V(4).InfoS("Sent sigterm", "pid", key)
return true
})
// wait all ossfs processes to exit
Expand Down