Skip to content

CNF-23377: Migrate away from deprecated ioutil#490

Open
sebrandon1 wants to merge 1 commit into
openshift:mainfrom
sebrandon1:ioutil_deprecation
Open

CNF-23377: Migrate away from deprecated ioutil#490
sebrandon1 wants to merge 1 commit into
openshift:mainfrom
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 from ioutil to os package:

File and directory operations:

  • Replaced all instances of ioutil.ReadFile, ioutil.WriteFile, and ioutil.ReadDir with os.ReadFile, os.WriteFile, and os.ReadDir respectively throughout the codebase, including files like cfg.go, scmauths.go, sshkey.go, common.go, and their associated test files. [1] [2] [3] [4] [5] [6] [7] [8] [9]

  • Updated all usages of ioutil.TempFile and ioutil.TempDir to os.CreateTemp and os.MkdirTemp respectively, ensuring temporary files and directories are created using the recommended APIs. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Imports and cleanup:

These changes ensure the project is compatible with newer Go versions and avoids deprecated functionality.

Summary by CodeRabbit

  • Refactor
    • Replaced deprecated file and temporary-file helpers with modern Go stdlib equivalents across the builder and test suites. Changes update file read/write and temp dir/file operations, removing the old dependency. No functional, behavioral, or public API changes; existing error handling and test assertions preserved.

@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 Apr 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: f1de4b02-8ed7-4178-ad3e-729dda8a14d9

📥 Commits

Reviewing files that changed from the base of the PR and between e6c9462 and 9fc7571.

📒 Files selected for processing (20)
  • pkg/build/builder/cmd/dockercfg/cfg.go
  • pkg/build/builder/cmd/dockercfg/cfg_test.go
  • pkg/build/builder/cmd/scmauth/cacert.go
  • pkg/build/builder/cmd/scmauth/password.go
  • pkg/build/builder/cmd/scmauth/scmauth_test.go
  • pkg/build/builder/cmd/scmauth/scmauths.go
  • pkg/build/builder/cmd/scmauth/scmauths_test.go
  • pkg/build/builder/cmd/scmauth/sshkey.go
  • pkg/build/builder/cmd/scmauth/sshkey_test.go
  • pkg/build/builder/cmd/scmauth/util.go
  • pkg/build/builder/common.go
  • pkg/build/builder/common_test.go
  • pkg/build/builder/daemonless.go
  • pkg/build/builder/daemonless_test.go
  • pkg/build/builder/docker_test.go
  • pkg/build/builder/dockerutil_test.go
  • pkg/build/builder/source.go
  • pkg/build/builder/source_test.go
  • pkg/build/builder/sti.go
  • pkg/build/builder/util_linux.go
✅ Files skipped from review due to trivial changes (6)
  • pkg/build/builder/util_linux.go
  • pkg/build/builder/common.go
  • pkg/build/builder/cmd/dockercfg/cfg.go
  • pkg/build/builder/cmd/scmauth/scmauth_test.go
  • pkg/build/builder/cmd/scmauth/sshkey_test.go
  • pkg/build/builder/docker_test.go
🚧 Files skipped from review as they are similar to previous changes (14)
  • pkg/build/builder/cmd/scmauth/sshkey.go
  • pkg/build/builder/sti.go
  • pkg/build/builder/daemonless.go
  • pkg/build/builder/cmd/scmauth/scmauths_test.go
  • pkg/build/builder/cmd/scmauth/password.go
  • pkg/build/builder/common_test.go
  • pkg/build/builder/daemonless_test.go
  • pkg/build/builder/cmd/dockercfg/cfg_test.go
  • pkg/build/builder/dockerutil_test.go
  • pkg/build/builder/cmd/scmauth/util.go
  • pkg/build/builder/cmd/scmauth/cacert.go
  • pkg/build/builder/source_test.go
  • pkg/build/builder/source.go
  • pkg/build/builder/cmd/scmauth/scmauths.go

Walkthrough

