Skip to content

Conversation

@sebrandon1
Copy link
Member

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

@coderabbitai
Copy link

coderabbitai bot commented Nov 24, 2025

Walkthrough

Migrate deprecated ioutil package functions to their standard library equivalents: replacing ioutil.ReadFile with os.ReadFile and ioutil.TempFile with os.CreateTemp. Removes unused ioutil imports while preserving existing error handling and logic flow.

Changes

Cohort / File(s) Summary
CA Bundle and Certificate File Reading
pkg/controller/cabundleinjector/starter.go, pkg/controller/servingcert/starter/starter.go
Replace ioutil.ReadFile with os.ReadFile for reading CA bundle and intermediate certificate files. Remove unused ioutil import; relocate other imports as needed. Error handling and subsequent processing unchanged.
Test Utilities
test/util/rotate.go
Replace ioutil.TempFile with os.CreateTemp for creating temporary certificate and key files. Remove ioutil import. Surrounding logic and error handling preserved.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Straightforward, mechanical API replacements (ioutil.ReadFileos.ReadFile, ioutil.TempFileos.CreateTemp)
  • Consistent pattern applied across 3 files with no logic modifications
  • Import cleanup only; no behavior changes or error handling modifications
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between f5a143a and c6bfab3.

📒 Files selected for processing (3)
  • pkg/controller/cabundleinjector/starter.go (2 hunks)
  • pkg/controller/servingcert/starter/starter.go (1 hunks)
  • test/util/rotate.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/controller/servingcert/starter/starter.go
  • test/util/rotate.go
  • pkg/controller/cabundleinjector/starter.go
🔇 Additional comments (4)
test/util/rotate.go (1)

61-61: LGTM! Correct migration from deprecated ioutil.TempFile.

The replacement of ioutil.TempFile with os.CreateTemp correctly follows the Go 1.16 deprecation guidance. The function signature and behavior are identical, and error handling is properly preserved.

Also applies to: 77-77

pkg/controller/servingcert/starter/starter.go (1)

105-105: LGTM! Correct migration from deprecated ioutil.ReadFile.

The replacement of ioutil.ReadFile with os.ReadFile correctly follows the Go 1.16 deprecation guidance. The function signature and behavior are identical, and the existing error handling (including os.IsNotExist check) continues to work correctly.

pkg/controller/cabundleinjector/starter.go (2)

10-11: LGTM! Import adjustment.

The import block reordering is clean and maintains proper organization.


55-55: LGTM! Correct migration from deprecated ioutil.ReadFile.

All three replacements of ioutil.ReadFile with os.ReadFile correctly follow the Go 1.16 deprecation guidance. The function signature and behavior are identical, and the existing error handling (including os.IsNotExist check on line 67) continues to work correctly.

Also applies to: 61-61, 66-66


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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 24, 2025

[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 p0lyn0mial 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
Contributor

openshift-ci bot commented Nov 24, 2025

@sebrandon1: all tests passed!

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.

@xingxingxia
Copy link

@sebrandon1 @coderabbitai

err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
has one ioutil.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the specific file mentioned by the user
echo "=== Examining pkg/operator/v4_00_assets/bindata.go ==="
cat pkg/operator/v4_00_assets/bindata.go | head -20
echo ""
echo "=== Looking for ioutil usage around line 614 ==="
sed -n '610,620p' pkg/operator/v4_00_assets/bindata.go

echo ""
echo "=== Searching for all remaining ioutil usages in the codebase ==="
rg -n 'ioutil\.' --type=go

echo ""
echo "=== Checking if bindata.go is a generated file ==="
head -5 pkg/operator/v4_00_assets/bindata.go

Length of output: 1466


@xingxingxia @sebrandon1 Good catch! I've verified that pkg/operator/v4_00_assets/bindata.go line 614 does indeed contain a remaining ioutil.WriteFile usage (and an io/ioutil import on line 15). This is actually the only remaining ioutil usage in the entire codebase.

However, this file is a generated file created by go-bindata, as indicated by the header comment:

// Code generated for package v4_00_assets by go-bindata DO NOT EDIT. (@generated)

To address this ioutil usage, you'll need to:

  1. Regenerate the bindata file using the go-bindata tool (or its replacement) with updated code that uses os.WriteFile instead of ioutil.WriteFile
  2. Check if you're using an older version of go-bindata that still generates ioutil calls, and update to a newer version if available
  3. Alternatively, consider migrating to a more modern alternative like go:embed (introduced in Go 1.16) if feasible for your use case

Would you like me to help investigate the bindata generation process or search for the command/script that generates this file?

@sebrandon1
Copy link
Member Author

Yes, this is bindata so I didn't edit that file.

@xingxingxia
Copy link

Maybe it needs regenerated to be updated?

@sebrandon1
Copy link
Member Author

I think that's a good plan. I wonder if that should be a separate PR because regenerating might encompass more changes than just ioutil.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants