mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
remove ioutil in kubelet
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
537941765f
commit
4fac7486d4
@ -19,13 +19,12 @@ package cm
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
@ -240,7 +239,7 @@ func (m *podContainerManagerImpl) GetAllPodsFromCgroups() (map[types.UID]CgroupN
|
||||
// get the subsystems QoS cgroup absolute name
|
||||
qcConversion := m.cgroupManager.Name(qosContainerName)
|
||||
qc := path.Join(val, qcConversion)
|
||||
dirInfo, err := ioutil.ReadDir(qc)
|
||||
dirInfo, err := os.ReadDir(qc)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
|
@ -19,8 +19,8 @@ package kubelet
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
cadvisorapiv1 "github.com/google/cadvisor/info/v1"
|
||||
@ -301,7 +301,7 @@ func (kl *Kubelet) getPodVolumePathListFromDisk(podUID types.UID) ([]string, err
|
||||
return volumes, nil
|
||||
}
|
||||
|
||||
volumePluginDirs, err := ioutil.ReadDir(podVolDir)
|
||||
volumePluginDirs, err := os.ReadDir(podVolDir)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Could not read directory", "path", podVolDir)
|
||||
return volumes, err
|
||||
@ -370,7 +370,7 @@ func (kl *Kubelet) getPodVolumeSubpathListFromDisk(podUID types.UID) ([]string,
|
||||
}
|
||||
|
||||
// Explicitly walks /<volume>/<container name>/<subPathIndex>
|
||||
volumePluginDirs, err := ioutil.ReadDir(podSubpathsDir)
|
||||
volumePluginDirs, err := os.ReadDir(podSubpathsDir)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Could not read directory", "path", podSubpathsDir)
|
||||
return volumes, err
|
||||
@ -378,7 +378,7 @@ func (kl *Kubelet) getPodVolumeSubpathListFromDisk(podUID types.UID) ([]string,
|
||||
for _, volumePluginDir := range volumePluginDirs {
|
||||
volumePluginName := volumePluginDir.Name()
|
||||
volumePluginPath := filepath.Join(podSubpathsDir, volumePluginName)
|
||||
containerDirs, err := ioutil.ReadDir(volumePluginPath)
|
||||
containerDirs, err := os.ReadDir(volumePluginPath)
|
||||
if err != nil {
|
||||
return volumes, fmt.Errorf("could not read directory %s: %v", volumePluginPath, err)
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ const (
|
||||
|
||||
// Get a list of pods that have data directories.
|
||||
func (kl *Kubelet) listPodsFromDisk() ([]types.UID, error) {
|
||||
podInfos, err := ioutil.ReadDir(kl.getPodsDir())
|
||||
podInfos, err := os.ReadDir(kl.getPodsDir())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ package kubelet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
@ -209,7 +209,7 @@ func (kl *Kubelet) cleanupOrphanedPodDirs(pods []*v1.Pod, runningPods []*kubecon
|
||||
|
||||
// Call RemoveAllOneFilesystem for remaining subdirs under the pod directory
|
||||
podDir := kl.getPodDir(uid)
|
||||
podSubdirs, err := ioutil.ReadDir(podDir)
|
||||
podSubdirs, err := os.ReadDir(podDir)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Could not read directory", "path", podDir)
|
||||
orphanRemovalErrors = append(orphanRemovalErrors, fmt.Errorf("orphaned pod %q found, but error occurred during reading the pod dir from disk: %v", uid, err))
|
||||
|
@ -35,7 +35,7 @@ import (
|
||||
)
|
||||
|
||||
func validateDirExists(dir string) error {
|
||||
_, err := ioutil.ReadDir(dir)
|
||||
_, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -43,7 +43,7 @@ func validateDirExists(dir string) error {
|
||||
}
|
||||
|
||||
func validateDirNotExists(dir string) error {
|
||||
_, err := ioutil.ReadDir(dir)
|
||||
_, err := os.ReadDir(dir)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -139,7 +138,7 @@ func calcRestartCountByLogDir(path string) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
restartCount := int(0)
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func TestRotateLogs(t *testing.T) {
|
||||
require.NoError(t, c.rotateLogs())
|
||||
|
||||
timestamp := now.Format(timestampFormat)
|
||||
logs, err := ioutil.ReadDir(dir)
|
||||
logs, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, logs, 5)
|
||||
assert.Equal(t, testLogs[0], logs[0].Name())
|
||||
@ -223,7 +223,7 @@ func TestClean(t *testing.T) {
|
||||
err = c.Clean("container-3")
|
||||
require.NoError(t, err)
|
||||
|
||||
logs, err := ioutil.ReadDir(dir)
|
||||
logs, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, logs, 4)
|
||||
assert.Equal(t, testLogs[0], logs[0].Name())
|
||||
@ -259,7 +259,7 @@ func TestCleanupUnusedLog(t *testing.T) {
|
||||
assert.Len(t, got, 2)
|
||||
assert.Equal(t, []string{testLogs[0], testLogs[3]}, got)
|
||||
|
||||
logs, err := ioutil.ReadDir(dir)
|
||||
logs, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, logs, 2)
|
||||
assert.Equal(t, testLogs[0], filepath.Join(dir, logs[0].Name()))
|
||||
@ -309,7 +309,7 @@ func TestRemoveExcessLog(t *testing.T) {
|
||||
assert.Equal(t, name, filepath.Base(got[i]))
|
||||
}
|
||||
|
||||
logs, err := ioutil.ReadDir(dir)
|
||||
logs, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, logs, len(test.expect))
|
||||
for i, name := range test.expect {
|
||||
|
@ -22,7 +22,7 @@ package reconciler
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -669,7 +669,7 @@ func (rc *reconciler) updateStates(volumesNeedUpdate map[v1.UniqueVolumeName]*re
|
||||
// It returns a list of pod volume information including pod's uid, volume's plugin name, mount path,
|
||||
// and volume spec name.
|
||||
func getVolumesFromPodDir(podDir string) ([]podVolume, error) {
|
||||
podsDirInfo, err := ioutil.ReadDir(podDir)
|
||||
podsDirInfo, err := os.ReadDir(podDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -691,8 +691,8 @@ func getVolumesFromPodDir(podDir string) ([]podVolume, error) {
|
||||
volumesDirs[v1.PersistentVolumeBlock] = path.Join(podDir, config.DefaultKubeletVolumeDevicesDirName)
|
||||
|
||||
for volumeMode, volumesDir := range volumesDirs {
|
||||
var volumesDirInfo []os.FileInfo
|
||||
if volumesDirInfo, err = ioutil.ReadDir(volumesDir); err != nil {
|
||||
var volumesDirInfo []fs.DirEntry
|
||||
if volumesDirInfo, err = os.ReadDir(volumesDir); err != nil {
|
||||
// Just skip the loop because given volumesDir doesn't exist depending on volumeMode
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user