This PR replaces deprecated io/ioutil usage across the build package by switching to os package equivalents (ReadFile, WriteFile, CreateTemp, MkdirTemp, ReadDir), preserving existing control flow and error handling.

Changes

Cohort / File(s) Summary
SCM Auth package
pkg/build/builder/cmd/scmauth/*
Replaced ioutil helpers with os equivalents and adjusted SCMAuths to accept []os.DirEntry; removed io/ioutil imports.
SCM Auth tests
pkg/build/builder/cmd/scmauth/*_test.go
Tests updated to use os.MkdirTemp, os.CreateTemp, os.ReadFile, os.WriteFile, os.ReadDir; removed io/ioutil imports.
Docker config
pkg/build/builder/cmd/dockercfg/*
Switched ioutil.ReadFileos.ReadFile and ioutil.TempDiros.MkdirTemp in code and tests; removed io/ioutil imports.
Builder core logic
pkg/build/builder/{common,daemonless,source,sti,util_linux}.go
Replaced file I/O and temp helpers with os equivalents (ReadFile/WriteFile/CreateTemp/MkdirTemp/ReadDir); imports updated, control flow unchanged.
Builder tests & other tests
pkg/build/builder/*_test.go
Test files updated to use os equivalents for temp dirs/files, reads/writes, and directory reads; removed io/ioutil imports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (2 errors, 1 warning)

Check name Status Explanation Resolution
Stable And Deterministic Test Names ❌ Error Test names in docker_test.go and common_test.go use fmt.Sprintf("%d", i), creating numeric indices instead of descriptive, stable test names, violating requirements. Replace fmt.Sprintf("%d", i) test names with descriptive names that remain stable across test suite changes.
Ote Binary Stdout Contract ❌ Error PR adds new cmd/main.go file with fmt.Println/Printf calls writing to stdout in process-level main() function, violating OTE Binary Stdout Contract. Redirect fmt.Print* calls in cmd/main.go main() function to os.Stderr (e.g., fmt.Fprintln(os.Stderr, ...)) to avoid corrupting stdout JSON contract.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (12 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: migrating from the deprecated ioutil package to os package equivalents across the codebase.
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.
Test Structure And Quality ✅ Passed PR uses standard Go tests (not Ginkgo). Custom check for Ginkgo test structure is inapplicable; changes only refactor deprecated io/ioutil to os.
Microshift Test Compatibility ✅ Passed PR contains no new Ginkgo e2e tests; only refactoring changes migrating deprecated ioutil APIs to os equivalents in existing code and tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added in this PR. The changes are purely refactoring to migrate from deprecated io/ioutil to os package functions.
Topology-Aware Scheduling Compatibility ✅ Passed PR is a pure Go refactoring (ioutil deprecation migration) with no deployment manifests, operator code, or scheduling constraints that would require topology-awareness checks.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR does not add any new Ginkgo e2e tests; it only refactors existing code to replace deprecated ioutil package calls with os package equivalents. Check not applicable.
No-Weak-Crypto ✅ Passed PR migrates ioutil to os package with no weak crypto additions. Pre-existing SHA1 in common.go (for non-security repo naming) is unmodified by the PR.
Container-Privileges ✅ Passed PR modifies only Go source code replacing ioutil with os; no K8s/container manifests with privileged settings were introduced.
No-Sensitive-Data-In-Logs ✅ Passed PR only replaces deprecated ioutil functions with os equivalents; no new logging statements were introduced, and existing logging does not expose sensitive data.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/build/builder/cmd/scmauth/scmauths.go (1)

55-60: ⚠️ Potential issue | 🔴 Critical

os.ReadDir return type mismatches present signature (build break).

os.ReadDir returns []os.DirEntry, but present at line 23 accepts []os.FileInfo. The calls at line 60 (and line 40 in scmauths_test.go) will not compile.

Change the present signature from []os.FileInfo to []os.DirEntry—the function only calls Name(), which exists on both types.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/build/builder/cmd/scmauth/scmauths.go` around lines 55 - 60, The build
breaks because present currently accepts []os.FileInfo while os.ReadDir returns
[]os.DirEntry; update the present function signature (present) to accept
[]os.DirEntry instead of []os.FileInfo and adjust any callers (e.g., the
present(files) call and the test that passes directory listings) so they pass
the DirEntry slice; no other logic changes are needed since present only calls
Name() which exists on both types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/build/builder/cmd/scmauth/scmauths.go`:
- Around line 55-60: The build breaks because present currently accepts
[]os.FileInfo while os.ReadDir returns []os.DirEntry; update the present
function signature (present) to accept []os.DirEntry instead of []os.FileInfo
and adjust any callers (e.g., the present(files) call and the test that passes
directory listings) so they pass the DirEntry slice; no other logic changes are
needed since present only calls Name() which exists on both types.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: ec876062-ca39-458a-8f62-f2fa2af5aeb7

📥 Commits

Reviewing files that changed from the base of the PR and between fcd4ce2 and adcb7ed.

📒 Files selected for processing (20)
  • pkg/build/builder/cmd/dockercfg/cfg.go
  • pkg/build/builder/cmd/dockercfg/cfg_test.go
  • pkg/build/builder/cmd/scmauth/cacert.go
  • pkg/build/builder/cmd/scmauth/password.go
  • pkg/build/builder/cmd/scmauth/scmauth_test.go
  • pkg/build/builder/cmd/scmauth/scmauths.go
  • pkg/build/builder/cmd/scmauth/scmauths_test.go
  • pkg/build/builder/cmd/scmauth/sshkey.go
  • pkg/build/builder/cmd/scmauth/sshkey_test.go
  • pkg/build/builder/cmd/scmauth/util.go
  • pkg/build/builder/common.go
  • pkg/build/builder/common_test.go
  • pkg/build/builder/daemonless.go
  • pkg/build/builder/daemonless_test.go
  • pkg/build/builder/docker_test.go
  • pkg/build/builder/dockerutil_test.go
  • pkg/build/builder/source.go
  • pkg/build/builder/source_test.go
  • pkg/build/builder/sti.go
  • pkg/build/builder/util_linux.go

@sebrandon1 sebrandon1 changed the title Migrate away from deprecated ioutil CNF-23377: Migrate away from deprecated ioutil Apr 30, 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 30, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 30, 2026

@sebrandon1: This pull request references CNF-23377 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 from ioutil to os package:

File and directory operations:

  • Replaced all instances of ioutil.ReadFile, ioutil.WriteFile, and ioutil.ReadDir with os.ReadFile, os.WriteFile, and os.ReadDir respectively throughout the codebase, including files like cfg.go, scmauths.go, sshkey.go, common.go, and their associated test files. [1] [2] [3] [4] [5] [6] [7] [8] [9]

  • Updated all usages of ioutil.TempFile and ioutil.TempDir to os.CreateTemp and os.MkdirTemp respectively, ensuring temporary files and directories are created using the recommended APIs. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Imports and cleanup:

These changes ensure the project is compatible with newer Go versions and avoids deprecated functionality.

Summary by CodeRabbit

  • Refactor
  • Replaced deprecated file and temp helpers with modern Go stdlib equivalents across the builder and test suites (file read/write and temp file/dir operations). No behavioral or public API changes; functionality and error handling preserved.

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.

@sebrandon1
Copy link
Copy Markdown
Member Author

/remove-lifecycle stale

@sebrandon1
Copy link
Copy Markdown
Member Author

/retest

@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 May 4, 2026
@sebrandon1
Copy link
Copy Markdown
Member Author

/retest

@sebrandon1 sebrandon1 force-pushed the ioutil_deprecation branch from e6c9462 to 9fc7571 Compare May 29, 2026 15:00
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 29, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sebrandon1
Once this PR has been reviewed and has the lgtm label, please assign moebasim 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

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 29, 2026

@sebrandon1: The following tests 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/security 9fc7571 link false /test security
ci/prow/e2e-aws-ovn-image-ecosystem 9fc7571 link true /test e2e-aws-ovn-image-ecosystem

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

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants