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