Skip to content

CNF-23051: Migrate away from deprecated ioutil#422

Open
sebrandon1 wants to merge 1 commit intoopenshift:masterfrom
sebrandon1:ioutil_deprecation
Open

CNF-23051: Migrate away from deprecated ioutil#422
sebrandon1 wants to merge 1 commit intoopenshift:masterfrom
sebrandon1:ioutil_deprecation

Conversation

@sebrandon1
Copy link
Copy Markdown
Member

@sebrandon1 sebrandon1 commented Nov 24, 2025

ioutil has been deprecated since Go 1.16: https://go.dev/doc/go1.16#ioutil

Tracking issue: redhat-best-practices-for-k8s/telco-bot#52

Migration away from ioutil:

  • Replaced ioutil.TempFile with os.CreateTemp for creating temporary files in build_controller_test.go.
  • Updated ioutil.NopCloser to io.NopCloser and ioutil.ReadAll to io.ReadAll in imagestream_controller_test.go and templateinstance_controller_test.go. [1] [2] [3]

Cleanup of imports:

  • Removed unused ioutil imports and added io where necessary in test files. [1] [2] [3]

Summary by CodeRabbit

  • Tests
    • Updated test infrastructure to use modern Go APIs for file and I/O operations.

@openshift-bot
Copy link
Copy Markdown
Contributor

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci openshift-ci Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 23, 2026
@sebrandon1
Copy link
Copy Markdown
Member Author

/remove-lifecycle stale

@openshift-ci openshift-ci Bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 23, 2026
@ingvagabund
Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 27, 2026

Walkthrough

Replace deprecated io/ioutil package usage across three test files with modern standard library alternatives: os.CreateTemp replaces ioutil.TempFile, io.NopCloser replaces ioutil.NopCloser, and io.ReadAll replaces ioutil.ReadAll.

Changes

Cohort / File(s) Summary
Deprecation API Migration
pkg/build/controller/build/build_controller_test.go, pkg/image/controller/imagestream_controller_test.go, pkg/template/controller/templateinstance_controller_test.go
Updated test files to replace deprecated io/ioutil package calls with equivalent standard library functions: os.CreateTemp for temporary file creation, io.NopCloser for wrapping readers, and io.ReadAll for reading content. Corresponding import statements were updated accordingly.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

🚥 Pre-merge checks | ✅ 11 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main objective of the PR: migrating from the deprecated ioutil package to modern Go standard library alternatives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Modified test files use standard Go testing framework, not Ginkgo. No test names were added or modified in this PR.
Test Structure And Quality ✅ Passed The custom check for Ginkgo test patterns is not applicable to this PR, which modifies only standard Go unit tests using *testing.T without any Ginkgo imports.
Microshift Test Compatibility ✅ Passed The custom check for MicroShift Test Compatibility does not apply because the modified files contain standard Go unit tests, not Ginkgo e2e tests, and no new Ginkgo tests were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR does not add new Ginkgo e2e tests; changes are minor updates replacing deprecated ioutil APIs in existing controller unit tests.
Topology-Aware Scheduling Compatibility ✅ Passed Modified files are test files with no scheduling-related patterns. Changes migrate deprecated ioutil APIs to modern Go standard library equivalents.
Ote Binary Stdout Contract ✅ Passed All changes are in test files only, migrating deprecated ioutil functions to standard library equivalents with no stdout writes introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR does not add new Ginkgo e2e tests. It only refactors test utilities by migrating away from deprecated ioutil package functions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@ingvagabund
Copy link
Copy Markdown
Member

@sayan-biswas can you please approve?

@sebrandon1 sebrandon1 changed the title Migrate away from deprecated ioutil CNF-23051: Migrate away from deprecated ioutil Apr 20, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 20, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 20, 2026

@sebrandon1: This pull request references CNF-23051 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

ioutil has been deprecated since Go 1.16: https://go.dev/doc/go1.16#ioutil

Tracking issue: redhat-best-practices-for-k8s/telco-bot#52

Migration away from ioutil:

  • Replaced ioutil.TempFile with os.CreateTemp for creating temporary files in build_controller_test.go.
  • Updated ioutil.NopCloser to io.NopCloser and ioutil.ReadAll to io.ReadAll in imagestream_controller_test.go and templateinstance_controller_test.go. [1] [2] [3]

Cleanup of imports:

  • Removed unused ioutil imports and added io where necessary in test files. [1] [2] [3]

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ingvagabund, sebrandon1

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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 30, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/build/controller/build/build_controller_test.go`:
- Around line 1763-1766: The test calls os.CreateTemp and immediately defers
os.Remove(registriesConf.Name()) before checking err, which can panic if
CreateTemp failed; update the code in build_controller_test.go to check the
error returned by os.CreateTemp first (i.e., if err != nil { t.Errorf(...);
return } or t.Fatalf), only then use registriesConf and establish the defer
os.Remove(registriesConf.Name()), ensuring registriesConf is non-nil when
referenced.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 92e9659b-1985-4ded-91fd-e2c42ef2d67a

📥 Commits

Reviewing files that changed from the base of the PR and between 731d742 and 5abed52.

📒 Files selected for processing (3)
  • pkg/build/controller/build/build_controller_test.go
  • pkg/image/controller/imagestream_controller_test.go
  • pkg/template/controller/templateinstance_controller_test.go

Comment on lines +1763 to 1766
registriesConf, err := os.CreateTemp("", "registries.conf")
defer os.Remove(registriesConf.Name())
if err != nil {
t.Errorf("unexpected error creating temp file: %s", err.Error())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard CreateTemp error before using registriesConf.

At Line 1764, registriesConf.Name() is called before checking err. If os.CreateTemp fails, this can panic on nil and mask the real failure.

💡 Suggested fix
 registriesConf, err := os.CreateTemp("", "registries.conf")
-defer os.Remove(registriesConf.Name())
 if err != nil {
 	t.Errorf("unexpected error creating temp file: %s", err.Error())
+	return
 }
+defer os.Remove(registriesConf.Name())
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
registriesConf, err := os.CreateTemp("", "registries.conf")
defer os.Remove(registriesConf.Name())
if err != nil {
t.Errorf("unexpected error creating temp file: %s", err.Error())
registriesConf, err := os.CreateTemp("", "registries.conf")
if err != nil {
t.Errorf("unexpected error creating temp file: %s", err.Error())
return
}
defer os.Remove(registriesConf.Name())
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/build/controller/build/build_controller_test.go` around lines 1763 -
1766, The test calls os.CreateTemp and immediately defers
os.Remove(registriesConf.Name()) before checking err, which can panic if
CreateTemp failed; update the code in build_controller_test.go to check the
error returned by os.CreateTemp first (i.e., if err != nil { t.Errorf(...);
return } or t.Fatalf), only then use registriesConf and establish the defer
os.Remove(registriesConf.Name()), ensuring registriesConf is non-nil when
referenced.

@sebrandon1
Copy link
Copy Markdown
Member Author

/retest

@ingvagabund
Copy link
Copy Markdown
Member

/lgtm

@ingvagabund
Copy link
Copy Markdown
Member

/verified by CI

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label May 4, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@ingvagabund: This PR has been marked as verified by CI.

Details

In response to this:

/verified by CI

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label May 4, 2026
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 731d742 and 2 for PR HEAD 5abed52 in total

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 5, 2026

@sebrandon1: 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/e2e-hypershift-conformance 5abed52 link true /test e2e-hypershift-conformance

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants