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

Fix leader election in deployment #428

Closed
wants to merge 3 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deploy/cephfs/helm/templates/provisioner-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ spec:
image: "{{ .Values.provisioner.image.repository }}:{{ .Values.provisioner.image.tag }}"
args:
- "--csi-address=$(ADDRESS)"
- "--enable-leader-election=true"
- "--leader-election-type=leases"
- "--v=5"
env:
Expand Down
1 change: 1 addition & 0 deletions deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
args:
- "--csi-address=$(ADDRESS)"
- "--v=5"
- "--enable-leader-election=true"
- "--leader-election-type=leases"
env:
- name: ADDRESS
Expand Down
1 change: 1 addition & 0 deletions deploy/rbd/helm/templates/provisioner-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
args:
- "--csi-address=$(ADDRESS)"
- "--v=5"
- "--enable-leader-election=true"
- "--leader-election-type=leases"
env:
- name: ADDRESS
Expand Down
3 changes: 2 additions & 1 deletion deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ spec:
args:
- "--csi-address=$(ADDRESS)"
- "--v=5"
- --leader-election-type=leases"
- "--enable-leader-election=true"
- "--leader-election-type=leases"
env:
- name: ADDRESS
value: unix:///csi/csi-provisioner.sock
Expand Down
2 changes: 1 addition & 1 deletion deploy/rbd/kubernetes/csi-rbdplugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: driver-registrar
image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.2
image: quay.io/k8scsi/csi-node-driver-registrar:v1.1.0
args:
- "--v=5"
- "--csi-address=/csi/csi.sock"
Expand Down
40 changes: 36 additions & 4 deletions e2e/cephfs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package e2e

