Skip to content

Commit

Permalink
Merge pull request #612 from openebs/clone-tsts
Browse files Browse the repository at this point in the history
test(clone): use correct clone app and volume
  • Loading branch information
sinhaashish authored Jan 20, 2025
2 parents c61011a + 8d2f443 commit a48fcdb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 54 deletions.
8 changes: 8 additions & 0 deletions tests/pts/pts.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ func (b *Builder) WithContainerBuilders(
return b
}

// WithTerminationGracePeriodSeconds adds the terminationGracePeriodSeconds
func (b *Builder) WithTerminationGracePeriodSeconds(
period int64,
) *Builder {
b.podtemplatespec.Object.Spec.TerminationGracePeriodSeconds = &period
return b
}

// WithVolumeBuilders builds the list of volumebuilders provided
// and merges it to the volumes field of podtemplatespec.
func (b *Builder) WithVolumeBuilders(
Expand Down
3 changes: 2 additions & 1 deletion tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func init() {

OpenEBSNamespace = os.Getenv("OPENEBS_NAMESPACE")
if OpenEBSNamespace == "" {
os.Setenv("OPENEBS_NAMESPACE", "openebs")
OpenEBSNamespace = "openebs"
os.Setenv("OPENEBS_NAMESPACE", OpenEBSNamespace)
}
SCClient = sc.NewKubeClient(sc.WithKubeConfigPath(KubeConfigPath))
PVCClient = pvc.NewKubeClient(pvc.WithKubeConfigPath(KubeConfigPath))
Expand Down
93 changes: 40 additions & 53 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package tests

import (
"fmt"
"k8s.io/klog/v2"
"os/exec"
"time"

"k8s.io/klog/v2"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -478,41 +478,31 @@ func resizeAndVerifyPVC() {
}
func createDeployVerifyApp() {
ginkgo.By("creating and deploying app pod")
createAndDeployAppPod(appName)
time.Sleep(30 * time.Second)
ginkgo.By("verifying app pod is running", verifyAppPodRunning)
createAndDeployAppPod(appName, pvcName)
ginkgo.By("verifying app pod is running", func() { verifyAppPodRunning(appName) })
}

func createDeployVerifyCloneApp() {
ginkgo.By("creating and deploying app pod")
createAndDeployAppPod(cloneAppName)
time.Sleep(30 * time.Second)
ginkgo.By("verifying app pod is running", verifyAppPodRunning)
createAndDeployAppPod(cloneAppName, clonePvcName)
ginkgo.By("verifying app pod is running", func() { verifyAppPodRunning(cloneAppName) })
}

func createAndDeployAppPod(appname string) {
func createAndDeployAppPod(appname string, pvcname string) {
var err error
labels := map[string]string{
"app": "busybox",
"appName": appname,
}
ginkgo.By("building a busybox app pod deployment using above zfs volume")
deployObj, err = deploy.NewBuilder().
WithName(appname).
WithNamespace(OpenEBSNamespace).
WithLabelsNew(
map[string]string{
"app": "busybox",
},
).
WithSelectorMatchLabelsNew(
map[string]string{
"app": "busybox",
},
).
WithLabelsNew(labels).
WithSelectorMatchLabelsNew(labels).
WithPodTemplateSpecBuilder(
pts.NewBuilder().
WithLabelsNew(
map[string]string{
"app": "busybox",
},
).
WithLabelsNew(labels).
WithContainerBuilders(
container.NewBuilder().
WithImage("busybox").
Expand All @@ -537,45 +527,38 @@ func createAndDeployAppPod(appname string) {
WithVolumeBuilders(
k8svolume.NewBuilder().
WithName("datavol1").
WithPVCSource(pvcObj.Name),
),
WithPVCSource(pvcname),
).
WithTerminationGracePeriodSeconds(5),
).
Build()

gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "while building app deployement {%s}", appName)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "while building app deployement {%s}", appname)

deployObj, err = DeployClient.WithNamespace(OpenEBSNamespace).Create(deployObj)
gomega.Expect(err).ShouldNot(
gomega.HaveOccurred(),
"while creating pod {%s} in namespace {%s}",
appName,
appname,
OpenEBSNamespace,
)
}

func createAndDeployBlockAppPod() {
var err error
labels := map[string]string{
"app": "busybox",
"appName": appName,
}
ginkgo.By("building a busybox app pod deployment using above zfs volume")
deployObj, err = deploy.NewBuilder().
WithName(appName).
WithNamespace(OpenEBSNamespace).
WithLabelsNew(
map[string]string{
"app": "busybox",
},
).
WithSelectorMatchLabelsNew(
map[string]string{
"app": "busybox",
},
).
WithLabelsNew(labels).
WithSelectorMatchLabelsNew(labels).
WithPodTemplateSpecBuilder(
pts.NewBuilder().
WithLabelsNew(
map[string]string{
"app": "busybox",
},
).
WithLabelsNew(labels).
WithContainerBuilders(
container.NewBuilder().
WithImage("busybox").
Expand All @@ -601,7 +584,8 @@ func createAndDeployBlockAppPod() {
k8svolume.NewBuilder().
WithName("datavol1").
WithPVCSource(pvcObj.Name),
),
).
WithTerminationGracePeriodSeconds(5),
).
Build()

Expand All @@ -618,18 +602,21 @@ func createAndDeployBlockAppPod() {

func createDeployVerifyBlockApp() {
ginkgo.By("creating and deploying app pod", createAndDeployBlockAppPod)
time.Sleep(30 * time.Second)
ginkgo.By("verifying app pod is running", verifyAppPodRunning)
ginkgo.By("verifying app pod is running", func() { verifyAppPodRunning(appName) })
}

func verifyAppPodRunning() {
func verifyAppPodRunning(appname string) {
var err error
appPod, err = PodClient.WithNamespace(OpenEBSNamespace).
List(metav1.ListOptions{
LabelSelector: "app=busybox",
},
)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "while verifying application pod")
gomega.Eventually(func() bool {
appPod, err = PodClient.WithNamespace(OpenEBSNamespace).
List(metav1.ListOptions{
LabelSelector: "app=busybox,appName=" + appname,
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "while verifying application pod")
return len(appPod.Items) == 1
},
60, 5).
Should(gomega.BeTrue())

status := IsPodRunningEventually(OpenEBSNamespace, appPod.Items[0].Name)
gomega.Expect(status).To(gomega.Equal(true), "while checking status of pod {%s}", appPod.Items[0].Name)
Expand Down

0 comments on commit a48fcdb

Please sign in to comment.