Skip to content

Commit

Permalink
Merge pull request #245 from red-hat-storage/sync_us--devel
Browse files Browse the repository at this point in the history
Syncing latest changes from upstream devel for ceph-csi
  • Loading branch information
openshift-merge-bot[bot] authored Jan 18, 2024
2 parents 705b180 + ab87045 commit 42b977c
Show file tree
Hide file tree
Showing 28 changed files with 461 additions and 1,323 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.21.5

require (
github.com/IBM/keyprotect-go-client v0.12.2
github.com/aws/aws-sdk-go v1.49.17
github.com/aws/aws-sdk-go v1.49.21
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7
github.com/ceph/ceph-csi/api v0.0.0-00010101000000-000000000000
github.com/ceph/go-ceph v0.25.0
Expand All @@ -22,7 +22,7 @@ require (
github.com/kubernetes-csi/csi-lib-utils v0.17.0
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.3.0
github.com/libopenstorage/secrets v0.0.0-20231011182615-5f4b25ceede1
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/pkg/xattr v0.4.9
github.com/prometheus/client_golang v1.18.0
Expand Down Expand Up @@ -150,11 +150,11 @@ require (
go.uber.org/zap v1.25.0 // indirect
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect
Expand Down
18 changes: 8 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.44.164/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.49.17 h1:Cc+7LgPjKeJkF2SdNo1IkpQ5Dfl9HCZEVw9OP3CPuEI=
github.com/aws/aws-sdk-go v1.49.17/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.49.21 h1:Rl8KW6HqkwzhATwvXhyr7vD4JFUMi7oXGAw9SrxxIFY=
github.com/aws/aws-sdk-go v1.49.21/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU=
github.com/aws/aws-sdk-go-v2 v1.24.1/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 h1:vF+Zgd9s+H4vOXd5BMaPWykta2a6Ih0AKLq/X6NYKn4=
Expand Down Expand Up @@ -1423,8 +1423,8 @@ github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3Ro
github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY=
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
Expand Down Expand Up @@ -1801,8 +1801,6 @@ golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1934,8 +1932,8 @@ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -2179,8 +2177,8 @@ golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
69 changes: 62 additions & 7 deletions internal/cephfs/mounter/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package mounter
import (
"context"
"fmt"
"os"
"strings"

"github.com/ceph/ceph-csi/internal/cephfs/store"
"github.com/ceph/ceph-csi/internal/util"
Expand All @@ -27,13 +29,47 @@ import (
const (
volumeMounterKernel = "kernel"
netDev = "_netdev"
kernelModule = "ceph"
)

type KernelMounter struct{}
// testErrorf can be set by unit test for enhanced error reporting.
var testErrorf = func(fmt string, args ...any) { /* do nothing */ }

func mountKernel(ctx context.Context, mountPoint string, cr *util.Credentials, volOptions *store.VolumeOptions) error {
if err := execCommandErr(ctx, "modprobe", "ceph"); err != nil {
return err
type KernelMounter interface {
Mount(
ctx context.Context,
mountPoint string,
cr *util.Credentials,
volOptions *store.VolumeOptions,
) error

Name() string
}

type kernelMounter struct {
// needsModprobe indicates that the ceph kernel module is not loaded in
// the kernel yet (or compiled into it)
needsModprobe bool
}

func NewKernelMounter() KernelMounter {
return &kernelMounter{
needsModprobe: !filesystemSupported(kernelModule),
}
}

func (m *kernelMounter) mountKernel(
ctx context.Context,
mountPoint string,
cr *util.Credentials,
volOptions *store.VolumeOptions,
) error {
if m.needsModprobe {
if err := execCommandErr(ctx, "modprobe", kernelModule); err != nil {
return err
}

m.needsModprobe = false
}

args := []string{
Expand Down Expand Up @@ -68,7 +104,7 @@ func mountKernel(ctx context.Context, mountPoint string, cr *util.Credentials, v
return err
}

func (m *KernelMounter) Mount(
func (m *kernelMounter) Mount(
ctx context.Context,
mountPoint string,
cr *util.Credentials,
Expand All @@ -78,7 +114,26 @@ func (m *KernelMounter) Mount(
return err
}

return mountKernel(ctx, mountPoint, cr, volOptions)
return m.mountKernel(ctx, mountPoint, cr, volOptions)
}

func (m *KernelMounter) Name() string { return "Ceph kernel client" }
func (m *kernelMounter) Name() string { return "Ceph kernel client" }

// filesystemSupported checks if the passed name of the filesystem is included
// in /proc/filesystems.
func filesystemSupported(fs string) bool {
// /proc/filesystems contains a list of all supported filesystems,
// either compiled into the kernel, or as loadable module.
data, err := os.ReadFile("/proc/filesystems")
if err != nil {
testErrorf("failed to read /proc/filesystems: %v", err)

return false
}

// The format of /proc/filesystems is one filesystem per line, an
// optional keyword ("nodev") followed by a tab and the name of the
// filesystem. Matching <tab>ceph<eol> for the ceph kernel module that
// supports CephFS.
return strings.Contains(string(data), "\t"+fs+"\n")
}
38 changes: 38 additions & 0 deletions internal/cephfs/mounter/kernel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2024 The Ceph-CSI Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mounter

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestFilesystemSupported(t *testing.T) {
t.Parallel()

testErrorf = func(fmt string, args ...any) {
t.Errorf(fmt, args...)
}

// "proc" is always a supported filesystem, we detect supported
// filesystems by reading from it
assert.True(t, filesystemSupported("proc"))

// "nonefs" is a made-up name, and does not exist
assert.False(t, filesystemSupported("nonefs"))
}
2 changes: 1 addition & 1 deletion internal/cephfs/mounter/volumemounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func New(volOptions *store.VolumeOptions) (VolumeMounter, error) {
case volumeMounterFuse:
return &FuseMounter{}, nil
case volumeMounterKernel:
return &KernelMounter{}, nil
return NewKernelMounter(), nil
}

return nil, fmt.Errorf("unknown mounter '%s'", chosenMounter)
Expand Down
4 changes: 2 additions & 2 deletions internal/cephfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ func (ns *NodeServer) setMountOptions(
}
volOptions.FuseMountOptions = util.MountOptionsAdd(volOptions.FuseMountOptions, configuredMountOptions)
volOptions.FuseMountOptions = util.MountOptionsAdd(volOptions.FuseMountOptions, mountOptions...)
case *mounter.KernelMounter:
case mounter.KernelMounter:
configuredMountOptions = ns.kernelMountOptions
// override of kernelMountOptions are set
if kernelMountOptions != "" {
Expand All @@ -821,7 +821,7 @@ func (ns *NodeServer) setMountOptions(
if !csicommon.MountOptionContains(strings.Split(volOptions.FuseMountOptions, ","), readOnly) {
volOptions.FuseMountOptions = util.MountOptionsAdd(volOptions.FuseMountOptions, readOnly)
}
case *mounter.KernelMounter:
case mounter.KernelMounter:
if !csicommon.MountOptionContains(strings.Split(volOptions.KernelMountOptions, ","), readOnly) {
volOptions.KernelMountOptions = util.MountOptionsAdd(volOptions.KernelMountOptions, readOnly)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cephfs/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Test_setMountOptions(t *testing.T) {
{
name: "KernelMountOptions set in cluster-1 config and not set in CLI",
ns: &NodeServer{},
mnt: mounter.VolumeMounter(&mounter.KernelMounter{}),
mnt: mounter.VolumeMounter(mounter.NewKernelMounter()),
volOptions: &store.VolumeOptions{
ClusterID: "cluster-1",
},
Expand All @@ -97,7 +97,7 @@ func Test_setMountOptions(t *testing.T) {
ns: &NodeServer{
kernelMountOptions: cliKernelMountOptions,
},
mnt: mounter.VolumeMounter(&mounter.KernelMounter{}),
mnt: mounter.VolumeMounter(mounter.NewKernelMounter()),
volOptions: &store.VolumeOptions{
ClusterID: "cluster-1",
},
Expand All @@ -119,7 +119,7 @@ func Test_setMountOptions(t *testing.T) {
ns: &NodeServer{
kernelMountOptions: cliKernelMountOptions,
},
mnt: mounter.VolumeMounter(&mounter.KernelMounter{}),
mnt: mounter.VolumeMounter(mounter.NewKernelMounter()),
volOptions: &store.VolumeOptions{
ClusterID: "cluster-2",
},
Expand Down Expand Up @@ -162,7 +162,7 @@ func Test_setMountOptions(t *testing.T) {
if !strings.Contains(tc.volOptions.FuseMountOptions, tc.want) {
t.Errorf("Set FuseMountOptions = %v Required FuseMountOptions = %v", tc.volOptions.FuseMountOptions, tc.want)
}
case *mounter.KernelMounter:
case mounter.KernelMounter:
if !strings.Contains(tc.volOptions.KernelMountOptions, tc.want) {
t.Errorf("Set KernelMountOptions = %v Required KernelMountOptions = %v", tc.volOptions.KernelMountOptions, tc.want)
}
Expand Down
Loading

0 comments on commit 42b977c

Please sign in to comment.