import (
"fmt"

. "github.com/onsi/ginkgo" // nolint

"k8s.io/kubernetes/test/e2e/framework"
Expand Down Expand Up @@ -41,7 +43,9 @@ var _ = Describe("cephfs", func() {
cephfsFiles := getFilesinDirectory(cephfsDirPath)
for _, file := range cephfsFiles {
res, err := framework.RunKubectl("delete", "-f", cephfsDirPath+file.Name())
framework.Logf("failed to delete resource in %s with err %v", res, err)
if err != nil {
framework.Logf("failed to delete resource in %s with err %v", res, err)
}
}
deleteSecret(cephfsExamplePath + "secret.yaml")
deleteStorageClass(cephfsExamplePath + "storageclass.yaml")
Expand All @@ -50,6 +54,8 @@ var _ = Describe("cephfs", func() {

Context("Test cephfs CSI", func() {
It("Test cephfs CSI", func() {
pvcPath := cephfsExamplePath + "pvc.yaml"
appPath := cephfsExamplePath + "pod.yaml"
By("checking provisioner deployment is completed")
err := waitForDeploymentComplete(cephfsDeploymentName, namespace, f.ClientSet, deployTimeout)
if err != nil {
Expand All @@ -64,16 +70,42 @@ var _ = Describe("cephfs", func() {

By("create and delete a PVC", func() {
By("create a PVC and Bind it to an app", func() {
pvcPath := cephfsExamplePath + "pvc.yaml"
appPath := cephfsExamplePath + "pod.yaml"

validatePVCAndAppBinding(pvcPath, appPath, f)

})

By("create a PVC and Bind it to an app with normal user", func() {
pvcPath := cephfsExamplePath + "pvc.yaml"
validateNormalUserPVCAccess(pvcPath, f)
})

By("create/delete multiple PVC and App", func() {
totalCount := 2
pvc := loadPVC(pvcPath)
pvc.Namespace = f.UniqueName
app := loadApp(appPath)
app.Namespace = f.UniqueName
//create pvc and app
for i := 0; i < totalCount; i++ {
name := fmt.Sprintf("%s%d", f.UniqueName, i)
err := createPVCAndApp(name, f, pvc, app)
if err != nil {
Fail(err.Error())
}

}
//TODO add cephfs backend validation

//delete pvc and app
for i := 0; i < totalCount; i++ {
name := fmt.Sprintf("%s%d", f.UniqueName, i)
err := deletePVCAndApp(name, f, pvc, app)
if err != nil {
Fail(err.Error())
}

}
})
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions e2e/deploy-rook.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func createRBDPool() {
}
func deleteFileSystem() {
commonPath := fmt.Sprintf("%s/%s", rookURL, "filesystem-test.yaml")
framework.RunKubectlOrDie("delete", "-f", commonPath)
framework.RunKubectl("delete", "-f", commonPath)
}

func deleteRBDPool() {
commonPath := fmt.Sprintf("%s/%s", rookURL, "pool-test.yaml")
framework.RunKubectlOrDie("delete", "-f", commonPath)
framework.RunKubectl("delete", "-f", commonPath)
}

func deployOperator(c kubernetes.Interface) {
Expand Down Expand Up @@ -109,5 +109,5 @@ func tearDownRook() {
// TODO need to add selector for cleanup validation
framework.Cleanup(opPath, rookNS)
commonPath := fmt.Sprintf("%s/%s", rookURL, "common.yaml")
framework.RunKubectlOrDie("delete", "-f", commonPath)
framework.RunKubectl("delete", "-f", commonPath)
}
52 changes: 48 additions & 4 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package e2e

import (
"fmt"

. "github.com/onsi/ginkgo" // nolint

"k8s.io/kubernetes/test/e2e/framework"
Expand Down Expand Up @@ -43,7 +45,9 @@ var _ = Describe("RBD", func() {
rbdFiles := getFilesinDirectory(rbdDirPath)
for _, file := range rbdFiles {
res, err := framework.RunKubectl("delete", "-f", rbdDirPath+file.Name())
framework.Logf("failed to delete resource in %s with err %v", res, err)
if err != nil {
framework.Logf("failed to delete resource in %s with err %v", res, err)
}
}
deleteRBDPool()
deleteSecret(rbdExamplePath + "secret.yaml")
Expand All @@ -52,6 +56,9 @@ var _ = Describe("RBD", func() {

Context("Test RBD CSI", func() {
It("Test RBD CSI", func() {

pvcPath := rbdExamplePath + "pvc.yaml"
appPath := rbdExamplePath + "pod.yaml"
By("checking provisioner deployment is completed")
err := waitForDeploymentComplete(rbdDeploymentName, namespace, f.ClientSet, deployTimeout)
if err != nil {
Expand All @@ -65,15 +72,52 @@ var _ = Describe("RBD", func() {
}

By("create a PVC and Bind it to an app", func() {
pvcPath := rbdExamplePath + "pvc.yaml"
appPath := rbdExamplePath + "pod.yaml"
validatePVCAndAppBinding(pvcPath, appPath, f)
})

By("create a PVC and Bind it to an app with normal user", func() {
pvcPath := rbdExamplePath + "pvc.yaml"
validateNormalUserPVCAccess(pvcPath, f)
})

By("create/delete multiple PVC and App", func() {
totalCount := 2
pvc := loadPVC(pvcPath)
pvc.Namespace = f.UniqueName
app := loadApp(appPath)
app.Namespace = f.UniqueName
//create pvc and app
for i := 0; i < totalCount; i++ {
name := fmt.Sprintf("%s%d", f.UniqueName, i)
err := createPVCAndApp(name, f, pvc, app)
if err != nil {
Fail(err.Error())
}

}
// validate created backend rbd images
images := listRBDImages(f)
if len(images) != totalCount {
framework.Logf("backend image creation not matching pvc count, image count = % pvc count %d", len(images), totalCount)
Fail("validate multiple pvc failed")
}

//delete pvc and app
for i := 0; i < totalCount; i++ {
name := fmt.Sprintf("%s%d", f.UniqueName, i)
err := deletePVCAndApp(name, f, pvc, app)
if err != nil {
Fail(err.Error())
}

}

// validate created backend rbd images
images = listRBDImages(f)
if len(images) > 0 {
framework.Logf("left out rbd backend images count %d", len(images))
Fail("validate multiple pvc failed")
}
})
})
})

Expand Down
65 changes: 55 additions & 10 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,28 +470,55 @@ func checkCephPods(ns string, c kubernetes.Interface, count, t int, opt *metav1.

}

// createPVCAndApp creates pvc and pod
// if name is not empty same will be set as pvc and app name
func createPVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error {

if name != "" {
pvc.Name = name
app.Name = name
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = name
}
err := createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
if err != nil {
return err
}
err = createApp(f.ClientSet, app, deployTimeout)
return err
}

// deletePVCAndApp delete pvc and pod
// if name is not empty same will be set as pvc and app name
func deletePVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error {

if name != "" {
pvc.Name = name
app.Name = name
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = name
}

err := deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
if err != nil {
return err
}
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
return err
}

func validatePVCAndAppBinding(pvcPath, appPath string, f *framework.Framework) {
pvc := loadPVC(pvcPath)
pvc.Namespace = f.UniqueName
framework.Logf("The PVC template %+v", pvc)
err := createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
if err != nil {
Fail(err.Error())
}

app := loadApp(appPath)
app.Namespace = f.UniqueName
err = createApp(f.ClientSet, app, deployTimeout)
if err != nil {
Fail(err.Error())
}

err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
err := createPVCAndApp("", f, pvc, app)
if err != nil {
Fail(err.Error())
}

err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
err = deletePVCAndApp("", f, pvc, app)
if err != nil {
Fail(err.Error())
}
Expand All @@ -506,6 +533,7 @@ func validateNormalUserPVCAccess(pvcPath string, f *framework.Framework) {
if err != nil {
Fail(err.Error())
}

var user int64 = 2000
app := &v1.Pod{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -568,4 +596,21 @@ func validateNormalUserPVCAccess(pvcPath string, f *framework.Framework) {
if err != nil {
Fail(err.Error())
}

}

func listRBDImages(f *framework.Framework) []string {

opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools",
}
stdout := execCommandInPod(f, "rbd ls --pool=replicapool --format=json", rookNS, &opt)

var imgInfos []string

err := json.Unmarshal([]byte(stdout), &imgInfos)
if err != nil {
Fail(err.Error())
}
return imgInfos
}