Skip to content

Close files opened by hack helper commands#4709

Open
buley wants to merge 2 commits intoAzure:masterfrom
buley:buley/close-opened-hack-files
Open

Close files opened by hack helper commands#4709
buley wants to merge 2 commits intoAzure:masterfrom
buley:buley/close-opened-hack-files

Conversation

@buley
Copy link
Copy Markdown

@buley buley commented Mar 24, 2026

Which issue this PR addresses:

Fixes #4708

What this PR does / why we need it:

This closes the files opened by hack/aead and hack/role once their read and parse paths complete. The hack/aead change keeps the existing stdin path untouched while cleaning up only real file opens.

Test plan for issue:

  • go test ./hack/aead ./hack/role
  • These helper packages do not currently carry focused unit tests, so the package compile check is the narrowest automated verification available here.

Is there any documentation that needs to be updated for this PR?

No. This is an internal resource-cleanup change in hack/.

How do you know this will function as expected in production?

The change only adds file cleanup after existing reads complete and does not alter CLI flags, parsing logic, or the data produced by either helper.

Copilot AI review requested due to automatic review settings March 24, 2026 19:13
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 24, 2026

Hi @buley. Thanks for your PR.

I'm waiting for a Azure 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #4708 by ensuring short-lived helper commands under hack/ properly close any files they open during read/parse operations, avoiding unnecessary file descriptor leaks.

Changes:

  • Add a deferred Close() for the manifest file opened by hack/role.
  • Add best-effort closing for files opened by hack/aead when -file is not - (stdin remains untouched).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
hack/role/role.go Defer-close the manifest file after opening it for parsing.
hack/aead/aead.go Track and defer-close the opened input file when reading from a path instead of stdin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@buley
Copy link
Copy Markdown
Author

buley commented Mar 24, 2026

Addressed the Copilot feedback in c1ae10766 by simplifying the hack/aead open/close flow and replacing the //nolint:errcheck close defers with explicit deferred wrappers.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Close files opened by hack/aead and hack/role helpers

2 participants