Skip to content

sandbox_controller: improve error handling#185

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
Iceber:improve_error_handling
Dec 6, 2025
Merged

sandbox_controller: improve error handling#185
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
Iceber:improve_error_handling

Conversation

@Iceber

@Iceber Iceber commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@netlify

netlify Bot commented Nov 26, 2025

Copy link
Copy Markdown

Deploy Preview for agent-sandbox canceled.

Name Link
🔨 Latest commit dbfac36
🔍 Latest deploy log https://app.netlify.com/projects/agent-sandbox/deploys/6927b67cf65a220007324f1d
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 26, 2025
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @Iceber. Thanks for your PR.

I'm waiting for a github.com 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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 26, 2025
@janetkuo

Copy link
Copy Markdown
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 Nov 26, 2025
Comment thread controllers/sandbox_controller.go Outdated
Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
@Iceber Iceber force-pushed the improve_error_handling branch from 7c95570 to dbfac36 Compare November 27, 2025 02:24
@Iceber Iceber requested a review from janetkuo November 27, 2025 02:26
@barney-s

barney-s commented Dec 2, 2025

Copy link
Copy Markdown
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2025

@barney-s barney-s left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The refactoring in reconcilePVCs to un-nest the logic is a good improvement for readability. Several error messages could be made more specific by including the names of the resources being acted upon, which would greatly help with debugging.


if !k8serrors.IsNotFound(err) {
log.Error(err, "Failed to get PVC")
return fmt.Errorf("PVC Get Failed: %w", err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The error message "PVC Get Failed" is generic. For better debuggability, please include the name of the PVC that could not be retrieved. For example: return fmt.Errorf("failed to get PVC %s: %w", pvcName, err)

return fmt.Errorf("SetControllerReference for PVC failed: %w", err)
}
if err := r.Create(ctx, pvc, client.FieldOwner(sandboxControllerFieldOwner)); err != nil {
log.Error(err, "Failed to create PVC", "PVC.Namespace", sandbox.Namespace, "PVC.Name", pvcName)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

While the error is logged, the returned error lacks context. Consider wrapping the error to make it clearer where it originated, for instance: return fmt.Errorf("failed to create PVC %s: %w", pvcName, err).

if podReady && svcReady {
readyCondition.Status = metav1.ConditionTrue
readyCondition.Reason = "DependenciesReady"
return readyCondition

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

While removing the early return is a valid stylistic choice for creating a single exit point, the condition for Ready=False is now less explicit. Consider adding an else block to set a Reason such as "DependenciesNotReady". This would make the sandbox's status clearer during inspection.

log.Error(err, "Failed to get PVC")
return fmt.Errorf("PVC Get Failed: %w", err)
}
if err == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This continue statement handles the case where the PVC already exists. This is correct, but adding a comment here explaining that this signifies the "pvc already exists" case would improve clarity for future readers.

Spec: pvcTemplate.Spec,
}
if err := ctrl.SetControllerReference(sandbox, pvc, r.Scheme); err != nil {
return fmt.Errorf("SetControllerReference for PVC failed: %w", err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When setting the controller reference, the error message SetControllerReference for PVC failed is helpful, but it would be even better to include the name of the PVC for which it failed.

@janetkuo janetkuo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Iceber, janetkuo

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

The pull request process is described 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 k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2025
@k8s-ci-robot k8s-ci-robot merged commit cb78b51 into kubernetes-sigs:main Dec 6, 2025
10 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

4 participants