Fix CSI node bind mount and publish to correct image registry.

Use k8s mount-utils for bind mounts so the pod target directory is created
before mounting, and push CI images to ghcr.io/kubelancloud/kks-csi-plugin
to match the deployed chart.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-06 08:50:32 +03:30
co-authored by Cursor
parent 7321058edb
commit 62c26f6fda
6 changed files with 65 additions and 9 deletions
+9 -3
View File
@@ -107,9 +107,15 @@ func cleanupMountPoint(target string, mounter *mount.SafeFormatAndMount) error {
}
func bindMount(source, target string) error {
out, err := exec.Command("mount", "--bind", source, target).CombinedOutput()
if err != nil {
return fmt.Errorf("bind mount %s -> %s: %w: %s", source, target, err, strings.TrimSpace(string(out)))
if !isMounted(source) {
return fmt.Errorf("staging path %s is not mounted", source)
}
if isMounted(target) {
return nil
}
mounter := mount.New("")
if err := mounter.Mount(source, target, "", []string{"bind"}); err != nil {
return fmt.Errorf("bind mount %s -> %s: %w", source, target, err)
}
return nil
}
+48
View File
@@ -0,0 +1,48 @@
//go:build linux
package driver
import (
"os"
"path/filepath"
"testing"
)
func TestBindMountCreatesTargetAndIsIdempotent(t *testing.T) {
t.Parallel()
root := t.TempDir()
source := filepath.Join(root, "globalmount")
target := filepath.Join(root, "pods", "test", "mount")
if err := os.MkdirAll(source, 0o755); err != nil {
t.Fatalf("mkdir source: %v", err)
}
if err := os.WriteFile(filepath.Join(source, "probe"), []byte("ok"), 0o644); err != nil {
t.Fatalf("write probe file: %v", err)
}
mounter := newMounter()
if err := mounter.Mount("tmpfs", source, "tmpfs", []string{}); err != nil {
t.Fatalf("mount tmpfs at source: %v", err)
}
t.Cleanup(func() {
_ = cleanupMountPoint(source, mounter)
})
if err := bindMount(source, target); err != nil {
t.Fatalf("first bindMount failed: %v", err)
}
t.Cleanup(func() {
_ = cleanupMountPoint(target, mounter)
})
if _, err := os.Stat(target); err != nil {
t.Fatalf("target mount path missing: %v", err)
}
if _, err := os.Stat(filepath.Join(target, "probe")); err != nil {
t.Fatalf("bind mount did not expose source contents: %v", err)
}
if err := bindMount(source, target); err != nil {
t.Fatalf("second bindMount failed: %v", err)
}
}
+2 -3
View File
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
@@ -91,8 +90,8 @@ func (s *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublish
return nil, invalidArgument("staging target path is required")
}
if err := os.MkdirAll(filepath.Dir(req.GetTargetPath()), 0o755); err != nil {
return nil, internalError(err)
if !isMounted(req.GetStagingTargetPath()) {
return nil, internalError(fmt.Errorf("staging path %s is not mounted", req.GetStagingTargetPath()))
}
if err := bindMount(req.GetStagingTargetPath(), req.GetTargetPath()); err != nil {