Skip to content

Commit

Permalink
adjust log position and fix some format
Browse files Browse the repository at this point in the history
  • Loading branch information
targetoee committed Oct 31, 2023
1 parent 295999d commit defd1b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
8 changes: 6 additions & 2 deletions test/e2e/framework/helpers/k8s/pv_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ type PvConfig struct {
Labels map[string]string
Capacity string
AccessModes []v1.PersistentVolumeAccessMode
Source string
Type string
Path string
NodeAffinity *v1.VolumeNodeAffinity
StorageClass string
}

const (
LocalTypePv string = "Local"
)

func InitPersistentVolume(conf PvConfig) (*v1.PersistentVolume, error) {
pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -49,7 +53,7 @@ func InitPersistentVolume(conf PvConfig) (*v1.PersistentVolume, error) {
StorageClassName: conf.StorageClass,
},
}
if conf.Source == "Local" {
if conf.Type == LocalTypePv {
pv.Spec.PersistentVolumeSource = v1.PersistentVolumeSource{
Local: &v1.LocalVolumeSource{
Path: conf.Path,
Expand Down
60 changes: 30 additions & 30 deletions test/e2e/persistent_volume/persistent_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ var kClient k8s.KubeCtl
var restClient yunikorn.RClient
var dev = "dev-" + common.RandSeq(5)

const (
LocalTypePv = "Local"
StandardScName = "standard"
)

var _ = ginkgo.BeforeSuite(func() {
// Initializing kubectl client
kClient = k8s.KubeCtl{}
Expand Down Expand Up @@ -80,17 +85,17 @@ var _ = ginkgo.Describe("PersistentVolume", func() {
Name: pvName,
Capacity: "1Gi",
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Source: "Local",
Type: LocalTypePv,
Path: "/tmp",
StorageClass: "standard",
StorageClass: StandardScName,
}

ginkgo.By("Create local type pv " + pvName)
pvObj, err := k8s.InitPersistentVolume(conf)
Ω(err).NotTo(HaveOccurred())
_, err = kClient.CreatePersistentVolume(pvObj)
Ω(err).NotTo(HaveOccurred())
Ω(kClient.WaitForPersistentVolumeAvailable(pvName, time.Duration(60)*time.Second)).NotTo(HaveOccurred())
ginkgo.By("Create local type pv " + pvName)
Ω(kClient.WaitForPersistentVolumeAvailable(pvName, 60*time.Second)).NotTo(HaveOccurred())

pvcName := "pvc-" + common.RandSeq(5)
pvcConf := k8s.PvcConfig{
Expand All @@ -99,12 +104,12 @@ var _ = ginkgo.Describe("PersistentVolume", func() {
VolumeName: pvName,
}

ginkgo.By("Create pvc " + pvcName + ", which binds to " + pvName)
pvcObj, err := k8s.InitPersistentVolumeClaim(pvcConf)
Ω(err).NotTo(HaveOccurred())
_, err = kClient.CreatePersistentVolumeClaim(pvcObj, dev)
Ω(err).NotTo(HaveOccurred())
Ω(kClient.WaitForPersistentVolumeClaimPresent(dev, pvcName, time.Duration(60)*time.Second)).NotTo(HaveOccurred())
ginkgo.By("Create pvc " + pvcName + ", which binds to " + pvName)
Ω(kClient.WaitForPersistentVolumeClaimPresent(dev, pvcName, 60*time.Second)).NotTo(HaveOccurred())

podName := "pod-" + common.RandSeq(5)
podConf := k8s.TestPodConfig{
Expand All @@ -113,15 +118,15 @@ var _ = ginkgo.Describe("PersistentVolume", func() {
PvcName: pvcName,
}

ginkgo.By("Create pod " + podName + ", which uses pvc " + pvcName)
podObj, err := k8s.InitTestPod(podConf)
Ω(err).NotTo(HaveOccurred())
_, err = kClient.CreatePod(podObj, dev)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create pod " + podName + ", which uses pvc " + pvcName)

err = kClient.WaitForPodRunning(dev, podName, time.Duration(60)*time.Second)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Check pod " + podName + " is successfully running")
err = kClient.WaitForPodRunning(dev, podName, 60*time.Second)
Ω(err).NotTo(HaveOccurred())
})

ginkgo.It("Verify_dynamic_bindng_with_nfs_server", func() {
Expand All @@ -130,7 +135,7 @@ var _ = ginkgo.Describe("PersistentVolume", func() {
// Create nfs server and related rbac
saName := "nfs-service-account"
crName := "nfs-cluster-role"
crbName := "nfs-cluster-role-binding"
crbName := "nfs-cluster-role-binding" //nolint:gosec
serverName := "nfs-provisioner"
scName := "nfs-sc"
createNfsRbac(saName, crName, crbName)
Expand All @@ -144,12 +149,12 @@ var _ = ginkgo.Describe("PersistentVolume", func() {
StorageClassName: scName,
}

ginkgo.By("Create pvc " + pvcName + ", which uses storage class " + scName)
pvcObj, err := k8s.InitPersistentVolumeClaim(pvcConf)
Ω(err).NotTo(HaveOccurred())
_, err = kClient.CreatePersistentVolumeClaim(pvcObj, dev)
Ω(err).NotTo(HaveOccurred())
Ω(kClient.WaitForPersistentVolumeClaimPresent(dev, pvcName, time.Duration(60)*time.Second)).NotTo(HaveOccurred())
ginkgo.By("Create pvc " + pvcName + ", which uses storage class " + scName)
Ω(kClient.WaitForPersistentVolumeClaimPresent(dev, pvcName, 60*time.Second)).NotTo(HaveOccurred())

// Create pod
podName := "pod-" + common.RandSeq(5)
Expand All @@ -159,29 +164,26 @@ var _ = ginkgo.Describe("PersistentVolume", func() {
PvcName: pvcName,
}

ginkgo.By("Create pod " + podName + " with pvc " + pvcName)
podObj, err := k8s.InitTestPod(podConf)
Ω(err).NotTo(HaveOccurred())
_, err = kClient.CreatePod(podObj, dev)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create pod " + podName + " with pvc " + pvcName)

err = kClient.WaitForPodRunning(dev, podName, time.Duration(60)*time.Second)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Check pod " + podName + " is successfully running")

err = deleteNfsRelatedRoles(saName, crName, crbName)
err = kClient.WaitForPodRunning(dev, podName, 60*time.Second)
Ω(err).NotTo(HaveOccurred())

err = deleteNfsProvisioner(serverName, scName)
Ω(err).NotTo(HaveOccurred())
deleteNfsRelatedRoles(saName, crName, crbName)
deleteNfsProvisioner(serverName, scName)
})
})

func createNfsRbac(svaName string, crName string, crbName string) {
// Create service account, cluster role and role binding
ginkgo.By("Create service account " + svaName)
_, err := kClient.CreateServiceAccount(svaName, dev)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create service account " + svaName)

nfsClusterRole := &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -208,13 +210,13 @@ func createNfsRbac(svaName string, crName string, crbName string) {
},
},
}
ginkgo.By("Create cluster role " + crName)
_, err = kClient.CreateClusterRole(nfsClusterRole)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create cluster role " + crName)

ginkgo.By("Create cluster role binding " + crbName)
_, err = kClient.CreateClusterRoleBinding(crbName, crName, dev, svaName)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create cluster role binding " + crbName)
}

func createNfsProvisioner(svaName string, serverName string, scName string) {
Expand Down Expand Up @@ -304,9 +306,9 @@ func createNfsProvisioner(svaName string, serverName string, scName string) {
},
}

ginkgo.By("Create nfs provisioner " + serverName)
_, err := kClient.CreateDeployment(nfsProvisioner, dev)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create nfs provisioner " + serverName)

// Create storage class
sc := &storagev1.StorageClass{
Expand All @@ -320,12 +322,13 @@ func createNfsProvisioner(svaName string, serverName string, scName string) {
Provisioner: "openebs.io/nfsrwx",
}

ginkgo.By("Create storage class " + scName)
_, err = kClient.CreateStorageClass(sc)
Ω(err).NotTo(HaveOccurred())
ginkgo.By("Create storage class " + scName)
}

func deleteNfsRelatedRoles(serviceAccount string, clusterRole string, clusterRoleBinding string) error {
func deleteNfsRelatedRoles(serviceAccount string, clusterRole string, clusterRoleBinding string) {
ginkgo.By("Deleting NFS related roles and bindings")
err := kClient.DeleteClusterRoleBindings(clusterRoleBinding)
Ω(err).NotTo(HaveOccurred())

Expand All @@ -334,16 +337,13 @@ func deleteNfsRelatedRoles(serviceAccount string, clusterRole string, clusterRol

err = kClient.DeleteServiceAccount(serviceAccount, dev)
Ω(err).NotTo(HaveOccurred())

return err
}

func deleteNfsProvisioner(deployName string, scName string) error {
func deleteNfsProvisioner(deployName string, scName string) {
ginkgo.By("Deleting NFS deployment and storage class")
err := kClient.DeleteDeployment(deployName, dev)
Ω(err).NotTo(HaveOccurred())

err = kClient.DeleteStorageClass(scName)
Ω(err).NotTo(HaveOccurred())

return err
}

0 comments on commit defd1b5

Please sign in to comment.