Refractor E2E to reduce code duplication

Updated E2E to reduce code duplication
and create resouces in different namespaces.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-02-26 13:41:05 +05:30 committed by mergify[bot]
parent 4690dc6ea7
commit e788328750
8 changed files with 269 additions and 107 deletions

View File

@ -72,7 +72,7 @@ are available while running tests:
| flag | description | | flag | description |
| ----------------- | ----------------------------------------------------------------------------- | | ----------------- | ----------------------------------------------------------------------------- |
| deploy-timeout | Timeout to wait for created kubernetes resources (default: 10) | | deploy-timeout | Timeout to wait for created kubernetes resources (default: 10 minutes) |
| deploy-cephfs | Deploy cephfs csi driver as part of E2E (default: true) | | deploy-cephfs | Deploy cephfs csi driver as part of E2E (default: true) |
| deploy-rbd | Deploy rbd csi driver as part of E2E (default: true) | | deploy-rbd | Deploy rbd csi driver as part of E2E (default: true) |
| cephcsi-namespace | The namespace in which cephcsi driver will be created (default: "default") | | cephcsi-namespace | The namespace in which cephcsi driver will be created (default: "default") |

View File

@ -2,13 +2,9 @@ package e2e
import ( import (
"fmt" "fmt"
"time"
. "github.com/onsi/ginkgo" // nolint . "github.com/onsi/ginkgo" // nolint
v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log" e2elog "k8s.io/kubernetes/test/e2e/framework/log"
@ -29,42 +25,86 @@ var (
func deployCephfsPlugin() { func deployCephfsPlugin() {
// delete objects deployed by rook // delete objects deployed by rook
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", cephfsDirPath+cephfsProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", cephfsDirPath+cephfsNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) data, err := replaceNamespaceInTemplate(cephfsDirPath + cephfsProvisionerRBAC)
// deploy provisioner if err != nil {
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisioner, fmt.Sprintf("--namespace=%s", cephCSINamespace)) e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsProvisionerRBAC, err)
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) }
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisionerPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace)) _, err = framework.RunKubectlInput(data, "--ignore-not-found=true", ns, "delete", "-f", "-")
// deploy nodeplugin if err != nil {
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePlugin, fmt.Sprintf("--namespace=%s", cephCSINamespace)) e2elog.Logf("failed to delete provisioner rbac %s %v", cephfsDirPath+cephfsProvisionerRBAC, err)
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) }
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePluginPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data, err = replaceNamespaceInTemplate(cephfsDirPath + cephfsNodePluginRBAC)
if err != nil {
e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsNodePluginRBAC, err)
}
_, err = framework.RunKubectlInput(data, "delete", "--ignore-not-found=true", ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to delete nodeplugin rbac %s %v", cephfsDirPath+cephfsNodePluginRBAC, err)
}
createORDeleteCephfsResouces("create")
} }
func deleteCephfsPlugin() { func deleteCephfsPlugin() {
_, err := framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisioner, fmt.Sprintf("--namespace=%s", cephCSINamespace)) createORDeleteCephfsResouces("delete")
if err != nil {
e2elog.Logf("failed to delete cephfs provisioner %v", err)
} }
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
func createORDeleteCephfsResouces(action string) {
data, err := replaceNamespaceInTemplate(cephfsDirPath + cephfsProvisioner)
if err != nil { if err != nil {
e2elog.Logf("failed to delete cephfs provisioner rbac %v", err) e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsProvisioner, err)
} }
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisionerPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace)) _, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil { if err != nil {
e2elog.Logf("failed to delete cephfs provisioner psp %v", err) e2elog.Logf("failed to %s cephfs provisioner %v", action, err)
} }
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePlugin, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data, err = replaceNamespaceInTemplate(cephfsDirPath + cephfsProvisionerRBAC)
if err != nil { if err != nil {
e2elog.Logf("failed to delete cephfs nodeplugin %v", err) e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsProvisionerRBAC, err)
} }
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) _, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil { if err != nil {
e2elog.Logf("failed to delete cephfs nodeplugin rbac %v", err) e2elog.Logf("failed to %s cephfs provisioner rbac %v", action, err)
} }
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePluginPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data, err = replaceNamespaceInTemplate(cephfsDirPath + cephfsProvisionerPSP)
if err != nil { if err != nil {
e2elog.Logf("failed to delete cephfs nodeplugin psp %v", err) e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsProvisionerPSP, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s cephfs provisioner psp %v", action, err)
}
data, err = replaceNamespaceInTemplate(cephfsDirPath + cephfsNodePlugin)
if err != nil {
e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsNodePlugin, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s cephfs nodeplugin %v", action, err)
}
data, err = replaceNamespaceInTemplate(cephfsDirPath + cephfsNodePluginRBAC)
if err != nil {
e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsNodePluginRBAC, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s cephfs nodeplugin rbac %v", action, err)
}
data, err = replaceNamespaceInTemplate(cephfsDirPath + cephfsNodePluginPSP)
if err != nil {
e2elog.Logf("failed to read content from %s %v", cephfsDirPath+cephfsNodePluginPSP, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s cephfs nodeplugin psp %v", action, err)
} }
} }
@ -74,23 +114,16 @@ var _ = Describe("cephfs", func() {
// deploy cephfs CSI // deploy cephfs CSI
BeforeEach(func() { BeforeEach(func() {
c = f.ClientSet c = f.ClientSet
createConfigMap(cephfsDirPath, f.ClientSet, f)
if deployCephFS { if deployCephFS {
if cephCSINamespace != defaultNs { if cephCSINamespace != defaultNs {
// create namespace err := createNamespace(c, cephCSINamespace)
ns := &v1.Namespace{ if err != nil {
ObjectMeta: metav1.ObjectMeta{
Name: cephCSINamespace,
},
}
_, err := c.CoreV1().Namespaces().Create(ns)
if err != nil && !apierrs.IsAlreadyExists(err) {
Fail(err.Error()) Fail(err.Error())
} }
} }
deployCephfsPlugin() deployCephfsPlugin()
} }
createConfigMap(cephfsDirPath, f.ClientSet, f)
createCephfsSecret(f.ClientSet, f) createCephfsSecret(f.ClientSet, f)
}) })
@ -107,11 +140,7 @@ var _ = Describe("cephfs", func() {
if deployCephFS { if deployCephFS {
deleteCephfsPlugin() deleteCephfsPlugin()
if cephCSINamespace != defaultNs { if cephCSINamespace != defaultNs {
err := c.CoreV1().Namespaces().Delete(cephCSINamespace, nil) err := deleteNamespace(c, cephCSINamespace)
if err != nil && !apierrs.IsNotFound(err) {
Fail(err.Error())
}
err = framework.WaitForNamespacesDeleted(c, []string{cephCSINamespace}, time.Duration(deployTimeout)*time.Minute)
if err != nil { if err != nil {
Fail(err.Error()) Fail(err.Error())
} }

View File

@ -1,7 +1,7 @@
package e2e package e2e
import ( import (
"fmt" "strings"
. "github.com/onsi/gomega" // nolint . "github.com/onsi/gomega" // nolint
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -19,11 +19,7 @@ var (
) )
func deployVault(c kubernetes.Interface, deployTimeout int) { func deployVault(c kubernetes.Interface, deployTimeout int) {
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultServicePath, fmt.Sprintf("--namespace=%s", cephCSINamespace)) createORDeleteVault("create")
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultPSPPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultRBACPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultConfigPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
opt := metav1.ListOptions{ opt := metav1.ListOptions{
LabelSelector: "app=vault", LabelSelector: "app=vault",
} }
@ -37,20 +33,48 @@ func deployVault(c kubernetes.Interface, deployTimeout int) {
} }
func deleteVault() { func deleteVault() {
_, err := framework.RunKubectl("delete", "-f", vaultExamplePath+vaultServicePath, fmt.Sprintf("--namespace=%s", cephCSINamespace)) createORDeleteVault("delete")
}
func createORDeleteVault(action string) {
data, err := replaceNamespaceInTemplate(vaultExamplePath + vaultServicePath)
if err != nil { if err != nil {
e2elog.Logf("failed to delete vault statefull set %v", err) e2elog.Logf("failed to read content from %s %v", vaultExamplePath+vaultServicePath, err)
} }
_, err = framework.RunKubectl("delete", "-f", vaultExamplePath+vaultRBACPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data = strings.ReplaceAll(data, "vault.default", "vault."+cephCSINamespace)
data = strings.ReplaceAll(data, "value: default", "value: "+cephCSINamespace)
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil { if err != nil {
e2elog.Logf("failed to delete vault statefull set %v", err) e2elog.Logf("failed to %s vault statefulset %v", action, err)
} }
_, err = framework.RunKubectl("delete", "-f", vaultExamplePath+vaultConfigPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data, err = replaceNamespaceInTemplate(vaultExamplePath + vaultRBACPath)
if err != nil { if err != nil {
e2elog.Logf("failed to delete vault config map %v", err) e2elog.Logf("failed to read content from %s %v", vaultExamplePath+vaultRBACPath, err)
} }
_, err = framework.RunKubectl("delete", "-f", vaultExamplePath+vaultPSPPath, fmt.Sprintf("--namespace=%s", cephCSINamespace)) _, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil { if err != nil {
e2elog.Logf("failed to delete vault psp %v", err) e2elog.Logf("failed to %s vault statefulset %v", action, err)
}
data, err = replaceNamespaceInTemplate(vaultExamplePath + vaultConfigPath)
if err != nil {
e2elog.Logf("failed to read content from %s %v", vaultExamplePath+vaultConfigPath, err)
}
data = strings.ReplaceAll(data, "default", cephCSINamespace)
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s vault config map %v", action, err)
}
data, err = replaceNamespaceInTemplate(vaultExamplePath + vaultPSPPath)
if err != nil {
e2elog.Logf("failed to read content from %s %v", vaultExamplePath+vaultPSPPath, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s vault psp %v", action, err)
} }
} }

View File

@ -58,4 +58,5 @@ func handleFlags() {
framework.RegisterClusterFlags(flag.CommandLine) framework.RegisterClusterFlags(flag.CommandLine)
testing.Init() testing.Init()
flag.Parse() flag.Parse()
initResouces()
} }

View File

@ -25,11 +25,10 @@ import (
) )
func logsCSIPods(label string, c clientset.Interface) { func logsCSIPods(label string, c clientset.Interface) {
ns := "default"
opt := metav1.ListOptions{ opt := metav1.ListOptions{
LabelSelector: label, LabelSelector: label,
} }
podList, err := c.CoreV1().Pods(ns).List(opt) podList, err := c.CoreV1().Pods(cephCSINamespace).List(opt)
if err != nil { if err != nil {
e2elog.Logf("failed to list pods with selector %s %v", label, err) e2elog.Logf("failed to list pods with selector %s %v", label, err)
return return

View File

@ -3,13 +3,9 @@ package e2e
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
. "github.com/onsi/ginkgo" // nolint . "github.com/onsi/ginkgo" // nolint
v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log" e2elog "k8s.io/kubernetes/test/e2e/framework/log"
@ -31,42 +27,84 @@ var (
func deployRBDPlugin() { func deployRBDPlugin() {
// delete objects deployed by rook // delete objects deployed by rook
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", rbdDirPath+rbdProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) data, err := replaceNamespaceInTemplate(rbdDirPath + rbdProvisionerRBAC)
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", rbdDirPath+rbdNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) if err != nil {
// deploy provisioner e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdProvisionerRBAC, err)
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdProvisioner, fmt.Sprintf("--namespace=%s", cephCSINamespace)) }
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) _, err = framework.RunKubectlInput(data, "--ignore-not-found=true", ns, "delete", "-f", "-")
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdProvisionerPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace)) if err != nil {
// deploy nodeplugin e2elog.Logf("failed to delete provisioner rbac %s %v", rbdDirPath+rbdProvisionerRBAC, err)
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdNodePlugin, fmt.Sprintf("--namespace=%s", cephCSINamespace)) }
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdNodePluginPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace)) data, err = replaceNamespaceInTemplate(rbdDirPath + rbdNodePluginRBAC)
if err != nil {
e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdNodePluginRBAC, err)
}
_, err = framework.RunKubectlInput(data, "delete", "--ignore-not-found=true", ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to delete nodeplugin rbac %s %v", rbdDirPath+rbdNodePluginRBAC, err)
}
createORDeleteRbdResouces("create")
} }
func deleteRBDPlugin() { func deleteRBDPlugin() {
_, err := framework.RunKubectl("delete", "-f", rbdDirPath+rbdProvisioner, fmt.Sprintf("--namespace=%s", cephCSINamespace)) createORDeleteRbdResouces("delete")
if err != nil {
e2elog.Logf("failed to delete rbd provisioner %v", err)
} }
_, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace), fmt.Sprintf("--namespace=%s", cephCSINamespace))
func createORDeleteRbdResouces(action string) {
data, err := replaceNamespaceInTemplate(rbdDirPath + rbdProvisioner)
if err != nil { if err != nil {
e2elog.Logf("failed to delete provisioner rbac %v", err) e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdProvisioner, err)
} }
_, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdProvisionerPSP) _, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil { if err != nil {
e2elog.Logf("failed to delete provisioner psp %v", err) e2elog.Logf("failed to %s rbd provisioner %v", action, err)
} }
_, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdNodePlugin, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data, err = replaceNamespaceInTemplate(rbdDirPath + rbdProvisionerRBAC)
if err != nil { if err != nil {
e2elog.Logf("failed to delete nodeplugin %v", err) e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdProvisionerRBAC, err)
} }
_, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace)) _, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil { if err != nil {
e2elog.Logf("failed to delete nodeplugin rbac %v", err) e2elog.Logf("failed to %s provisioner rbac %v", action, err)
} }
_, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdNodePluginPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
data, err = replaceNamespaceInTemplate(rbdDirPath + rbdProvisionerPSP)
if err != nil { if err != nil {
e2elog.Logf("failed to delete nodeplugin psp %v", err) e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdProvisionerPSP, err)
}
_, err = framework.RunKubectlInput(data, action, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s provisioner psp %v", action, err)
}
data, err = replaceNamespaceInTemplate(rbdDirPath + rbdNodePlugin)
if err != nil {
e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdNodePlugin, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s nodeplugin %v", action, err)
}
data, err = replaceNamespaceInTemplate(rbdDirPath + rbdNodePluginRBAC)
if err != nil {
e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdNodePluginRBAC, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s nodeplugin rbac %v", action, err)
}
data, err = replaceNamespaceInTemplate(rbdDirPath + rbdNodePluginPSP)
if err != nil {
e2elog.Logf("failed to read content from %s %v", rbdDirPath+rbdNodePluginPSP, err)
}
_, err = framework.RunKubectlInput(data, action, ns, "-f", "-")
if err != nil {
e2elog.Logf("failed to %s nodeplugin psp %v", action, err)
} }
} }
@ -76,21 +114,16 @@ var _ = Describe("RBD", func() {
// deploy RBD CSI // deploy RBD CSI
BeforeEach(func() { BeforeEach(func() {
c = f.ClientSet c = f.ClientSet
createConfigMap(rbdDirPath, f.ClientSet, f)
if deployRBD { if deployRBD {
if cephCSINamespace != defaultNs { if cephCSINamespace != defaultNs {
ns := &v1.Namespace{ err := createNamespace(c, cephCSINamespace)
ObjectMeta: metav1.ObjectMeta{ if err != nil {
Name: cephCSINamespace,
},
}
_, err := c.CoreV1().Namespaces().Create(ns)
if err != nil && !apierrs.IsAlreadyExists(err) {
Fail(err.Error()) Fail(err.Error())
} }
} }
deployRBDPlugin() deployRBDPlugin()
} }
createConfigMap(rbdDirPath, f.ClientSet, f)
createRBDStorageClass(f.ClientSet, f, make(map[string]string)) createRBDStorageClass(f.ClientSet, f, make(map[string]string))
createRBDSecret(f.ClientSet, f) createRBDSecret(f.ClientSet, f)
deployVault(f.ClientSet, deployTimeout) deployVault(f.ClientSet, deployTimeout)
@ -112,11 +145,7 @@ var _ = Describe("RBD", func() {
if deployRBD { if deployRBD {
deleteRBDPlugin() deleteRBDPlugin()
if cephCSINamespace != defaultNs { if cephCSINamespace != defaultNs {
err := c.CoreV1().Namespaces().Delete(cephCSINamespace, nil) err := deleteNamespace(c, cephCSINamespace)
if err != nil && !apierrs.IsNotFound(err) {
Fail(err.Error())
}
err = framework.WaitForNamespacesDeleted(c, []string{cephCSINamespace}, time.Duration(deployTimeout)*time.Minute)
if err != nil { if err != nil {
Fail(err.Error()) Fail(err.Error())
} }

View File

@ -42,11 +42,16 @@ var (
deployRBD bool deployRBD bool
cephCSINamespace string cephCSINamespace string
rookNamespace string rookNamespace string
ns string
vaultAddr = fmt.Sprintf("http://vault.%s.svc.cluster.local:8200", cephCSINamespace) vaultAddr string
poll = 2 * time.Second poll = 2 * time.Second
) )
func initResouces() {
ns = fmt.Sprintf("--namespace=%v", cephCSINamespace)
vaultAddr = fmt.Sprintf("http://vault.%s.svc.cluster.local:8200", cephCSINamespace)
}
// type snapInfo struct { // type snapInfo struct {
// ID int64 `json:"id"` // ID int64 `json:"id"`
// Name string `json:"name"` // Name string `json:"name"`
@ -54,11 +59,68 @@ var (
// Timestamp string `json:"timestamp"` // Timestamp string `json:"timestamp"`
// } // }
func createNamespace(c clientset.Interface, name string) error {
timeout := time.Duration(deployTimeout) * time.Minute
ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
_, err := c.CoreV1().Namespaces().Create(ns)
if err != nil && !apierrs.IsAlreadyExists(err) {
return err
}
return wait.PollImmediate(poll, timeout, func() (bool, error) {
_, err := c.CoreV1().Namespaces().Get(name, metav1.GetOptions{})
if err != nil {
e2elog.Logf("Error getting namespace: '%s': %v", name, err)
if apierrs.IsNotFound(err) {
return false, nil
}
if testutils.IsRetryableAPIError(err) {
return false, nil
}
return false, err
}
return true, nil
})
}
func deleteNamespace(c clientset.Interface, name string) error {
timeout := time.Duration(deployTimeout) * time.Minute
err := c.CoreV1().Namespaces().Delete(name, nil)
if err != nil && !apierrs.IsNotFound(err) {
Fail(err.Error())
}
return wait.PollImmediate(poll, timeout, func() (bool, error) {
_, err = c.CoreV1().Namespaces().Get(name, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
return true, nil
}
e2elog.Logf("Error getting namespace: '%s': %v", name, err)
if testutils.IsRetryableAPIError(err) {
return false, nil
}
return false, err
}
return false, nil
})
}
func replaceNamespaceInTemplate(filePath string) (string, error) {
read, err := ioutil.ReadFile(filePath)
if err != nil {
return "", err
}
return strings.ReplaceAll(string(read), "namespace: default", fmt.Sprintf("namespace: %s", cephCSINamespace)), nil
}
func waitForDaemonSets(name, ns string, c clientset.Interface, t int) error { func waitForDaemonSets(name, ns string, c clientset.Interface, t int) error {
timeout := time.Duration(t) * time.Minute timeout := time.Duration(t) * time.Minute
start := time.Now() start := time.Now()
e2elog.Logf("Waiting up to %v for all daemonsets in namespace '%s' to start", e2elog.Logf("Waiting up to %v for all daemonsets in namespace '%s' to start", timeout, ns)
timeout, ns)
return wait.PollImmediate(poll, timeout, func() (bool, error) { return wait.PollImmediate(poll, timeout, func() (bool, error) {
ds, err := c.AppsV1().DaemonSets(ns).Get(name, metav1.GetOptions{}) ds, err := c.AppsV1().DaemonSets(ns).Get(name, metav1.GetOptions{})
@ -198,6 +260,10 @@ func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, en
scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "storageclass.yaml") scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "storageclass.yaml")
sc := getStorageClass(scPath) sc := getStorageClass(scPath)
sc.Parameters["fsName"] = "myfs" sc.Parameters["fsName"] = "myfs"
sc.Parameters["csi.storage.k8s.io/provisioner-secret-namespace"] = cephCSINamespace
sc.Parameters["csi.storage.k8s.io/controller-expand-secret-namespace"] = cephCSINamespace
sc.Parameters["csi.storage.k8s.io/node-stage-secret-namespace"] = cephCSINamespace
if enablePool { if enablePool {
sc.Parameters["pool"] = "myfs-data0" sc.Parameters["pool"] = "myfs-data0"
} }
@ -208,7 +274,7 @@ func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, en
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
// remove new line present in fsID // remove new line present in fsID
fsID = strings.Trim(fsID, "\n") fsID = strings.Trim(fsID, "\n")
sc.Namespace = cephCSINamespace
sc.Parameters["clusterID"] = fsID sc.Parameters["clusterID"] = fsID
_, err := c.StorageV1().StorageClasses().Create(&sc) _, err := c.StorageV1().StorageClasses().Create(&sc)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
@ -218,6 +284,10 @@ func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, param
scPath := fmt.Sprintf("%s/%s", rbdExamplePath, "storageclass.yaml") scPath := fmt.Sprintf("%s/%s", rbdExamplePath, "storageclass.yaml")
sc := getStorageClass(scPath) sc := getStorageClass(scPath)
sc.Parameters["pool"] = "replicapool" sc.Parameters["pool"] = "replicapool"
sc.Parameters["csi.storage.k8s.io/provisioner-secret-namespace"] = cephCSINamespace
sc.Parameters["csi.storage.k8s.io/controller-expand-secret-namespace"] = cephCSINamespace
sc.Parameters["csi.storage.k8s.io/node-stage-secret-namespace"] = cephCSINamespace
opt := metav1.ListOptions{ opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools", LabelSelector: "app=rook-ceph-tools",
} }
@ -230,6 +300,7 @@ func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, param
for k, v := range parameters { for k, v := range parameters {
sc.Parameters[k] = v sc.Parameters[k] = v
} }
sc.Namespace = cephCSINamespace
_, err := c.StorageV1().StorageClasses().Create(&sc) _, err := c.StorageV1().StorageClasses().Create(&sc)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
} }
@ -264,7 +335,7 @@ func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework, param
func deleteConfigMap(pluginPath string) { func deleteConfigMap(pluginPath string) {
path := pluginPath + configMap path := pluginPath + configMap
_, err := framework.RunKubectl("delete", "-f", path) _, err := framework.RunKubectl("delete", "-f", path, ns)
if err != nil { if err != nil {
e2elog.Logf("failed to delete configmap %v", err) e2elog.Logf("failed to delete configmap %v", err)
} }
@ -296,6 +367,7 @@ func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Fra
data, err := json.Marshal(conmap) data, err := json.Marshal(conmap)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
cm.Data["config.json"] = string(data) cm.Data["config.json"] = string(data)
cm.Namespace = cephCSINamespace
_, err = c.CoreV1().ConfigMaps(cephCSINamespace).Create(&cm) _, err = c.CoreV1().ConfigMaps(cephCSINamespace).Create(&cm)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
} }
@ -324,6 +396,7 @@ func createCephfsSecret(c kubernetes.Interface, f *framework.Framework) {
sc.StringData["adminKey"] = adminKey sc.StringData["adminKey"] = adminKey
delete(sc.StringData, "userID") delete(sc.StringData, "userID")
delete(sc.StringData, "userKey") delete(sc.StringData, "userKey")
sc.Namespace = cephCSINamespace
_, err := c.CoreV1().Secrets(cephCSINamespace).Create(&sc) _, err := c.CoreV1().Secrets(cephCSINamespace).Create(&sc)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
} }
@ -338,12 +411,20 @@ func createRBDSecret(c kubernetes.Interface, f *framework.Framework) {
Expect(stdErr).Should(BeEmpty()) Expect(stdErr).Should(BeEmpty())
sc.StringData["userID"] = "admin" sc.StringData["userID"] = "admin"
sc.StringData["userKey"] = adminKey sc.StringData["userKey"] = adminKey
sc.Namespace = cephCSINamespace
_, err := c.CoreV1().Secrets(cephCSINamespace).Create(&sc) _, err := c.CoreV1().Secrets(cephCSINamespace).Create(&sc)
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
} }
func deleteResource(scPath string) { func deleteResource(scPath string) {
_, err := framework.RunKubectl("delete", "-f", scPath) data, err := replaceNamespaceInTemplate(scPath)
if err != nil {
e2elog.Logf("failed to read content from %s %v", scPath, err)
}
_, err = framework.RunKubectlInput(data, ns, "delete", "-f", "-")
if err != nil {
e2elog.Logf("failed to delete %s %v", scPath, err)
}
Expect(err).Should(BeNil()) Expect(err).Should(BeNil())
} }

View File

@ -11,7 +11,6 @@ sudo scripts/minikube.sh cephcsi
sudo scripts/minikube.sh k8s-sidecar sudo scripts/minikube.sh k8s-sidecar
sudo chown -R travis: "$HOME"/.minikube /usr/local/bin/kubectl sudo chown -R travis: "$HOME"/.minikube /usr/local/bin/kubectl
# functional tests # functional tests
go test github.com/ceph/ceph-csi/e2e --deploy-timeout=10 -timeout=30m --cephcsi-namespace=cephcsi-e2e-$RANDOM -v
go test github.com/ceph/ceph-csi/e2e --deploy-timeout=10 -timeout=30m -v
sudo scripts/minikube.sh clean sudo scripts/minikube.sh clean