Skip to content

Commit

Permalink
refact log
Browse files Browse the repository at this point in the history
Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls committed Aug 28, 2024
1 parent 03a6c7f commit d93f213
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/deploy-csi-in-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function deploy_webhook() {
sudo kustomize build ${GITHUB_WORKSPACE}/deploy/kubernetes/csi-ci/webhook >> ${GITHUB_WORKSPACE}/deploy/webhook.yaml
sudo ${GITHUB_WORKSPACE}/hack/update_install_script.sh
sudo ${GITHUB_WORKSPACE}/scripts/juicefs-csi-webhook-install.sh print | sed -e "s@juicedata/juicefs-csi-driver.*\$@juicedata/juicefs-csi-driver:${dev_tag}@g" \
-e 's@/var/lib/kubelet@/var/snap/microk8s/common/var/lib/kubelet@g' -e 's@--v=5@--v=6@g' -e "s@juicedata/csi-dashboard.*\$@juicedata/csi-dashboard:${dev_tag}@g" | sudo microk8s.kubectl apply -f -
-e 's@/var/lib/kubelet@/var/snap/microk8s/common/var/lib/kubelet@g' -e "s@juicedata/csi-dashboard.*\$@juicedata/csi-dashboard:${dev_tag}@g" | sudo microk8s.kubectl apply -f -
# Wait until the deploy finish
timeout=0
while true; do
Expand Down Expand Up @@ -161,7 +161,7 @@ function deploy_webhook_provisioner() {
sudo kustomize build ${GITHUB_WORKSPACE}/deploy/kubernetes/csi-ci/webhook-provisioner > ${GITHUB_WORKSPACE}/deploy/webhook.yaml
sudo ${GITHUB_WORKSPACE}/hack/update_install_script.sh
sudo ${GITHUB_WORKSPACE}/scripts/juicefs-csi-webhook-install.sh print | sed -e "s@juicedata/juicefs-csi-driver.*\$@juicedata/juicefs-csi-driver:${dev_tag}@g" \
-e 's@/var/lib/kubelet@/var/snap/microk8s/common/var/lib/kubelet@g' -e 's@--v=5@--v=6@g' -e "s@juicedata/csi-dashboard.*\$@juicedata/csi-dashboard:${dev_tag}@g" | sudo microk8s.kubectl apply -f -
-e 's@/var/lib/kubelet@/var/snap/microk8s/common/var/lib/kubelet@g' -e "s@juicedata/csi-dashboard.*\$@juicedata/csi-dashboard:${dev_tag}@g" | sudo microk8s.kubectl apply -f -
# Wait until the deploy finish
timeout=0
while true; do
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/pod-mount-share/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --enable-manager=true
- --config=/etc/config/config.yaml
env:
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/pod-mount-share/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
- --nodeid=$(NODE_NAME)
- --leader-election
- --cache-client-conf
- --v=6
- --v=1
- --config=/etc/config/config.yaml
env:
- name: CSI_ENDPOINT
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/pod-provisioner/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --enable-manager=true
- --config=/etc/config/config.yaml
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/pod-provisioner/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --provisioner=true
- --config=/etc/config/config.yaml
- name: csi-provisioner
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/pod/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --enable-manager=true
- --config=/etc/config/config.yaml
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/pod/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --config=/etc/config/config.yaml
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/process/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --by-process=true
- --config=/etc/config/config.yaml
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/process/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --by-process=true
- --config=/etc/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --webhook=true
- --provisioner=true
- --config=/etc/config/config.yaml
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-ci/webhook/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --webhook=true
- --validating-webhook=true
- --config=/etc/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --enable-manager=true
- --config=/etc/config/config.yaml
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
- --nodeid=$(NODE_NAME)
- --leader-election
- --cache-client-conf
- --v=6
- --v=1
- --config=/etc/config/config.yaml
env:
- name: CSI_ENDPOINT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --enable-manager=true
- --config=/etc/config/config.yaml
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --provisioner=true
- --config=/etc/config/config.yaml
- name: csi-provisioner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- --endpoint=$(CSI_ENDPOINT)
- --logtostderr
- --nodeid=$(NODE_NAME)
- --v=6
- --v=1
- --enable-manager=true
- --config=/etc/config/config.yaml
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ spec:
- --logtostderr
- --nodeid=$(NODE_NAME)
- --leader-election
- --v=6
- --v=1
- --config=/etc/config/config.yaml
7 changes: 6 additions & 1 deletion pkg/controller/pod_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (p *PodDriver) SetMountInfo(mit mountInfoTable) {
}

func (p *PodDriver) Run(ctx context.Context, current *corev1.Pod) (Result, error) {
ctx = util.WithLog(ctx, podDriverLog)
podStatus := getPodStatus(current)
podDriverLog.V(1).Info("start handle pod", "namespace", current.Namespace, "name", current.Name, "status", podStatus)
// check refs in mount pod annotation first, delete ref that target pod is not found
Expand Down Expand Up @@ -910,7 +911,11 @@ func mkrMp(ctx context.Context, pod corev1.Pod) error {
return err
}
err = util.DoWithTimeout(ctx, 3*time.Second, func() error {
return os.MkdirAll(mntPath, 0777)
exist, _ := mount.PathExists(mntPath)
if !exist {
return os.MkdirAll(mntPath, 0777)
}
return nil
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/pod_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func genMountInfos() []mount.MountInfo {
}

func TestPodDriver_podReadyHandler(t *testing.T) {
defer func() { _ = os.RemoveAll("tmp") }()
fuse.InitTestFds()
Convey("Test pod ready handler", t, FailureContinues, func() {
Convey("pod ready add need recovery ", func() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ func TestNodeUnpublishVolume(t *testing.T) {
metrics := newNodeMetrics(registerer)
Convey("Test NodeUnpublishVolume", t, func() {
Convey("test normal", func() {
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()
targetPath := "/test/path"
volumeId := "vol-test"

Expand Down Expand Up @@ -516,6 +520,10 @@ func TestNodeUnpublishVolume(t *testing.T) {
targetPath := "/test/path"
volumeId := "vol-test"

patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()
mockCtl := gomock.NewController(t)
defer mockCtl.Finish()

Expand Down
7 changes: 6 additions & 1 deletion pkg/fuse/passfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ func (fs *Fds) GetFdAddress(ctx context.Context, podHashVal string) (string, err
addressInPod := path.Join(fs.basePath, "fuse_fd_csi_comm.sock")
// mkdir parent
err := util.DoWithTimeout(ctx, 2*time.Second, func() error {
return os.MkdirAll(path.Join(fs.basePath, podHashVal), 0777)
parentPath := path.Join(fs.basePath, podHashVal)
exist, _ := k8sMount.PathExists(parentPath)
if !exist {
return os.MkdirAll(parentPath, 0777)
}
return nil
})
if err != nil {
return "", err
Expand Down
28 changes: 28 additions & 0 deletions pkg/juicefs/juicefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return true, nil
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down Expand Up @@ -673,6 +677,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return true, errors.New("test")
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down Expand Up @@ -714,6 +722,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return true, nil
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down Expand Up @@ -750,6 +762,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return true, nil
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down Expand Up @@ -786,6 +802,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return true, nil
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down Expand Up @@ -822,6 +842,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return false, nil
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down Expand Up @@ -857,6 +881,10 @@ func Test_juicefs_MountFs(t *testing.T) {
return false, nil
})
defer patch1.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand Down
2 changes: 2 additions & 0 deletions pkg/juicefs/mount/builder/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package builder
import (
"encoding/json"
"fmt"
"os"
"path"
"reflect"
"testing"
Expand Down Expand Up @@ -208,6 +209,7 @@ func Test_getCacheDirVolumes(t *testing.T) {
}

func TestNewMountPod(t *testing.T) {
defer func() { _ = os.RemoveAll("tmp") }()
fuse.InitTestFds()
config.NodeName = "node"
config.Namespace = ""
Expand Down
6 changes: 5 additions & 1 deletion pkg/juicefs/mount/pod_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ func (p *PodMount) createOrAddRef(ctx context.Context, podName string, jfsSettin
jfsSetting.SecretName = fmt.Sprintf("juicefs-%s-secret", jfsSetting.UniqueId)
// mkdir mountpath
err = util.DoWithTimeout(ctx, 3*time.Second, func() error {
return os.MkdirAll(jfsSetting.MountPath, 0777)
exist, _ := k8sMount.PathExists(jfsSetting.MountPath)
if !exist {
return os.MkdirAll(jfsSetting.MountPath, 0777)
}
return nil
})
if err != nil {
return
Expand Down
5 changes: 5 additions & 0 deletions pkg/juicefs/mount/pod_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func TestAddRefOfMountWithMock(t *testing.T) {
}

func TestJUmount(t *testing.T) {
defer func() { _ = os.RemoveAll("tmp") }()
fakeClientSet := fake.NewSimpleClientset()
fuse.InitTestFds()

Expand Down Expand Up @@ -740,6 +741,10 @@ func TestJMount(t *testing.T) {
return mocks.FakeFileInfoIno1{}, nil
})
defer patch5.Reset()
patch := ApplyFunc(os.MkdirAll, func(path string, perm os.FileMode) error {
return nil
})
defer patch.Reset()

fakeClient := fake.NewSimpleClientset()
p := NewPodMount(&k8sclient.K8sClient{Interface: fakeClient}, mount.SafeFormatAndMount{
Expand Down

0 comments on commit d93f213

Please sign in to comment.