Skip to content

Commit

Permalink
cni should handler unmont volume, when delete pod. (#1873)
Browse files Browse the repository at this point in the history
Co-authored-by: wanglong <wang.long@99cloud.net>
  • Loading branch information
wlooppy and wanglong authored Sep 1, 2022
1 parent 031ed03 commit 14898dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/greenpau/ovsdb v1.0.2
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.3.0
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875
github.com/moby/sys/mountinfo v0.6.0
github.com/neverlee/keymutex v0.0.0-20171121013845-f593aa834bf9
github.com/oilbeater/go-ping v0.0.0-20200413021620-332b7197c5b5
github.com/onsi/ginkgo/v2 v2.1.5
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0Gq
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/moby/sys/mountinfo v0.6.0 h1:gUDhXQx58YNrpHlK4nSL+7y2pxFZkUcXqzFDKWdC0Oo=
github.com/moby/sys/mountinfo v0.6.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
Expand Down
9 changes: 9 additions & 0 deletions pkg/daemon/handler_linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package daemon

import (
"errors"
"fmt"
"io/fs"
"os"
"strings"
"syscall"
Expand All @@ -12,6 +14,7 @@ import (

"github.com/kubeovn/kube-ovn/pkg/request"
"github.com/kubeovn/kube-ovn/pkg/util"
"github.com/moby/sys/mountinfo"
)

func (csh cniServerHandler) validatePodRequest(req *request.CniRequest) error {
Expand Down Expand Up @@ -63,6 +66,12 @@ func removeShortSharedDir(pod *v1.Pod, volumeName string) (err error) {
klog.Errorf("shared directory %s does not exist to unmount, %s", sharedDir, err)
return nil
}

foundMount, err := mountinfo.Mounted(sharedDir)
if errors.Is(err, fs.ErrNotExist) || (err == nil && !foundMount) {
klog.Infof("volume: %s not mounted, no need to unmount", sharedDir)
return nil
}
err = unix.Unmount(sharedDir, 0)
if err != nil {
klog.Errorf("Failed to unmount dir: %v", err)
Expand Down

0 comments on commit 14898dd

Please sign in to comment.