Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated ioutil functions #298

Open
krishnakeshan opened this issue Dec 23, 2023 · 2 comments · May be fixed by #299
Open

Replace deprecated ioutil functions #298

krishnakeshan opened this issue Dec 23, 2023 · 2 comments · May be fixed by #299
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@krishnakeshan
Copy link

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 krishnakeshan linked a pull request Dec 23, 2023 that will close this issue
@k8s-triage-robot
Copy link

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-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 22, 2024
@k8s-triage-robot
Copy link

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-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants