Skip to content

tests: add a test to validate pause and resume feature#351

Open
darthsuburbus wants to merge 1 commit intokubernetes-sigs:mainfrom
darthsuburbus:topic/as/pvc-pers-e2e
Open

tests: add a test to validate pause and resume feature#351
darthsuburbus wants to merge 1 commit intokubernetes-sigs:mainfrom
darthsuburbus:topic/as/pvc-pers-e2e

Conversation

@darthsuburbus
Copy link

Description

Add a e2e test that tests out the pause and resume functionality implemented in #82:

  1. Create a Pod with a PVC and some generated data.
  2. Scale the replicas to 0, controller should delete the pod associated with the sandbox.
  3. Sandbox CR should remain consistent.
  4. Scale the replicas to 1, the controller will recreate the pod. Verify that the data is intact on the PVC.

This test addresses the request made in #248.

Testing Done

   pvc_persistence_test.go:68: WaitForObjectNotFound *v1.Namespace (/pvc-persistence-test-1772168327331581080) took 43.463444028s
--- PASS: TestPVCPersistenceAcrossReplicas (89.90s)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: darthsuburbus
Once this PR has been reviewed and has the lgtm label, please assign janetkuo for approval. For more information see the Code Review Process.

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

Details 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

@k8s-ci-robot
Copy link
Contributor

Welcome @darthsuburbus!

It looks like this is your first PR to kubernetes-sigs/agent-sandbox 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/agent-sandbox has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 27, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @darthsuburbus. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 27, 2026
@netlify
Copy link

netlify bot commented Feb 27, 2026

Deploy Preview for agent-sandbox canceled.

Name Link
🔨 Latest commit 355c2d7
🔍 Latest deploy log https://app.netlify.com/projects/agent-sandbox/deploys/69a127a04c176c0008cc4631

@janetkuo janetkuo added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 27, 2026
LabelSelector: "",
Conditions: []metav1.Condition{
{
Message: "Pod does not exist, replicas is 0; Service Exists",
Copy link
Member

Choose a reason for hiding this comment

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

In your WaitForObject calls, you are asserting the exact Message string inside the Conditions array (e.g., "Pod does not exist, replicas is 0; Service Exists" and "Pod is Ready; Service Exists").
While these strictly match the controller's current output, testing against exact human-readable message strings is generally an anti-pattern in K8s e2e tests.

Suggestion: Modify your predicates.SandboxHasStatus (or create a new predicate) to only assert against Type, Status, and Reason. The Reason field (DependenciesReady / SandboxNotReady) is meant for programmatic consumption for example.

},
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
Copy link
Member

Choose a reason for hiding this comment

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

nit: could we drop this down to 50Mi or 100Mi to be gentler on the test cluster's dynamic provisioner, depending on your storage class's minimums ?


// execWriteFileToPod writes content to a file inside a running pod via kubectl exec.
// The -i flag is required to forward stdin to the remote process.
func execWriteFileToPod(ctx context.Context, namespace, podName, filePath, content string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Currently, execWriteFileToPod and execReadFileFromPod use os/exec to invoke the local kubectl CLI. This introduces an environmental dependency on the test runner's kubectl binary and kubeconfig, which can lead to flaky tests in CI. Looking at the rest of our e2e test suite (like shutdown_test.go), we consistently rely on the client-go API via our test framework and avoid shelling out to external binaries.

Suggestion: Let's keep this test pure-Go and self-contained by using client-go to execute the read/write commands directly against the API server.

Copy link
Member

@vicentefb vicentefb left a comment

Choose a reason for hiding this comment

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

Thanks! This is a very valuable test that was missing. Overall, the logic is very solid. You're correctly simulating the exact behavior the controller executes when Replicas hits 0 (where it deletes the pod but retains the Sandbox CR and PVCs ), and then successfully validating the recovery. Left some comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants