utils icon indicating copy to clipboard operation
utils copied to clipboard

Replace deprecated ioutil functions

Open krishnakeshan opened this issue 1 year ago • 2 comments

Is your feature request related to a problem?/Why is this needed This project uses the ioutil package for the following functions

ReadAll
TempDir
ReadFile
WriteFile
ReadDir

The functions in ioutil have been deprecated in favour of similar functions in io and os. While some of these deprecated functions internally call the corresponding, recommended, io and os functions, we could benefit by replacing these usages directly in the project code.

Describe the solution you'd like in detail Replace usages of deprecated functions on a case-by-case basis with functions in os and io. The following command finds all files in the utils project importing the ioutils package:

grep -Rl "io/ioutil" .

and the result is

./temp/dir.go
./temp/dir_test.go
./io/read_test.go
./io/read.go
./inotify/inotify_linux_test.go
./exec/stdiopipe_test.go
./exec/exec_test.go
./mount/mount_windows_test.go
./mount/mount_linux_test.go
./mount/mount_helper_unix_test.go
./mount/safe_format_and_mount_test.go
./mount/mount_helper_test.go
./nsenter/nsenter_test.go

A simple MR replacing usages in these files with relevant (perhaps improved?) tests would be the solution. Almost all of the functions listed in the previous section have become wrappers around the newer functions. However, ioutil.ReadDir's replacement os.ReadDir offers supposedly better efficiency and the return type changes from fs.FileInfo -> fs.DirEntry and it returns a partial result in the case of an error while reading the directory. These changes do not matter in the context of this project and a simple replacement will work with no additional changes.

I've created a branch for this fix in my fork and go test ./... reports no errors

?   	k8s.io/utils/clock	[no test files]
ok  	k8s.io/utils/buffer	0.366s
ok  	k8s.io/utils/clock/testing	0.657s
?   	k8s.io/utils/inotify	[no test files]
?   	k8s.io/utils/internal/third_party/forked/golang/golang-lru	[no test files]
ok  	k8s.io/utils/cpuset	0.934s
ok  	k8s.io/utils/diff	1.485s
ok  	k8s.io/utils/env	1.206s
?   	k8s.io/utils/nsenter	[no test files]
ok  	k8s.io/utils/exec	4.072s
ok  	k8s.io/utils/exec/testing	1.685s
ok  	k8s.io/utils/field	1.661s
ok  	k8s.io/utils/integer	1.915s
ok  	k8s.io/utils/internal/third_party/forked/golang/net	2.192s
ok  	k8s.io/utils/io	2.250s
ok  	k8s.io/utils/keymutex	6.247s
ok  	k8s.io/utils/lru	7.261s
ok  	k8s.io/utils/mount	2.274s
ok  	k8s.io/utils/net	2.153s
ok  	k8s.io/utils/net/ebtables	2.368s
ok  	k8s.io/utils/path	2.328s
ok  	k8s.io/utils/pointer	2.272s
ok  	k8s.io/utils/ptr	1.672s
ok  	k8s.io/utils/semantic	1.706s
ok  	k8s.io/utils/set	1.696s
ok  	k8s.io/utils/strings	1.680s
ok  	k8s.io/utils/strings/slices	1.561s
ok  	k8s.io/utils/temp	1.647s
ok  	k8s.io/utils/temp/temptest	1.545s
ok  	k8s.io/utils/third_party/forked/golang/reflect	1.582s
ok  	k8s.io/utils/trace	1.598s

If this issue gets triaged, I can create a pull request.

Describe alternatives you've considered N/A

Additional context N/A

krishnakeshan avatar Dec 23 '23 16:12 krishnakeshan

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Mar 22 '24 16:03 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Apr 21 '24 17:04 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar May 21 '24 17:05 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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.

k8s-ci-robot avatar May 21 '24 17:05 k8s-ci-robot