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

test: to check the status of pvc as bound and pod as running #162

Merged
merged 1 commit into from
May 9, 2022

Conversation

riya-singhal31
Copy link
Contributor

@riya-singhal31 riya-singhal31 commented Apr 20, 2022

this test creates pvc and pod and verifies the status of pvc to be bound and pod to be running, and cleans them up.

Signed-off-by: riya-singhal31 [email protected]

@riya-singhal31
Copy link
Contributor Author

Output:
[riyasinghal@fedora lvm-operator]$ oc get pvc,pods
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/lvmblockpvc Bound pvc-8d8a4385-99c0-46b5-a0ba-235983d2aed9 5Gi RWO odf-lvm-vg1 10s
persistentvolumeclaim/lvmfilepvc Bound pvc-244885b9-7e9d-40b4-88cb-956bb040bdd6 5Gi RWO odf-lvm-vg1 12s

NAME READY STATUS RESTARTS AGE
pod/lvmblockpod 1/1 Running 0 10s
pod/lvmfilepod 1/1 Running 0 12s

e2e/common.go Outdated
Comment on lines 29 to 32
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "PersistentVolumeClaim",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dont need to add the API version and kind

e2e/common.go Outdated
Spec: k8sv1.PersistentVolumeClaimSpec{
StorageClassName: &storageClass,
AccessModes: []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteOnce},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line not required.

e2e/common.go Outdated
AccessModes: []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteOnce},

VolumeMode: &volumemode,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line not required.

e2e/common.go Outdated

Resources: k8sv1.ResourceRequirements{
Requests: k8sv1.ResourceList{
"storage": storageQuantity,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"storage": storageQuantity,
v1.ResourceStorage: resource.MustParse(quantity),

e2e/common.go Outdated
Comment on lines 57 to 58
APIVersion: "v1",
Kind: "Pod",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here as well.

e2e/common.go Outdated
if err != nil && !errors.IsAlreadyExists(err) {
return err
}
pod, err = DeployManagerObj.GetK8sClient().CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pod, err = DeployManagerObj.GetK8sClient().CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
_, err = DeployManagerObj.GetK8sClient().CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})

e2e/common.go Outdated
return false, nil
}

if pvc.Status.Phase != k8sv1.ClaimBound {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the error is not found you need to continue of else this case cause panic as the Status might be nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never be NotFound as the PVC was just created.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 above notFound error check need to be removed.

Expect(err).To(BeNil())

err = tests.WaitForPVCBound(blockpvc, namespace, blockpod)
fmt.Printf("%v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required

It("and verify bound status", func() {
By("Should be bound")
err := tests.WaitForPVCBound(filepvc, namespace, filepod)
fmt.Printf("%v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf not required.

Comment on lines 67 to 68
err = tests.DeployManagerObj.GetK8sClient().CoreV1().PersistentVolumeClaims(namespace).Delete(context.TODO(), filepvc.Name, metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
Expect(err).To(BeNil())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PVC deletion will not ensure PV is deleted. you might need to add a check to validate that PV is also deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can take that up in a later PR. For now, the LVMCluster cleanup will fail if the PV still exists.

@riya-singhal31
Copy link
Contributor Author

/test lvm-operator-bundle-e2e-aws

@riya-singhal31
Copy link
Contributor Author

Updated the PR to address suggestions, thanks.

Copy link
Contributor

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nits.

e2e/common.go Outdated
Comment on lines 24 to 25
_, err := resource.ParseQuantity(quantity)
gomega.Expect(err).To(gomega.BeNil())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not required. as we are directly using quantity at line 38

e2e/common.go Outdated
)

//nolint:errcheck
func debug(msg string, args ...interface{}) {
ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf(msg, args...)))
}

// GetSamplePVC returns a sample pvc.
func GetSamplePVC(storageClass string, quantity string, name string, volumemode k8sv1.PersistentVolumeMode) *k8sv1.PersistentVolumeClaim {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func GetSamplePVC(storageClass string, quantity string, name string, volumemode k8sv1.PersistentVolumeMode) *k8sv1.PersistentVolumeClaim {
func GetSamplePVC(storageClass , quantity , name string, volumemode k8sv1.PersistentVolumeMode) *k8sv1.PersistentVolumeClaim {

e2e/common.go Outdated
}

// GetSamplePod returns a sample pod.
func GetSamplePod(name string, pvcName string) *k8sv1.Pod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func GetSamplePod(name string, pvcName string) *k8sv1.Pod {
func GetSamplePod(name , pvcName string) *k8sv1.Pod {

e2e/common.go Outdated
if err != nil {
return fmt.Errorf("%v: %s", err, lastReason)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to check pod is in a running the state?

Copy link
Contributor Author

@riya-singhal31 riya-singhal31 Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion,
Added the function for same.

@@ -33,3 +36,59 @@ var _ = Describe("Validation test", func() {
})
})
})

// Test to verify the PVC status
var _ = Describe("PVC Status check", VerifyPVCStatus)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • IMHO refactoring it like below will be good as we are going to expand the test coverage for components

  • in e2e/lvm/lvm_suite_test.go everything upto line 28 will stay as it is
  • after that it'll take below form
var _ = Describe("LVMO", func() {
  Context("lvmcluster", <funcWhichValidatesResources>)
  Contextt("pvc", <funcWhichValidatesPVCops>)
})
  • and the functions will be in package e2e (existing or new file) but not in lvm_suite_test.go, makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out Leela,
I've now made separate files for separate tests now, as lvm_suite_test.go will makes more sense if it contains only setup and teardown part.

e2e/common.go Outdated
)

//nolint:errcheck
func debug(msg string, args ...interface{}) {
ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf(msg, args...)))
}

// GetSamplePVC returns a sample pvc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • if there's a possibility that the GetSample* methods should return different fields and values it's better to consider moving templates into a separate folder (let's say testdata to confirm with go recommendations) and manipulate those templates?
  • it'll be like, you have a PVC template and deep copy that at call site and set the fields

Copy link
Contributor Author

@riya-singhal31 riya-singhal31 Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

e2e/common.go Outdated

// WaitForPVCBound waits for a pvc with a given name and namespace to reach BOUND phase.
func WaitForPVCBound(pvc *k8sv1.PersistentVolumeClaim, namespace string, pod *k8sv1.Pod) error {
pvc, err := DeployManagerObj.GetK8sClient().CoreV1().PersistentVolumeClaims(namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • we can define a single context or declare a pkg level context and use the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the suggestion!
That will need to be done in pkg/deploymanager.
Will add this while changing multiple clients to single client and will create a separate PR for that concern.

})

AfterEach(func() {
err := tests.DeployManagerObj.GetK8sClient().CoreV1().Pods(namespace).Delete(context.TODO(), filepod.Name, metav1.DeleteOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • if we are going to use k8sClient multiple times in multiple places why not register that in BeforeSuite (create a var at pkg level) if SuiteFailed to False and use that throughout?
  • iirc there was also an effort to unify all clients used in the test and having that at pkg level might be helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will unify all clients in the next PR.

@riya-singhal31 riya-singhal31 force-pushed the pvcbound branch 3 times, most recently from 9053d43 to 6ab87b2 Compare April 22, 2022 11:58
@riya-singhal31 riya-singhal31 changed the title test: to check the status of pvc as bound test: to check the status of pvc as bound and pod as running Apr 25, 2022
@riya-singhal31
Copy link
Contributor Author

/test lvm-operator-bundle-e2e-aws

Copy link
Contributor

@leelavg leelavg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • some more refactoring can be done however this pr is good enough for the functionality it's testing

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2022
err = utilwait.PollImmediate(interval, timeout, func() (done bool, err error) {
err = t.crClient.Get(context.TODO(), types.NamespacedName{Name: lvmClusterRes.Name, Namespace: InstallNamespace}, cluster)
if err != nil && errors.IsNotFound(err) {
//lastReason = fmt.Sprintf("Error talking to k8s apiserver: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't notice that. Updated.

return true, nil
}
if err == nil {
//lastReason = "Waiting on namespace to be deleted"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

this test creates pvc and pod and verifies the status of pvc to be bound, and deletes them.

Signed-off-by: riya-singhal31 <[email protected]>
@riya-singhal31
Copy link
Contributor Author

/retest

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 6, 2022

@riya-singhal31: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/lvm-operator-bundle-e2e-aws ebae206 link false /test lvm-operator-bundle-e2e-aws

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 9, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 9, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: leelavg, nbalacha, riya-singhal31

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 9, 2022
@openshift-merge-robot openshift-merge-robot merged commit 4e44ceb into openshift:main May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants