-
Notifications
You must be signed in to change notification settings - Fork 263
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,22 +42,22 @@ | |
|
||
[[constraint]] | ||
name = "k8s.io/kubernetes" | ||
version = "v1.12.0" | ||
version = "v1.14.0" | ||
|
||
[[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]] | ||
|
@@ -68,10 +68,18 @@ | |
name = "github.com/json-iterator/go" | ||
version = "1.1.4" | ||
|
||
[[override]] | ||
name = "k8s.io/client-go" | ||
branch = "master" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need master or can kubernetes-1.14.0 work? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this actually needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when using dep ensure, I was getting a |
||
name = "gopkg.in/fsnotify.v1" | ||
|
||
[prune] | ||
non-go = true | ||
go-tests = true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does someone run the e2e tests with their own private images? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/). | ||
|
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") | ||
} |
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, also should we stick to csi spec 1.0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.1 is fine too. The resizing stuff will be unimplemented |
||
} | ||
} |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
}) | ||
|
||
}) |
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done