replace ioutil with os, update doc

This commit is contained in:
charles-chenzz 2023-04-11 15:41:03 +08:00
parent ad18954259
commit ccf7ddacfc
9 changed files with 14 additions and 15 deletions

View File

@ -17,8 +17,8 @@ limitations under the License.
package admission
import (
"io/ioutil"
"net/http"
"os"
"time"
"k8s.io/klog/v2"
@ -55,7 +55,7 @@ func (c *Config) New(proxyTransport *http.Transport, egressSelector *egressselec
var cloudConfig []byte
if c.CloudConfigFile != "" {
var err error
cloudConfig, err = ioutil.ReadFile(c.CloudConfigFile)
cloudConfig, err = os.ReadFile(c.CloudConfigFile)
if err != nil {
klog.Fatalf("Error reading from cloud configuration file %s: %#v", c.CloudConfigFile, err)
}

View File

@ -91,7 +91,7 @@ func WriteTmpFile(fs utilfs.Filesystem, path string, data []byte) (tmpPath strin
}
}()
// Name() will be an absolute path when using utilfs.DefaultFS, because ioutil.TempFile passes
// Name() will be an absolute path when using utilfs.DefaultFS, because os.CreateTemp passes
// an absolute path to os.Open, and we ensure similar behavior in utilfs.FakeFS for testing.
tmpPath = tmpFile.Name()

View File

@ -22,7 +22,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"time"
@ -407,7 +406,7 @@ func TestReadLogsLimitsWithTimestamps(t *testing.T) {
logLineFmt := "2022-10-29T16:10:22.592603036-05:00 stdout P %v\n"
logLineNewLine := "2022-10-29T16:10:22.592603036-05:00 stdout F \n"
tmpfile, err := ioutil.TempFile("", "log.*.txt")
tmpfile, err := os.CreateTemp("", "log.*.txt")
assert.NoError(t, err)
count := 10000

View File

@ -17,7 +17,7 @@ limitations under the License.
package prober
import (
"io/ioutil"
"os"
"reflect"
"sync"
@ -111,7 +111,7 @@ func newTestManager() *manager {
// Add test pod to pod manager, so that status manager can get the pod from pod manager if needed.
podManager.AddPod(getTestPod())
testRootDir := ""
if tempDir, err := ioutil.TempDir("", "kubelet_test."); err != nil {
if tempDir, err := os.MkdirTemp("", "kubelet_test."); err != nil {
return nil
} else {
testRootDir = tempDir

View File

@ -19,9 +19,9 @@ package prober
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"sync"
"sync/atomic"
"testing"
@ -82,7 +82,7 @@ func TestTCPPortExhaustion(t *testing.T) {
for _, tt := range tests {
t.Run(fmt.Sprintf(tt.name), func(t *testing.T) {
testRootDir := ""
if tempDir, err := ioutil.TempDir("", "kubelet_test."); err != nil {
if tempDir, err := os.MkdirTemp("", "kubelet_test."); err != nil {
t.Fatalf("can't make a temp rootdir: %v", err)
} else {
testRootDir = tempDir

View File

@ -19,7 +19,7 @@ package prober
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
@ -155,7 +155,7 @@ func TestDoProbe(t *testing.T) {
// Clean up.
testRootDir := ""
if tempDir, err := ioutil.TempDir("", "kubelet_test."); err != nil {
if tempDir, err := os.MkdirTemp("", "kubelet_test."); err != nil {
t.Fatalf("can't make a temp rootdir: %v", err)
} else {
testRootDir = tempDir

View File

@ -18,8 +18,8 @@ package status
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"reflect"
"strconv"
"strings"
@ -90,7 +90,7 @@ func newTestManager(kubeClient clientset.Interface) *manager {
podManager.AddPod(getTestPod())
podStartupLatencyTracker := util.NewPodStartupLatencyTracker()
testRootDir := ""
if tempDir, err := ioutil.TempDir("", "kubelet_test."); err != nil {
if tempDir, err := os.MkdirTemp("", "kubelet_test."); err != nil {
return nil
} else {
testRootDir = tempDir

View File

@ -85,7 +85,7 @@ func (fs *DefaultFs) RemoveAll(path string) error {
return os.RemoveAll(fs.prefix(path))
}
// Remove via os.RemoveAll
// Remove via os.Remove
func (fs *DefaultFs) Remove(name string) error {
return os.Remove(fs.prefix(name))
}

View File

@ -33,7 +33,7 @@ type Filesystem interface {
RemoveAll(path string) error
Remove(name string) error
// from "io/ioutil"
// from "os"
ReadFile(filename string) ([]byte, error)
TempDir(dir, prefix string) (string, error)
TempFile(dir, prefix string) (File, error)