Skip to content

Conversation

@jhadvig
Copy link
Member

@jhadvig jhadvig commented Jan 9, 2026

/assign @Leo6Leo

@jhadvig jhadvig changed the title Replace deprecated io/ioutil pkg NO-JIRA: Replace deprecated io/ioutil pkg Jan 9, 2026
@openshift-ci-robot
Copy link
Contributor

@jhadvig: This pull request explicitly references no jira issue.

Details

In response to this:

/assign @Leo6Leo

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-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 9, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

Walkthrough

This pull request systematically migrates the codebase from the deprecated io/ioutil package to standard library equivalents: replacing ioutil.ReadFile with os.ReadFile, ioutil.ReadAll with io.ReadAll, ioutil.Discard with io.Discard, and ioutil.NopCloser with io.NopCloser across 22 files.

Changes

Cohort / File(s) Summary
Helm Actions Tests – Discard and File I/O Migration
pkg/helm/actions/get_chart_test.go, pkg/helm/actions/get_release_test.go, pkg/helm/actions/install_chart_test.go, pkg/helm/actions/upgrade_release_test.go
Replaced ioutil.Discard with io.Discard and ioutil.ReadFile with os.ReadFile in multiple test configurations and file-read operations; updated imports from io/ioutil to io and os.
Helm Actions Tests – Discard-Only Migration
pkg/helm/actions/list_releases_test.go, pkg/helm/actions/release_history_test.go, pkg/helm/actions/rollback_release_test.go, pkg/helm/actions/template_test.go, pkg/helm/actions/uninstall_release_test.go
Replaced ioutil.Discard with io.Discard and updated import from io/ioutil to io in KubeClient initialization.
Helm Actions Tests – ReadAll Migration
pkg/helm/actions/auth_test.go, pkg/helm/actions/setup_test.go
Replaced ioutil.ReadFile with os.ReadFile (auth_test.go) and ioutil.ReadAll with io.ReadAll (setup_test.go); updated imports accordingly.
Helm Chartproxy and Related Packages
pkg/helm/chartproxy/repos.go, pkg/helm/chartproxy/repos_test.go, pkg/helm/chartproxy/proxy_test.go
Replaced ioutil.ReadFile with os.ReadFile, ioutil.ReadAll with io.ReadAll, and ioutil.NopCloser with io.NopCloser; updated imports from io/ioutil to io and os.
Stream Read Operations
pkg/graphql/resolver/k8s.go, pkg/helm/metrics/metrics_test.go, pkg/proxy/proxy_test.go, pkg/terminal/proxy.go
Replaced ioutil.ReadAll with io.ReadAll and ioutil.NopCloser with io.NopCloser; updated import from io/ioutil to io.
File Read Operations
pkg/devfile/sample_test.go, pkg/server/certs.go, pkg/serverconfig/config.go
Replaced ioutil.ReadFile with os.ReadFile and updated import from io/ioutil to os.
Chart Verifier Tests
pkg/helm/chartverifier/chart_verifier_test.go
Replaced ioutil.Discard with io.Discard and updated import from io/ioutil to io.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

✨ Finishing touches
  • 📝 Generate docstrings

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

@openshift-ci openshift-ci bot requested review from TheRealJon and sowmya-sl January 9, 2026 14:12
@openshift-ci openshift-ci bot added the component/backend Related to backend label Jan 9, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 9, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jhadvig

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 Jan 9, 2026
Copy link

@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

Caution

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

⚠️ Outside diff range comments (1)
pkg/helm/chartproxy/repos.go (1)

83-93: Add defer resp.Body.Close() to prevent resource leak.

The HTTP response body from httpClient.Get() is never closed, causing a resource leak that can lead to connection pool exhaustion and memory leaks over time.

🔧 Proposed fix to close the response body
 	resp, err := httpClient.Get(indexURL)
 	if err != nil {
 		return nil, err
 	}
+	defer resp.Body.Close()
 	if resp.StatusCode != 200 {
 		return nil, errors.New(fmt.Sprintf("Response for %v returned %v with status code %v", indexURL, resp, resp.StatusCode))
 	}
 	body, err := io.ReadAll(resp.Body)
🤖 Fix all issues with AI agents
In @pkg/helm/actions/auth_test.go:
- Around line 3-6: The test currently calls os.ReadFile for "./server.crt" and
"./server.key" but ignores the returned errors; change these calls to check the
error and fail the test immediately (use t.Fatalf or t.Fatal) when os.ReadFile
returns a non-nil error so the test stops with a clear message about failing to
read the certificate/key (refer to the variables holding the cert/key bytes and
the test function in pkg/helm/actions/auth_test.go where the reads occur, lines
around the existing os.ReadFile calls).
🧹 Nitpick comments (3)
pkg/helm/actions/setup_test.go (1)

88-105: Consider capturing command stderr to improve error messages.

The current implementation redirects the command's stderr to os.Stderr (line 91), then attempts to read from os.Stderr in error handlers (lines 94, 100). This won't work as intended because os.Stderr is a write-only stream for the current process—you can't read back output that's already been written.

To include actual stderr content in error messages, capture it to a buffer instead.

♻️ Proposed fix to capture stderr
 func ExecuteScript(filepath string, waitForCompletion bool) error {
+	var stderr bytes.Buffer
 	tlsCmd := exec.Command(filepath)
 	tlsCmd.Stdout = os.Stdout
-	tlsCmd.Stderr = os.Stderr
+	tlsCmd.Stderr = &stderr
 	err := tlsCmd.Start()
 	if err != nil {
-		bytes, _ := io.ReadAll(os.Stderr)
-		return fmt.Errorf("Error starting program :%s:%s:%w", filepath, string(bytes), err)
+		return fmt.Errorf("Error starting program :%s:%s:%w", filepath, stderr.String(), err)
 	}
 	if waitForCompletion {
 		err = tlsCmd.Wait()
 		if err != nil {
-			bytes, _ := io.ReadAll(os.Stderr)
-			return fmt.Errorf("Error waiting program :%s:%s:%w", filepath, string(bytes), err)
+			return fmt.Errorf("Error waiting program :%s:%s:%w", filepath, stderr.String(), err)
 		}
 	}
 	return nil
 }

Add bytes to imports:

import (
	"bytes"
	"fmt"
	"io"
	"os"
	"os/exec"
	"testing"
	"time"

	"helm.sh/helm/v3/pkg/cli"
)
pkg/helm/chartproxy/repos_test.go (1)

633-634: API replacement is correct; however, consider refactoring the stderr handling.

The replacement of ioutil.ReadAll with io.ReadAll is correct. However, there's a pre-existing issue with the error handling logic: attempting to read from os.Stderr doesn't work as intended because it's the process's own standard error stream, not the command's output. Since tlsCmd.Stderr = os.Stderr (line 630), command errors are already being written directly to the process's stderr, making this read operation ineffective (it would return empty bytes or fail).

If you want to capture the command's stderr for inclusion in error messages, consider using a bytes.Buffer:

♻️ Proposed refactor to capture command stderr
 func ExecuteScript(filepath string, waitForCompletion bool) error {
 	tlsCmd := exec.Command(filepath)
+	var stderrBuf bytes.Buffer
 	tlsCmd.Stdout = os.Stdout
-	tlsCmd.Stderr = os.Stderr
+	tlsCmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
 	err := tlsCmd.Start()
 	if err != nil {
-		bytes, _ := io.ReadAll(os.Stderr)
-		return fmt.Errorf("Error starting command :%s:%s:%w", filepath, string(bytes), err)
+		return fmt.Errorf("Error starting command :%s:%s:%w", filepath, stderrBuf.String(), err)
 	}
 	if waitForCompletion {
 		err = tlsCmd.Wait()
 		if err != nil {
-			bytes, _ := io.ReadAll(os.Stderr)
-			return fmt.Errorf("Error waiting command :%s:%s:%w", filepath, string(bytes), err)
+			return fmt.Errorf("Error waiting command :%s:%s:%w", filepath, stderrBuf.String(), err)
 		}
 	}
 	return nil
 }

This captures stderr in a buffer while still writing it to the console, allowing the error messages to include actual command output.

Also applies to: 639-640

pkg/terminal/proxy.go (1)

239-255: io.ReadAll replacement is correct; consider dropping redundant io.NopCloser here.
http.NewRequest will wrap an io.Reader body with io.NopCloser automatically.

Proposed tweak
-	wkspReq, err := http.NewRequest(http.MethodPost, host.String(), io.NopCloser(bytes.NewReader(body)))
+	wkspReq, err := http.NewRequest(http.MethodPost, host.String(), bytes.NewReader(body))
📜 Review details

Configuration used: Organization 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 f494af4 and 64f5e7f.

📒 Files selected for processing (22)
  • pkg/devfile/sample_test.go
  • pkg/graphql/resolver/k8s.go
  • pkg/helm/actions/auth_test.go
  • pkg/helm/actions/get_chart_test.go
  • pkg/helm/actions/get_release_test.go
  • pkg/helm/actions/install_chart_test.go
  • pkg/helm/actions/list_releases_test.go
  • pkg/helm/actions/release_history_test.go
  • pkg/helm/actions/rollback_release_test.go
  • pkg/helm/actions/setup_test.go
  • pkg/helm/actions/template_test.go
  • pkg/helm/actions/uninstall_release_test.go
  • pkg/helm/actions/upgrade_release_test.go
  • pkg/helm/chartproxy/proxy_test.go
  • pkg/helm/chartproxy/repos.go
  • pkg/helm/chartproxy/repos_test.go
  • pkg/helm/chartverifier/chart_verifier_test.go
  • pkg/helm/metrics/metrics_test.go
  • pkg/proxy/proxy_test.go
  • pkg/server/certs.go
  • pkg/serverconfig/config.go
  • pkg/terminal/proxy.go
