Skip to content

add Kubernetes End to End tests to the NFS Driver #10

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

Merged
merged 5 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
824 changes: 714 additions & 110 deletions Gopkg.lock

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@

[[constraint]]
name = "k8s.io/kubernetes"
version = "v1.12.0"
version = "v1.14.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the vendor updates into a separate commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


[[override]]
name = "k8s.io/kubernetes"
version = "v1.12.0"
version = "v1.14.0"

[[override]]
version = "kubernetes-1.12.0"
version = "kubernetes-1.14.0"
name = "k8s.io/api"

[[override]]
version = "kubernetes-1.12.0"
version = "kubernetes-1.14.0"
name = "k8s.io/apiserver"

[[override]]
version = "kubernetes-1.12.0"
version = "kubernetes-1.14.0"
name = "k8s.io/apiextensions-apiserver"

[[override]]
Expand All @@ -68,10 +68,18 @@
name = "github.com/json-iterator/go"
version = "1.1.4"

[[override]]
name = "k8s.io/client-go"
branch = "master"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need master or can kubernetes-1.14.0 work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having an issue similar to this, but using master solved it. I'll look more into it to see if we can avoid using master.


[[override]]
name = "gopkg.in/square/go-jose.v2"
version = "2.1.7"

[[override]]
source = "https://github.com/fsnotify/fsnotify/archive/v1.4.7.tar.gz"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this actually needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using dep ensure, I was getting a panic: version queue is empty error, and adding this solved it. Reference: golang/dep#1799

name = "gopkg.in/fsnotify.v1"

