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 ISCSI Driver #17

Closed
wants to merge 5 commits into from
Closed
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
  •  
  •  
  •  
629 changes: 617 additions & 12 deletions Gopkg.lock

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

[[constraint]]
name = "k8s.io/kubernetes"
version = "v1.14.0"
branch = "release-1.14"

[[override]]
version = "kubernetes-1.14.0"
Expand Down Expand Up @@ -87,3 +87,27 @@
[[constraint]]
name = "github.com/kubernetes-csi/csi-lib-utils"
version = "0.2.0"

[[override]]
name = "k8s.io/client-go"
version = "kubernetes-1.14.0"

[[override]]
name = "k8s.io/kube-aggregator"
version = "kubernetes-1.14.0"

[[override]]
name = "k8s.io/cli-runtime"
version = "kubernetes-1.14.0"

[[override]]
name = "k8s.io/component-base"
version = "kubernetes-1.14.0"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.14.0"

[[override]]
source = "https://github.com/fsnotify/fsnotify/archive/v1.4.7.tar.gz"
name = "gopkg.in/fsnotify.v1"
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ $ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINode
```

## Running Kubernetes End To End tests on an ISCSI 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 ISCSI 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-iscsi/tree/master/deploy/kubernetes), you would edit the [csi-attacher-iscsiplugin.yaml](https://github.com/kubernetes-csi/csi-driver-iscsi/blob/master/deploy/kubernetes/csi-attacher-iscsiplugin.yaml#L46) and [csi-nodeplugin-iscsiplugin.yaml](https://github.com/kubernetes-csi/csi-driver-iscsi/blob/master/deploy/kubernetes/csi-nodeplugin-iscsiplugin.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 ISCSI driver by running `make`
2) Create ISCSI Driver Image, where the image tag would be whatever that is required by your YAML deployment files `docker build -t quay.io/k8scsi/iscsiplugin: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

Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
Expand Down
39 changes: 39 additions & 0 deletions cmd/tests/iscsi-e2e.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
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"
"testing"

_ "github.com/kubernetes-csi/csi-driver-iscsi/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/kubernetes/test/e2e/framework"
)

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{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
mountPath: /csi

- name: iscsi
image: iscsiplugin:latest
image: quay.io/k8scsi/iscsiplugin:v1.0.0
args :
- "--nodeid=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: iscsiplugin:latest
image: quay.io/k8scsi/iscsiplugin:v1.0.0
args :
- "--nodeid=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"
Expand Down
2 changes: 1 addition & 1 deletion pkg/iscsi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type driver struct {
}

const (
driverName = "ISCSI"
driverName = "csi-iscsiplugin"
)

var (
Expand Down
46 changes: 46 additions & 0 deletions test/csi-volumes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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 (
"path"

. "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"
)

var CSITestSuites = []func() testsuites.TestSuite{
testsuites.InitVolumesTestSuite,
testsuites.InitVolumeIOTestSuite,
testsuites.InitVolumeModeTestSuite,
testsuites.InitSubPathTestSuite,
testsuites.InitProvisioningTestSuite,
//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 := InitISCSIDriver()
Context(testsuites.GetDriverNameWithFeatureTags(curDriver), func() {
testsuites.DefineTestSuite(curDriver, CSITestSuites)
})

})
139 changes: 139 additions & 0 deletions test/iscsi-testdriver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
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 iSCSIDriver struct {
driverInfo testsuites.DriverInfo
manifests []string
}

var ISCSIdriver = InitISCSIDriver

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

// initISCSIDriver returns ISCSIDriver that implements TestDriver interface
func initISCSIDriver(name string, manifests ...string) testsuites.TestDriver {
return &iSCSIDriver{
driverInfo: testsuites.DriverInfo{
Name: name,
MaxFileSize: testpatterns.FileSizeMedium,
SupportedFsType: sets.NewString(
"", // Default fsType
"ext2",
// TODO: fix iSCSI driver can work with ext3
//"ext3",
"ext4",
),
Capabilities: map[testsuites.Capability]bool{
testsuites.CapPersistence: true,
testsuites.CapFsGroup: true,
testsuites.CapExec: true,
},
},
manifests: manifests,
}
}

func InitISCSIDriver() testsuites.TestDriver {

return initISCSIDriver("csi-iscsiplugin",
"csi-attacher-iscsiplugin.yaml",
"csi-attacher-rbac.yaml",
"csi-nodeplugin-iscsiplugin.yaml",
"csi-nodeplugin-rbac.yaml")

}

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

func (i *iSCSIDriver) GetDriverInfo() *testsuites.DriverInfo {
return &i.driverInfo
}

func (i *iSCSIDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) {
if pattern.VolType == testpatterns.DynamicPV {
framework.Skipf("iSCSI Driver does not support dynamic provisioning -- skipping")
}
}

func (i *iSCSIDriver) GetPersistentVolumeSource(readOnly bool, fsType string, volume testsuites.TestVolume) (*v1.PersistentVolumeSource, *v1.VolumeNodeAffinity) {
iv, _ := volume.(*iSCSIVolume)
volSource := v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Driver: i.driverInfo.Name,
VolumeHandle: "iscsi-vol",
VolumeAttributes: map[string]string{
"targetPortal": iv.serverIP + ":3260",
"portals": "[]",
"iqn": iv.iqn,
"lun": "0",
"iscsiInterface": "default",
"discoveryCHAPAuth": "false",
"sessionCHAPAuth": "false",
},
},
}

if fsType != "" {
volSource.CSI.FSType = fsType
}

return &volSource, nil
}

func (i *iSCSIDriver) PrepareTest(f *framework.Framework) (*testsuites.PerTestConfig, func()) {
config := &testsuites.PerTestConfig{
Driver: i,
Prefix: "iscsi",
Framework: f,
}

return config, func() {}
}

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

iscsiConfig, serverPod, serverIP := framework.NewISCSIServer(cs, ns.Name)
config.ServerConfig = &iscsiConfig

return &iSCSIVolume{
serverPod: serverPod,
serverIP: serverIP,
// from k8s test/images/volume/iscsi/initiatorname.iscsi
iqn: "iqn.2003-01.org.linux-iscsi.f21.x8664:sn.4b0aae584f7c",
f: f,
}
}

func (v *iSCSIVolume) DeleteVolume() {
framework.CleanUpVolumeServer(v.f, v.serverPod)
}

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

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

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