🧰 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/helm/actions/list_releases_test.go
  • pkg/graphql/resolver/k8s.go
  • pkg/serverconfig/config.go
  • pkg/helm/actions/upgrade_release_test.go
  • pkg/helm/actions/auth_test.go
  • pkg/helm/actions/get_chart_test.go
  • pkg/proxy/proxy_test.go
  • pkg/helm/actions/get_release_test.go
  • pkg/helm/actions/setup_test.go
  • pkg/terminal/proxy.go
  • pkg/helm/metrics/metrics_test.go
  • pkg/helm/actions/release_history_test.go
  • pkg/devfile/sample_test.go
  • pkg/helm/chartproxy/repos.go
  • pkg/helm/chartproxy/repos_test.go
  • pkg/helm/actions/template_test.go
  • pkg/helm/chartproxy/proxy_test.go
  • pkg/helm/actions/rollback_release_test.go
  • pkg/helm/actions/uninstall_release_test.go
  • pkg/helm/actions/install_chart_test.go
  • pkg/helm/chartverifier/chart_verifier_test.go
  • pkg/server/certs.go
🔇 Additional comments (34)
pkg/helm/chartverifier/chart_verifier_test.go (2)

5-5: LGTM! Correct migration from deprecated package.

The import change from io/ioutil to io correctly follows Go's deprecation guidance (Go 1.16+).


31-31: LGTM! Correct usage of the new API.

Both occurrences correctly replace ioutil.Discard with io.Discard, maintaining identical functionality while using the current standard library API.

Also applies to: 48-48

pkg/helm/actions/uninstall_release_test.go (1)

6-6: LGTM! Clean migration from deprecated io/ioutil.

The replacement of ioutil.Discard with io.Discard is correct and consistent across all test functions. This migration aligns with Go 1.16+ best practices and has no impact on test behavior.

Also applies to: 41-41, 78-78, 124-124, 174-174

pkg/helm/actions/template_test.go (1)

5-5: LGTM! Clean migration from deprecated io/ioutil.

The changes correctly replace deprecated ioutil.Discard with io.Discard and update the import accordingly. The functionality remains identical and improves maintainability.

Also applies to: 99-99, 185-185

pkg/helm/actions/rollback_release_test.go (2)

6-6: LGTM! Correct migration from deprecated package.

The import change from io/ioutil to io follows Go's deprecation guidance (deprecated since Go 1.16).


55-55: LGTM! Correct replacement of deprecated API.

Both occurrences correctly replace ioutil.Discard with io.Discard, preserving the exact same behavior for discarding KubeClient output in test setup.

Also applies to: 100-100

pkg/proxy/proxy_test.go (2)

4-4: LGTM! Correct import migration.

The import change from io/ioutil to io aligns with Go 1.16+ best practices for moving away from the deprecated ioutil package.


56-56: LGTM! Correct function migration.

The replacement of ioutil.ReadAll with io.ReadAll is the proper migration path. The function signatures are identical, ensuring no behavior change.

pkg/helm/actions/setup_test.go (1)

5-5: LGTM! Correct deprecation migration.

The import change from io/ioutil to io correctly reflects the migration of ReadAll to the io package in Go 1.16+.

pkg/helm/chartproxy/repos.go (1)

9-9: LGTM! Migration from deprecated package is correct.

The changes properly migrate from the deprecated io/ioutil package to the standard io package. Both the import update and the io.ReadAll function call replacement are correct and maintain identical behavior.

Also applies to: 90-90

pkg/helm/chartproxy/repos_test.go (2)

6-6: LGTM! Import and API update are correct.

The addition of the io import and the replacement of ioutil.NopCloser with io.NopCloser correctly follows Go's deprecation migration path for the io/ioutil package.

Also applies to: 378-378


395-395: LGTM! File reading API correctly updated.

The replacements of ioutil.ReadFile with os.ReadFile are correct and properly follow Go's deprecation guidelines. Error handling for file operations remains appropriate.

Also applies to: 598-600

pkg/helm/actions/list_releases_test.go (2)

3-15: Good stdlib migration (ioutil.Discardio.Discard).

This keeps the test behavior the same while removing deprecated io/ioutil usage.

Also applies to: 45-50


3-5: Go version (1.24.0) fully supports io.Discard and os.ReadFile — no compatibility concerns.

The codebase targets Go 1.24.0, which exceeds the Go 1.16+ requirement. The file successfully uses io.Discard at line 47. No action needed.

pkg/server/certs.go (1)

3-16: Correct replacement (ioutil.ReadFileos.ReadFile).

pkg/serverconfig/config.go (1)

3-12: Correct replacement (ioutil.ReadFileos.ReadFile) with no behavioral change.

Also applies to: 137-143

pkg/helm/metrics/metrics_test.go (1)

3-14: Correct replacement (ioutil.ReadAllio.ReadAll) with same test semantics.

Also applies to: 151-160

pkg/devfile/sample_test.go (2)

3-15: Import change looks correct (switch to os).


138-149: os.ReadFile swap is correct and keeps behavior the same.

pkg/helm/chartproxy/proxy_test.go (3)

3-16: Import update to os is correct for ReadFile usage.


120-129: os.ReadFile use for loading index testdata is correct.


163-172: os.ReadFile use for loading expected merged index is correct.

pkg/helm/actions/release_history_test.go (3)

3-14: Import update to io is correct for io.Discard.


41-46: io.Discard replacement is correct (same sink semantics).


97-103: io.Discard replacement is correct in the non-exist history test as well.

pkg/terminal/proxy.go (1)

3-13: Import update is consistent with io.ReadAll / io.NopCloser usage.

pkg/graphql/resolver/k8s.go (4)

3-16: Import update to io is correct for io.ReadAll.


22-41: io.ReadAll replacement in FetchURL is correct and preserves behavior.


100-106: io.ReadAll replacement in error-body handling is correct.


145-151: io.ReadAll replacement in SSAR error-body handling is correct.

pkg/helm/actions/install_chart_test.go (1)

5-6: LGTM! Clean migration from deprecated ioutil.

The migration from io/ioutil to io and os packages is correct and follows Go 1.16+ best practices. All replacements are functionally equivalent:

  • ioutil.Discardio.Discard
  • ioutil.ReadFileos.ReadFile

Also applies to: 98-98, 177-177, 188-188, 190-190, 201-201, 274-274, 297-297, 361-361

pkg/helm/actions/upgrade_release_test.go (1)

5-6: LGTM! Consistent migration pattern.

All ioutil usages correctly replaced with modern equivalents across multiple test functions.

Also applies to: 107-107, 136-136, 138-138, 214-214, 282-282, 344-344, 456-456, 485-485, 487-487, 575-575, 667-667

pkg/helm/actions/get_release_test.go (1)

5-6: LGTM! Correct API migration.

All deprecated ioutil functions properly replaced with their modern counterparts.

Also applies to: 74-74, 159-159, 170-170, 172-172, 183-183

pkg/helm/actions/get_chart_test.go (1)

4-5: LGTM! Complete and correct migration.

All ioutil usages consistently migrated to io and os packages across test cases.

Also applies to: 93-93, 206-206, 220-220, 222-222, 233-233, 340-340

Comment on lines 3 to 6
import (
"io/ioutil"
"os"
"testing"

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don’t ignore os.ReadFile errors in tests.

If ./server.crt / ./server.key can’t be read, the test will proceed with empty/nil data and fail later in less obvious ways.

Proposed fix
 			if tt.hasTLS {
-				cert, _ := os.ReadFile("./server.crt")
-				key, _ := os.ReadFile("./server.key")
+				cert, err := os.ReadFile("./server.crt")
+				require.NoError(t, err)
+				key, err := os.ReadFile("./server.key")
+				require.NoError(t, err)
 				tlsSecret := &v1.Secret{
 					Data: map[string][]byte{
 						tlsSecretCertKey: cert,
 						tlsSecretKey:     key,
 					},
 					ObjectMeta: metav1.ObjectMeta{Name: "test-tls", Namespace: configNamespace},
 				}
 				objs = append(objs, tlsSecret)
 			}

Also applies to: 71-82

🤖 Prompt for AI Agents
In @pkg/helm/actions/auth_test.go around lines 3 - 6, The test currently calls
os.ReadFile for "./server.crt" and "./server.key" but ignores the returned
errors; change these calls to check the error and fail the test immediately (use
t.Fatalf or t.Fatal) when os.ReadFile returns a non-nil error so the test stops
with a clear message about failing to read the certificate/key (refer to the
variables holding the cert/key bytes and the test function in
pkg/helm/actions/auth_test.go where the reads occur, lines around the existing
os.ReadFile calls).

Copy link
Contributor

@Leo6Leo Leo6Leo left a comment

Choose a reason for hiding this comment

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

@Leo6Leo
Copy link
Contributor

Leo6Leo commented Jan 13, 2026

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 13, 2026

@jhadvig: 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.

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. component/backend Related to backend 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