[prune]
non-go = true
go-tests = true
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ nfstestvol
$ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINode
```
## Running Kubernetes End To End tests on an NFS Driver

First, stand up a local cluster `ALLOW_PRIVILEGED=1 hack/local-up-cluster.sh` (from your Kubernetes repo)
For Fedora/RHEL clusters, the following might be required:
```
sudo chown -R $USER:$USER /var/run/kubernetes/
sudo chown -R $USER:$USER /var/lib/kubelet
sudo chcon -R -t svirt_sandbox_file_t /var/lib/kubelet
```
If you are plannig to test using your own private image, you could either install your nfs driver using your own set of YAML files, or edit the existing YAML files to use that private image.

When using the [existing set of YAML files](https://github.com/kubernetes-csi/csi-driver-nfs/tree/master/deploy/kubernetes), you would edit the [csi-attacher-nfsplugin.yaml](https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/kubernetes/csi-attacher-nfsplugin.yaml#L46) and [csi-nodeplugin-nfsplugin.yaml](https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/kubernetes/csi-nodeplugin-nfsplugin.yaml#L45) files to include your private image instead of the default one. After editing these files, skip to step 3 of the following steps.

If you already have a driver installed, skip to step 4 of the following steps.

1) Build the nfs driver by running `make`
2) Create NFS Driver Image, where the image tag would be whatever that is required by your YAML deployment files `docker build -t quay.io/k8scsi/nfsplugin:v1.0.0 .`
3) Install the Driver: `kubectl create -f deploy/kubernetes`
4) Build E2E test binary: `make build-tests`
5) Run E2E Tests using the following command: `./bin/tests --ginkgo.v --ginkgo.progress --kubeconfig=/var/run/kubernetes/admin.kubeconfig`


## Community, discussion, contribution, and support

Expand Down
38 changes: 38 additions & 0 deletions cmd/tests/nfs-e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2019 The Kubernetes 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 main

import (
"flag"
_ "github.com/kubernetes-csi/csi-driver-nfs/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/kubernetes/test/e2e/framework"
"testing"
)

func init() {
framework.HandleFlags()
framework.AfterReadingAllFlags(&framework.TestContext)
}

func Test(t *testing.T) {
flag.Parse()
RegisterFailHandler(Fail)
RunSpecs(t, "CSI Suite")
}

func main() {
Test(&testing.T{})
}
23 changes: 23 additions & 0 deletions pkg/nfs/controllerserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package nfs

import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/drivers/pkg/csi-common"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type ControllerServer struct {
*csicommon.DefaultControllerServer
}

func (cs ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func getControllerServer(csiDriver *csicommon.CSIDriver) ControllerServer {
return ControllerServer{
csicommon.NewDefaultControllerServer(csiDriver),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've updated csicommon for csi spec 1.1 (and we don't intend to. We want to deprecate csicommon).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still trying to move csicommon to kubernetes-csi/csi-lib-common?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we're just going to deprecate it. It doesn't seem to provide much value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, also should we stick to csi spec 1.0?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.1 is fine too. The resizing stuff will be unimplemented

}
}
2 changes: 1 addition & 1 deletion pkg/nfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (d *driver) Run() {
csicommon.NewDefaultIdentityServer(d.csiDriver),
// NFS plugin has not implemented ControllerServer
// using default controllerserver.
csicommon.NewDefaultControllerServer(d.csiDriver),
getControllerServer(d.csiDriver),
NewNodeServer(d))
s.Wait()
}
10 changes: 6 additions & 4 deletions pkg/nfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ import (
"strings"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/drivers/pkg/csi-common"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume/util"

"github.com/kubernetes-csi/drivers/pkg/csi-common"
)

type nodeServer struct {
Expand Down Expand Up @@ -92,7 +90,7 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.NotFound, "Volume not mounted")
}

err = util.UnmountPath(req.GetTargetPath(), mount.New(""))
err = mount.CleanupMountPoint(req.GetTargetPath(), mount.New(""), false)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand All @@ -107,3 +105,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
return &csi.NodeStageVolumeResponse{}, nil
}

func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
45 changes: 45 additions & 0 deletions test/csi-volumes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2019 The Kubernetes 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 test

import (
. "github.com/onsi/ginkgo"
_ "github.com/onsi/gomega"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/testfiles"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
"k8s.io/kubernetes/test/e2e/storage/utils"
"path"
)

var CSITestSuites = []func() testsuites.TestSuite{
testsuites.InitVolumesTestSuite,
testsuites.InitVolumeIOTestSuite,
testsuites.InitVolumeModeTestSuite,
testsuites.InitSubPathTestSuite,
testsuites.InitProvisioningTestSuite,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to define a global variable in the test framework that contains all the test suites? That way drivers don't need to manually copy them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that would be useful. Would there be any case where a driver would not want to run some of these test suites?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't need to. The test cases are supposed to check for driver capabilities and only run the tests that the driver can support.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have Snapshot and MultiVolume test suites, although they don't seem applicable to this nfs driver. Should be include them anyway and comment them out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya sure, since this would be used as an example right. Also, I think MultiVolume testsuite is not in 1.14?

Copy link
Contributor Author

@mathu97 mathu97 Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it doesn't matter as it'll still be commented out.

//testsuites.InitSnapshottableTestSuite,
//testsuites.InitMultiVolumeTestSuite,
}

// This executes testSuites for csi volumes.
var _ = utils.SIGDescribe("CSI Volumes", func() {
testfiles.AddFileSource(testfiles.RootFileSource{Root: path.Join(framework.TestContext.RepoRoot, "../../deploy/kubernetes/")})

curDriver := NFSdriver()
Context(testsuites.GetDriverNameWithFeatureTags(curDriver), func() {
testsuites.DefineTestSuite(curDriver, CSITestSuites)
})

})
142 changes: 142 additions & 0 deletions test/nfs-testdriver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
Copyright 2019 The Kubernetes 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 test

import (
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
"k8s.io/kubernetes/test/e2e/storage/testsuites"
)

type nfsDriver struct {
driverInfo testsuites.DriverInfo
manifests []string
}

var NFSdriver = InitNFSDriver

type nfsVolume struct {
serverIP string
serverPod *v1.Pod
f *framework.Framework
}

// initNFSDriver returns nfsDriver that implements TestDriver interface
func initNFSDriver(name string, manifests ...string) testsuites.TestDriver {
return &nfsDriver{
driverInfo: testsuites.DriverInfo{
Name: name,
MaxFileSize: testpatterns.FileSizeLarge,
SupportedFsType: sets.NewString(
"", // Default fsType
),
Capabilities: map[testsuites.Capability]bool{
testsuites.CapPersistence: true,
testsuites.CapExec: true,
},
},
manifests: manifests,
}
}

func InitNFSDriver() testsuites.TestDriver {

return initNFSDriver("csi-nfsplugin",
"csi-attacher-nfsplugin.yaml",
"csi-attacher-rbac.yaml",
"csi-nodeplugin-nfsplugin.yaml",
"csi-nodeplugin-rbac.yaml")

}

var _ testsuites.TestDriver = &nfsDriver{}
var _ testsuites.PreprovisionedVolumeTestDriver = &nfsDriver{}
var _ testsuites.PreprovisionedPVTestDriver = &nfsDriver{}

func (n *nfsDriver) GetDriverInfo() *testsuites.DriverInfo {
return &n.driverInfo
}

func (n *nfsDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
if pattern.VolType == testpatterns.DynamicPV {
framework.Skipf("NFS Driver does not support dynamic provisioning -- skipping")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future it may be cool to add something like the nfs-client provisioner to the sample driver, and then we can unlock these test cases as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

}
}

func (n *nfsDriver) GetPersistentVolumeSource(readOnly bool, fsType string, volume testsuites.TestVolume) (*v1.PersistentVolumeSource, *v1.VolumeNodeAffinity) {
nv, _ := volume.(*nfsVolume)
return &v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Driver: n.driverInfo.Name,
VolumeHandle: "nfs-vol",
VolumeAttributes: map[string]string{
"server": nv.serverIP,
"share": "/",
"readOnly": "true",
},
},
}, nil
}

func (n *nfsDriver) PrepareTest(f *framework.Framework) (*testsuites.PerTestConfig, func()) {
config := &testsuites.PerTestConfig{
Driver: n,
Prefix: "nfs",
Framework: f,
}

return config, func() {}
}

func (n *nfsDriver) CreateVolume(config *testsuites.PerTestConfig, volType testpatterns.TestVolType) testsuites.TestVolume {
f := config.Framework
cs := f.ClientSet
ns := f.Namespace

switch volType {
case testpatterns.InlineVolume:
fallthrough
case testpatterns.PreprovisionedPV:

//Create nfs server pod
c := framework.VolumeTestConfig{
Namespace: ns.Name,
Prefix: "nfs",
ServerImage: "gcr.io/kubernetes-e2e-test-images/volume/nfs:1.0",
ServerPorts: []int{2049},
ServerVolumes: map[string]string{"": "/exports"},
ServerReadyMessage: "NFS started",
}
config.ServerConfig = &c
serverPod, serverIP := framework.CreateStorageServer(cs, c)

return &nfsVolume{
serverIP: serverIP,
serverPod: serverPod,
f: f,
}

case testpatterns.DynamicPV:
// Do nothing
default:
framework.Failf("Unsupported volType:%v is specified", volType)
}
return nil
}

func (v *nfsVolume) DeleteVolume() {
framework.CleanUpVolumeServer(v.f, v.serverPod)
}
12 changes: 12 additions & 0 deletions vendor/github.com/PuerkitoBio/purell/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading