-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
Output: NAME READY STATUS RESTARTS AGE |
e2e/common.go
Outdated
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "PersistentVolumeClaim", | ||
}, |
There was a problem hiding this comment.
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}, | ||
|
There was a problem hiding this comment.
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, | ||
|
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"storage": storageQuantity, | |
v1.ResourceStorage: resource.MustParse(quantity), |
e2e/common.go
Outdated
APIVersion: "v1", | ||
Kind: "Pod", |
There was a problem hiding this comment.
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{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
e2e/lvm/lvm_suite_test.go
Outdated
Expect(err).To(BeNil()) | ||
|
||
err = tests.WaitForPVCBound(blockpvc, namespace, blockpod) | ||
fmt.Printf("%v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not required
e2e/lvm/lvm_suite_test.go
Outdated
It("and verify bound status", func() { | ||
By("Should be bound") | ||
err := tests.WaitForPVCBound(filepvc, namespace, filepod) | ||
fmt.Printf("%v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf not required.
e2e/lvm/lvm_suite_test.go
Outdated
err = tests.DeployManagerObj.GetK8sClient().CoreV1().PersistentVolumeClaims(namespace).Delete(context.TODO(), filepvc.Name, metav1.DeleteOptions{}) | ||
if err != nil && !errors.IsNotFound(err) { | ||
Expect(err).To(BeNil()) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
/test lvm-operator-bundle-e2e-aws |
67d2af4
to
9f18504
Compare
Updated the PR to address suggestions, thanks. |
There was a problem hiding this 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
_, err := resource.ParseQuantity(quantity) | ||
gomega.Expect(err).To(gomega.BeNil()) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
e2e/lvm/lvm_suite_test.go
Outdated
@@ -33,3 +36,59 @@ var _ = Describe("Validation test", func() { | |||
}) | |||
}) | |||
}) | |||
|
|||
// Test to verify the PVC status | |||
var _ = Describe("PVC Status check", VerifyPVCStatus) |
There was a problem hiding this comment.
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 inlvm_suite_test.go
, makes sense?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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{}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
e2e/lvm/lvm_suite_test.go
Outdated
}) | ||
|
||
AfterEach(func() { | ||
err := tests.DeployManagerObj.GetK8sClient().CoreV1().Pods(namespace).Delete(context.TODO(), filepod.Name, metav1.DeleteOptions{}) |
There was a problem hiding this comment.
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 inBeforeSuite
(create avar
at pkg level) ifSuiteFailed
toFalse
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?
There was a problem hiding this comment.
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.
9053d43
to
6ab87b2
Compare
/test lvm-operator-bundle-e2e-aws |
There was a problem hiding this 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
6ab87b2
to
973cbac
Compare
973cbac
to
1486ee3
Compare
pkg/deploymanager/LVMCluster.go
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this.
There was a problem hiding this comment.
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.
pkg/deploymanager/LVMCluster.go
Outdated
return true, nil | ||
} | ||
if err == nil { | ||
//lastReason = "Waiting on namespace to be deleted" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this.
There was a problem hiding this comment.
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]>
/retest |
@riya-singhal31: The following test failed, say
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. |
[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 |
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]