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 2 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
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")
}
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

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

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

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