Skip to content

Commit

Permalink
Merge pull request #109692 from yxxhero/remove_ioutil_in_kubelet
Browse files Browse the repository at this point in the history
remove ioutil in kubelet
  • Loading branch information
k8s-ci-robot committed Jun 3, 2022
2 parents 0c0b528 + 4fac748 commit 60902b7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
5 changes: 2 additions & 3 deletions pkg/kubelet/cm/pod_container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/kubelet_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package kubelet
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"

cadvisorapiv1 "github.com/google/cadvisor/info/v1"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -370,15 +370,15 @@ 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
}
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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kubelet_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package kubelet

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kubelet_volumes_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ import (
)

func validateDirExists(dir string) error {
_, err := ioutil.ReadDir(dir)
_, err := os.ReadDir(dir)
if err != nil {
return err
}
return nil
}

func validateDirNotExists(dir string) error {
_, err := ioutil.ReadDir(dir)
_, err := os.ReadDir(dir)
if os.IsNotExist(err) {
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubelet/kuberuntime/kuberuntime_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/url"
"os"
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/logs/container_log_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubelet/volumemanager/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package reconciler
import (
"context"
"fmt"
"io/ioutil"
"io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 60902b7

Please sign in to comment.