Skip to content
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

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

Merged
merged 5 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ $ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINode
```

## Running Kubernetes End To End tests on the NFS Driver
1) Stand up a local cluster `ALLOW_PRIVILEGED=1 hack/local-up-cluster.sh`
2) Build the nfs driver by running `make`
3) 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 .`
4) Run E2E Tests using the following command: `go test -v ./cmd/nfsplugin/ -ginkgo.v -ginkgo.progress --kubeconfig=/var/run/kubernetes/admin.kubeconfig -timeout=0`
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does someone run the e2e tests with their own private images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you would need to add the required YAML files for that private image in deploy/kubernetes, as those are the files that the e2e test uses to deploy the driver. I'll add that to the documentation.

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 see the updated documentation pointing to which yamls need to be changed

Copy link

Choose a reason for hiding this comment

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

should we build local image on each node? since the image is not publish to quay.io, if the plugin will run on each node, then should build or import the image to all nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just pushed the updated docs



## Community, discussion, contribution, and support

Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
Expand Down
34 changes: 34 additions & 0 deletions cmd/nfsplugin/nfsplugin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
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")
}
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, "")
}
43 changes: 43 additions & 0 deletions test/csi-volumes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
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.

}

// 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)
})

})
154 changes: 154 additions & 0 deletions test/nfs-testdriver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
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 (
"fmt"
. "github.com/onsi/ginkgo"
"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,
}

//Install the nfs driver from the manifests
cleanup, err := config.Framework.CreateFromManifests(nil, n.manifests...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of creating a new nfs driver for every test case, can we bring up the nfs driver once in the BeforeSuite()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the testdriver automatically creates a new namespace with a randomly generated name for each testcase, and I think the driver needs to be in that same namespace for it to be accessible by the tests. This would be hard to do in the BeforeSuite() if we don't know what the randomly generated namespace is called.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if you don't use CreateFromManifests, you can just bring up the driver directly in some default namespace. This is how we configure pd csi driver to run e2e externally and not bring up the driver for every test:

https://github.com/kubernetes/kubernetes/blob/51db0fe21a816b0818df571ad70386864d83c722/test/e2e/storage/drivers/csi.go#L444

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 that makes sense. So we would bring up the driver in a default namespace, instead of creating a new namespace for each test case right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah the driver could be brought up in the default namespace. Test case application pods will still come up in their own namespaces though

Copy link
Contributor

Choose a reason for hiding this comment

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

for now auto-deploying whatever is in the yaml folder every BeforeSuite is fine. If the user wants to test a different image version they can edit the yamls. In the future maybe there will be a flag for whether the test should deploy the driver or not if it already exists

Copy link
Contributor

Choose a reason for hiding this comment

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

@msau42 it's possible, like e.g. hostpath driver had some hardcoded paths that were changed so the yaml changed

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, I misspoke didn't mean before every test i mean before every testsuite. We agree on that already

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this is still bringing up the nfs driver for every test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I still haven't pushed it.


if err != nil {
framework.Failf("deploying %s driver: %v", n.driverInfo.Name, err)
}

return config, func() {
By(fmt.Sprintf("uninstalling %s driver", n.driverInfo.Name))
cleanup()
}
}

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