mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Remove ioutil in kubelet and its tests
Signed-off-by: inosato <si17_21@yahoo.co.jp>
This commit is contained in:
parent
f6e163fe27
commit
3b95d3b076
@ -18,7 +18,7 @@ package kubelet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -84,17 +84,17 @@ func TestApplyKubeletConfigPatches(t *testing.T) {
|
|||||||
expectedOutput = []byte("bar: 1\nfoo: 0\n")
|
expectedOutput = []byte("bar: 1\nfoo: 0\n")
|
||||||
)
|
)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "patches")
|
dir, err := os.MkdirTemp("", "patches")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create temp dir: %v", err)
|
t.Fatalf("could not create temp dir: %v", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(dir, "kubeletconfiguration.yaml"), patch, 0644); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, "kubeletconfiguration.yaml"), patch, 0644); err != nil {
|
||||||
t.Fatalf("could not write patch file: %v", err)
|
t.Fatalf("could not write patch file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := applyKubeletConfigPatches(input, dir, ioutil.Discard)
|
output, err := applyKubeletConfigPatches(input, dir, io.Discard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not apply patch: %v", err)
|
t.Fatalf("could not apply patch: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -101,11 +100,11 @@ users:
|
|||||||
client-key: mycertvalid.key
|
client-key: mycertvalid.key
|
||||||
|
|
||||||
`)
|
`)
|
||||||
filevalid, err := ioutil.TempFile(fileDir, "kubeconfigvalid")
|
filevalid, err := os.CreateTemp(fileDir, "kubeconfigvalid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(filevalid.Name(), testDataValid, os.FileMode(0755))
|
os.WriteFile(filevalid.Name(), testDataValid, os.FileMode(0755))
|
||||||
|
|
||||||
testDataInvalid := []byte(`
|
testDataInvalid := []byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@ -141,11 +140,11 @@ users:
|
|||||||
client-key: mycertinvalid.key
|
client-key: mycertinvalid.key
|
||||||
|
|
||||||
`)
|
`)
|
||||||
fileinvalid, err := ioutil.TempFile(fileDir, "kubeconfiginvalid")
|
fileinvalid, err := os.CreateTemp(fileDir, "kubeconfiginvalid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(fileinvalid.Name(), testDataInvalid, os.FileMode(0755))
|
os.WriteFile(fileinvalid.Name(), testDataInvalid, os.FileMode(0755))
|
||||||
|
|
||||||
testDatabootstrap := []byte(`
|
testDatabootstrap := []byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@ -178,13 +177,13 @@ users:
|
|||||||
user:
|
user:
|
||||||
token: mytoken-b
|
token: mytoken-b
|
||||||
`)
|
`)
|
||||||
fileboot, err := ioutil.TempFile(fileDir, "kubeconfig")
|
fileboot, err := os.CreateTemp(fileDir, "kubeconfig")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(fileboot.Name(), testDatabootstrap, os.FileMode(0755))
|
os.WriteFile(fileboot.Name(), testDatabootstrap, os.FileMode(0755))
|
||||||
|
|
||||||
dir, err := ioutil.TempDir(fileDir, "k8s-test-certstore-current")
|
dir, err := os.MkdirTemp(fileDir, "k8s-test-certstore-current")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create the test directory %q: %v", dir, err)
|
t.Fatalf("Unable to create the test directory %q: %v", dir, err)
|
||||||
}
|
}
|
||||||
@ -316,12 +315,12 @@ users:
|
|||||||
user:
|
user:
|
||||||
token: mytoken-b
|
token: mytoken-b
|
||||||
`)
|
`)
|
||||||
f, err := ioutil.TempFile("", "kubeconfig")
|
f, err := os.CreateTemp("", "kubeconfig")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
ioutil.WriteFile(f.Name(), testData, os.FileMode(0755))
|
os.WriteFile(f.Name(), testData, os.FileMode(0755))
|
||||||
|
|
||||||
config, err := loadRESTClientConfig(f.Name())
|
config, err := loadRESTClientConfig(f.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,6 @@ package cm
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -320,7 +319,7 @@ func getCpuWeight(cpuShares *uint64) uint64 {
|
|||||||
|
|
||||||
// readUnifiedControllers reads the controllers available at the specified cgroup
|
// readUnifiedControllers reads the controllers available at the specified cgroup
|
||||||
func readUnifiedControllers(path string) (sets.String, error) {
|
func readUnifiedControllers(path string) (sets.String, error) {
|
||||||
controllersFileContent, err := ioutil.ReadFile(filepath.Join(path, "cgroup.controllers"))
|
controllersFileContent, err := os.ReadFile(filepath.Join(path, "cgroup.controllers"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ package cm
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -204,7 +203,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
|
|||||||
if failSwapOn {
|
if failSwapOn {
|
||||||
// Check whether swap is enabled. The Kubelet does not support running with swap enabled.
|
// Check whether swap is enabled. The Kubelet does not support running with swap enabled.
|
||||||
swapFile := "/proc/swaps"
|
swapFile := "/proc/swaps"
|
||||||
swapData, err := ioutil.ReadFile(swapFile)
|
swapData, err := os.ReadFile(swapFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
klog.InfoS("File does not exist, assuming that swap is disabled", "path", swapFile)
|
klog.InfoS("File does not exist, assuming that swap is disabled", "path", swapFile)
|
||||||
|
@ -21,7 +21,6 @@ package cm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -148,11 +147,11 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) {
|
|||||||
t.Skip("skipping cgroup v1 test on a cgroup v2 system")
|
t.Skip("skipping cgroup v1 test on a cgroup v2 system")
|
||||||
}
|
}
|
||||||
req := require.New(t)
|
req := require.New(t)
|
||||||
tempDir, err := ioutil.TempDir("", "")
|
tempDir, err := os.MkdirTemp("", "")
|
||||||
req.NoError(err)
|
req.NoError(err)
|
||||||
defer os.RemoveAll(tempDir)
|
defer os.RemoveAll(tempDir)
|
||||||
req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm))
|
req.NoError(os.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm))
|
||||||
req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm))
|
req.NoError(os.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm))
|
||||||
mountInt := mount.NewFakeMounter(
|
mountInt := mount.NewFakeMounter(
|
||||||
[]mount.MountPoint{
|
[]mount.MountPoint{
|
||||||
{
|
{
|
||||||
|
@ -18,15 +18,13 @@ package cpumanager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
@ -629,7 +627,7 @@ func TestCPUManagerGenerate(t *testing.T) {
|
|||||||
if testCase.isTopologyBroken {
|
if testCase.isTopologyBroken {
|
||||||
machineInfo = &cadvisorapi.MachineInfo{}
|
machineInfo = &cadvisorapi.MachineInfo{}
|
||||||
}
|
}
|
||||||
sDir, err := ioutil.TempDir("/tmp/", "cpu_manager_test")
|
sDir, err := os.MkdirTemp("/tmp/", "cpu_manager_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("cannot create state file: %s", err.Error())
|
t.Errorf("cannot create state file: %s", err.Error())
|
||||||
}
|
}
|
||||||
@ -1349,7 +1347,7 @@ func TestCPUManagerHandlePolicyOptions(t *testing.T) {
|
|||||||
t.Run(testCase.description, func(t *testing.T) {
|
t.Run(testCase.description, func(t *testing.T) {
|
||||||
machineInfo := &mockedMachineInfo
|
machineInfo := &mockedMachineInfo
|
||||||
nodeAllocatableReservation := v1.ResourceList{}
|
nodeAllocatableReservation := v1.ResourceList{}
|
||||||
sDir, err := ioutil.TempDir("/tmp/", "cpu_manager_test")
|
sDir, err := os.MkdirTemp("/tmp/", "cpu_manager_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("cannot create state file: %s", err.Error())
|
t.Errorf("cannot create state file: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -201,7 +200,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
|
testingDir, err := os.MkdirTemp("", "cpumanager_state_test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(testingDir)
|
defer os.RemoveAll(testingDir)
|
||||||
// create checkpoint manager for testing
|
// create checkpoint manager for testing
|
||||||
@ -258,7 +257,7 @@ func TestCheckpointStateStore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
|
testingDir, err := os.MkdirTemp("", "cpumanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -331,7 +330,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
|
testingDir, err := os.MkdirTemp("", "cpumanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -390,7 +389,7 @@ func TestCheckpointStateClear(t *testing.T) {
|
|||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.description, func(t *testing.T) {
|
t.Run(tc.description, func(t *testing.T) {
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
|
testingDir, err := os.MkdirTemp("", "cpumanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package devicemanager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -78,7 +77,7 @@ func (m *wrappedManagerImpl) PluginListAndWatchReceiver(r string, resp *pluginap
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tmpSocketDir() (socketDir, socketName, pluginSocketName string, err error) {
|
func tmpSocketDir() (socketDir, socketName, pluginSocketName string, err error) {
|
||||||
socketDir, err = ioutil.TempDir("", "device_plugin")
|
socketDir, err = os.MkdirTemp("", "device_plugin")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -592,7 +591,7 @@ func TestCheckpoint(t *testing.T) {
|
|||||||
resourceName2 := "domain2.com/resource2"
|
resourceName2 := "domain2.com/resource2"
|
||||||
resourceName3 := "domain2.com/resource3"
|
resourceName3 := "domain2.com/resource3"
|
||||||
as := assert.New(t)
|
as := assert.New(t)
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
ckm, err := checkpointmanager.NewCheckpointManager(tmpDir)
|
ckm, err := checkpointmanager.NewCheckpointManager(tmpDir)
|
||||||
@ -910,7 +909,7 @@ func TestPodContainerDeviceAllocation(t *testing.T) {
|
|||||||
podsStub := activePodsStub{
|
podsStub := activePodsStub{
|
||||||
activePods: []*v1.Pod{},
|
activePods: []*v1.Pod{},
|
||||||
}
|
}
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
testManager, err := getTestManager(tmpDir, podsStub.getActivePods, testResources)
|
testManager, err := getTestManager(tmpDir, podsStub.getActivePods, testResources)
|
||||||
@ -1009,7 +1008,7 @@ func TestGetDeviceRunContainerOptions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
as := require.New(t)
|
as := require.New(t)
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
@ -1071,7 +1070,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
|
|||||||
podsStub := activePodsStub{
|
podsStub := activePodsStub{
|
||||||
activePods: []*v1.Pod{},
|
activePods: []*v1.Pod{},
|
||||||
}
|
}
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
@ -1162,7 +1161,7 @@ func TestUpdatePluginResources(t *testing.T) {
|
|||||||
|
|
||||||
as := assert.New(t)
|
as := assert.New(t)
|
||||||
monitorCallback := func(resourceName string, devices []pluginapi.Device) {}
|
monitorCallback := func(resourceName string, devices []pluginapi.Device) {}
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
@ -1220,7 +1219,7 @@ func TestDevicePreStartContainer(t *testing.T) {
|
|||||||
podsStub := activePodsStub{
|
podsStub := activePodsStub{
|
||||||
activePods: []*v1.Pod{},
|
activePods: []*v1.Pod{},
|
||||||
}
|
}
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
@ -1282,7 +1281,7 @@ func TestDevicePreStartContainer(t *testing.T) {
|
|||||||
|
|
||||||
func TestResetExtendedResource(t *testing.T) {
|
func TestResetExtendedResource(t *testing.T) {
|
||||||
as := assert.New(t)
|
as := assert.New(t)
|
||||||
tmpDir, err := ioutil.TempDir("", "checkpoint")
|
tmpDir, err := os.MkdirTemp("", "checkpoint")
|
||||||
as.Nil(err)
|
as.Nil(err)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
ckm, err := checkpointmanager.NewCheckpointManager(tmpDir)
|
ckm, err := checkpointmanager.NewCheckpointManager(tmpDir)
|
||||||
@ -1392,7 +1391,7 @@ func TestReadPreNUMACheckpoint(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(socketDir)
|
defer os.RemoveAll(socketDir)
|
||||||
|
|
||||||
err = ioutil.WriteFile(filepath.Join(socketDir, deviceManagerCheckpointFilename), []byte(oldCheckpoint), 0644)
|
err = os.WriteFile(filepath.Join(socketDir, deviceManagerCheckpointFilename), []byte(oldCheckpoint), 0644)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
topologyStore := topologymanager.NewFakeManager()
|
topologyStore := topologymanager.NewFakeManager()
|
||||||
|
@ -18,7 +18,6 @@ package memorymanager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -1982,7 +1981,7 @@ func TestNewManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.description, func(t *testing.T) {
|
t.Run(testCase.description, func(t *testing.T) {
|
||||||
stateFileDirectory, err := ioutil.TempDir("/tmp/", "memory_manager_tests")
|
stateFileDirectory, err := os.MkdirTemp("/tmp/", "memory_manager_tests")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot create state file: %s", err.Error())
|
t.Errorf("Cannot create state file: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -111,7 +110,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "memorymanager_state_test")
|
testingDir, err := os.MkdirTemp("", "memorymanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -174,7 +173,7 @@ func TestCheckpointStateStore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "memorymanager_state_test")
|
testingDir, err := os.MkdirTemp("", "memorymanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -293,7 +292,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "memorymanager_state_test")
|
testingDir, err := os.MkdirTemp("", "memorymanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -362,7 +361,7 @@ func TestCheckpointStateClear(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := ioutil.TempDir("", "memorymanager_state_test")
|
testingDir, err := os.MkdirTemp("", "memorymanager_state_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -35,7 +34,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
|
|||||||
defer removeAll(dirName, t)
|
defer removeAll(dirName, t)
|
||||||
|
|
||||||
fileName := filepath.Join(dirName, "test_pod_config")
|
fileName := filepath.Join(dirName, "test_pod_config")
|
||||||
err = ioutil.WriteFile(fileName, []byte{1, 2, 3}, 0555)
|
err = os.WriteFile(fileName, []byte{1, 2, 3}, 0555)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to write test file %#v", err)
|
t.Fatalf("unable to write test file %#v", err)
|
||||||
}
|
}
|
||||||
@ -74,7 +73,7 @@ func TestExtractFromEmptyDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mkTempDir(prefix string) (string, error) {
|
func mkTempDir(prefix string) (string, error) {
|
||||||
return ioutil.TempDir(os.TempDir(), prefix)
|
return os.MkdirTemp(os.TempDir(), prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAll(dir string, t *testing.T) {
|
func removeAll(dir string, t *testing.T) {
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -36,7 +35,7 @@ type OSInterface interface {
|
|||||||
Hostname() (name string, err error)
|
Hostname() (name string, err error)
|
||||||
Chtimes(path string, atime time.Time, mtime time.Time) error
|
Chtimes(path string, atime time.Time, mtime time.Time) error
|
||||||
Pipe() (r *os.File, w *os.File, err error)
|
Pipe() (r *os.File, w *os.File, err error)
|
||||||
ReadDir(dirname string) ([]os.FileInfo, error)
|
ReadDir(dirname string) ([]os.DirEntry, error)
|
||||||
Glob(pattern string) ([]string, error)
|
Glob(pattern string) ([]string, error)
|
||||||
Open(name string) (*os.File, error)
|
Open(name string) (*os.File, error)
|
||||||
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
|
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
|
||||||
@ -98,9 +97,9 @@ func (RealOS) Pipe() (r *os.File, w *os.File, err error) {
|
|||||||
return os.Pipe()
|
return os.Pipe()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadDir will call ioutil.ReadDir to return the files under the directory.
|
// ReadDir will call os.ReadDir to return the files under the directory.
|
||||||
func (RealOS) ReadDir(dirname string) ([]os.FileInfo, error) {
|
func (RealOS) ReadDir(dirname string) ([]os.DirEntry, error) {
|
||||||
return ioutil.ReadDir(dirname)
|
return os.ReadDir(dirname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Glob will call filepath.Glob to return the names of all files matching
|
// Glob will call filepath.Glob to return the names of all files matching
|
||||||
|
107
pkg/kubelet/container/testing/mockdirentry.go
Normal file
107
pkg/kubelet/container/testing/mockdirentry.go
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Code generated by MockGen.
|
||||||
|
// Source: os (interfaces: DirEntry)
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
fs "io/fs"
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockDirEntry is a mock of DirEntry interface.
|
||||||
|
type MockDirEntry struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockDirEntryMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockDirEntryMockRecorder is the mock recorder for MockDirEntry.
|
||||||
|
type MockDirEntryMockRecorder struct {
|
||||||
|
mock *MockDirEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockDirEntry creates a new mock instance.
|
||||||
|
func NewMockDirEntry(ctrl *gomock.Controller) *MockDirEntry {
|
||||||
|
mock := &MockDirEntry{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockDirEntryMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockDirEntry) EXPECT() *MockDirEntryMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info mocks base method.
|
||||||
|
func (m *MockDirEntry) Info() (fs.FileInfo, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Info")
|
||||||
|
ret0, _ := ret[0].(fs.FileInfo)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info indicates an expected call of Info.
|
||||||
|
func (mr *MockDirEntryMockRecorder) Info() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockDirEntry)(nil).Info))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDir mocks base method.
|
||||||
|
func (m *MockDirEntry) IsDir() bool {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "IsDir")
|
||||||
|
ret0, _ := ret[0].(bool)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDir indicates an expected call of IsDir.
|
||||||
|
func (mr *MockDirEntryMockRecorder) IsDir() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsDir", reflect.TypeOf((*MockDirEntry)(nil).IsDir))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name mocks base method.
|
||||||
|
func (m *MockDirEntry) Name() string {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Name")
|
||||||
|
ret0, _ := ret[0].(string)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name indicates an expected call of Name.
|
||||||
|
func (mr *MockDirEntryMockRecorder) Name() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockDirEntry)(nil).Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type mocks base method.
|
||||||
|
func (m *MockDirEntry) Type() fs.FileMode {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Type")
|
||||||
|
ret0, _ := ret[0].(fs.FileMode)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type indicates an expected call of Type.
|
||||||
|
func (mr *MockDirEntryMockRecorder) Type() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Type", reflect.TypeOf((*MockDirEntry)(nil).Type))
|
||||||
|
}
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Generated via: mockgen os FileInfo
|
|
||||||
// Edited to include required boilerplate
|
|
||||||
// Source: os (interfaces: FileInfo)
|
|
||||||
|
|
||||||
package testing
|
|
||||||
|
|
||||||
import (
|
|
||||||
os "os"
|
|
||||||
time "time"
|
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Mock of FileInfo interface
|
|
||||||
type MockFileInfo struct {
|
|
||||||
ctrl *gomock.Controller
|
|
||||||
recorder *_MockFileInfoRecorder
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recorder for MockFileInfo (not exported)
|
|
||||||
type _MockFileInfoRecorder struct {
|
|
||||||
mock *MockFileInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMockFileInfo(ctrl *gomock.Controller) *MockFileInfo {
|
|
||||||
mock := &MockFileInfo{ctrl: ctrl}
|
|
||||||
mock.recorder = &_MockFileInfoRecorder{mock}
|
|
||||||
return mock
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) EXPECT() *_MockFileInfoRecorder {
|
|
||||||
return _m.recorder
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) IsDir() bool {
|
|
||||||
ret := _m.ctrl.Call(_m, "IsDir")
|
|
||||||
ret0, _ := ret[0].(bool)
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_mr *_MockFileInfoRecorder) IsDir() *gomock.Call {
|
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "IsDir")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) ModTime() time.Time {
|
|
||||||
ret := _m.ctrl.Call(_m, "ModTime")
|
|
||||||
ret0, _ := ret[0].(time.Time)
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_mr *_MockFileInfoRecorder) ModTime() *gomock.Call {
|
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "ModTime")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) Mode() os.FileMode {
|
|
||||||
ret := _m.ctrl.Call(_m, "Mode")
|
|
||||||
ret0, _ := ret[0].(os.FileMode)
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_mr *_MockFileInfoRecorder) Mode() *gomock.Call {
|
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Mode")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) Name() string {
|
|
||||||
ret := _m.ctrl.Call(_m, "Name")
|
|
||||||
ret0, _ := ret[0].(string)
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_mr *_MockFileInfoRecorder) Name() *gomock.Call {
|
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Name")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) Size() int64 {
|
|
||||||
ret := _m.ctrl.Call(_m, "Size")
|
|
||||||
ret0, _ := ret[0].(int64)
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_mr *_MockFileInfoRecorder) Size() *gomock.Call {
|
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Size")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_m *MockFileInfo) Sys() interface{} {
|
|
||||||
ret := _m.ctrl.Call(_m, "Sys")
|
|
||||||
ret0, _ := ret[0].(interface{})
|
|
||||||
return ret0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_mr *_MockFileInfoRecorder) Sys() *gomock.Call {
|
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Sys")
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ import (
|
|||||||
// of the real call.
|
// of the real call.
|
||||||
type FakeOS struct {
|
type FakeOS struct {
|
||||||
StatFn func(string) (os.FileInfo, error)
|
StatFn func(string) (os.FileInfo, error)
|
||||||
ReadDirFn func(string) ([]os.FileInfo, error)
|
ReadDirFn func(string) ([]os.DirEntry, error)
|
||||||
MkdirAllFn func(string, os.FileMode) error
|
MkdirAllFn func(string, os.FileMode) error
|
||||||
SymlinkFn func(string, string) error
|
SymlinkFn func(string, string) error
|
||||||
GlobFn func(string, string) bool
|
GlobFn func(string, string) bool
|
||||||
@ -109,7 +109,7 @@ func (FakeOS) Pipe() (r *os.File, w *os.File, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadDir is a fake call that returns the files under the directory.
|
// ReadDir is a fake call that returns the files under the directory.
|
||||||
func (f *FakeOS) ReadDir(dirname string) ([]os.FileInfo, error) {
|
func (f *FakeOS) ReadDir(dirname string) ([]os.DirEntry, error) {
|
||||||
if f.ReadDirFn != nil {
|
if f.ReadDirFn != nil {
|
||||||
return f.ReadDirFn(dirname)
|
return f.ReadDirFn(dirname)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -344,12 +343,12 @@ func ensureHostsFile(fileName string, hostIPs []string, hostName, hostDomainName
|
|||||||
hostsFileContent = managedHostsFileContent(hostIPs, hostName, hostDomainName, hostAliases)
|
hostsFileContent = managedHostsFileContent(hostIPs, hostName, hostDomainName, hostAliases)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(fileName, hostsFileContent, 0644)
|
return os.WriteFile(fileName, hostsFileContent, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nodeHostsFileContent reads the content of node's hosts file.
|
// nodeHostsFileContent reads the content of node's hosts file.
|
||||||
func nodeHostsFileContent(hostsFilePath string, hostAliases []v1.HostAlias) ([]byte, error) {
|
func nodeHostsFileContent(hostsFilePath string, hostAliases []v1.HostAlias) ([]byte, error) {
|
||||||
hostsFileContent, err := ioutil.ReadFile(hostsFilePath)
|
hostsFileContent, err := os.ReadFile(hostsFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package kubelet
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -182,11 +181,11 @@ fe00::2 ip6-allrouters
|
|||||||
// writeHostsFile will write a hosts file into a temporary dir, and return that dir.
|
// writeHostsFile will write a hosts file into a temporary dir, and return that dir.
|
||||||
// Caller is responsible for deleting the dir and its contents.
|
// Caller is responsible for deleting the dir and its contents.
|
||||||
func writeHostsFile(filename string, cfg string) (string, error) {
|
func writeHostsFile(filename string, cfg string) (string, error) {
|
||||||
tmpdir, err := ioutil.TempDir("", "kubelet=kubelet_pods_test.go=")
|
tmpdir, err := os.MkdirTemp("", "kubelet=kubelet_pods_test.go=")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return tmpdir, ioutil.WriteFile(filepath.Join(tmpdir, filename), []byte(cfg), 0644)
|
return tmpdir, os.WriteFile(filepath.Join(tmpdir, filename), []byte(cfg), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManagedHostsFileContent(t *testing.T) {
|
func TestManagedHostsFileContent(t *testing.T) {
|
||||||
|
@ -19,7 +19,6 @@ package kubelet
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -184,7 +183,7 @@ func newTestKubeletWithImageList(
|
|||||||
kubelet.nodeName = types.NodeName(testKubeletHostname)
|
kubelet.nodeName = types.NodeName(testKubeletHostname)
|
||||||
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime)
|
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime)
|
||||||
kubelet.runtimeState.setNetworkState(nil)
|
kubelet.runtimeState.setNetworkState(nil)
|
||||||
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)
|
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||||
} else {
|
} else {
|
||||||
kubelet.rootDirectory = tempDir
|
kubelet.rootDirectory = tempDir
|
||||||
|
@ -21,7 +21,6 @@ package kubelet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -146,7 +145,7 @@ func TestCleanupOrphanedPodDirs(t *testing.T) {
|
|||||||
if err := os.MkdirAll(volumePath, 0750); err != nil {
|
if err := os.MkdirAll(volumePath, 0750); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(filepath.Join(volumePath, "test.txt"), []byte("test1"), 0640)
|
return os.WriteFile(filepath.Join(volumePath, "test.txt"), []byte("test1"), 0640)
|
||||||
},
|
},
|
||||||
validateFunc: func(kubelet *Kubelet) error {
|
validateFunc: func(kubelet *Kubelet) error {
|
||||||
podDir := kubelet.getPodDir("pod1uid")
|
podDir := kubelet.getPodDir("pod1uid")
|
||||||
@ -160,7 +159,7 @@ func TestCleanupOrphanedPodDirs(t *testing.T) {
|
|||||||
if err := os.MkdirAll(subPath, 0750); err != nil {
|
if err := os.MkdirAll(subPath, 0750); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(filepath.Join(subPath, "test.txt"), []byte("test1"), 0640)
|
return os.WriteFile(filepath.Join(subPath, "test.txt"), []byte("test1"), 0640)
|
||||||
},
|
},
|
||||||
validateFunc: func(kubelet *Kubelet) error {
|
validateFunc: func(kubelet *Kubelet) error {
|
||||||
podDir := kubelet.getPodDir("pod1uid")
|
podDir := kubelet.getPodDir("pod1uid")
|
||||||
|
@ -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.
|
// an absolute path to os.Open, and we ensure similar behavior in utilfs.FakeFS for testing.
|
||||||
tmpPath = tmpFile.Name()
|
tmpPath = tmpFile.Name()
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ func (m *kubeGenericRuntimeManager) makeMounts(opts *kubecontainer.RunContainerO
|
|||||||
} else {
|
} else {
|
||||||
fs.Close()
|
fs.Close()
|
||||||
|
|
||||||
// Chmod is needed because ioutil.WriteFile() ends up calling
|
// Chmod is needed because os.WriteFile() ends up calling
|
||||||
// open(2) to create the file, so the final mode used is "mode &
|
// open(2) to create the file, so the final mode used is "mode &
|
||||||
// ~umask". But we want to make sure the specified mode is used
|
// ~umask". But we want to make sure the specified mode is used
|
||||||
// in the file no matter what the umask is.
|
// in the file no matter what the umask is.
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package kuberuntime
|
package kuberuntime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -440,11 +439,11 @@ func TestRestartCountByLogDir(t *testing.T) {
|
|||||||
restartCount: 8,
|
restartCount: 8,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
tempDirPath, err := ioutil.TempDir("", "test-restart-count-")
|
tempDirPath, err := os.MkdirTemp("", "test-restart-count-")
|
||||||
assert.NoError(t, err, "create tempdir error")
|
assert.NoError(t, err, "create tempdir error")
|
||||||
defer os.RemoveAll(tempDirPath)
|
defer os.RemoveAll(tempDirPath)
|
||||||
for _, filename := range tc.filenames {
|
for _, filename := range tc.filenames {
|
||||||
err = ioutil.WriteFile(filepath.Join(tempDirPath, filename), []byte("a log line"), 0600)
|
err = os.WriteFile(filepath.Join(tempDirPath, filename), []byte("a log line"), 0600)
|
||||||
assert.NoError(t, err, "could not write log file")
|
assert.NoError(t, err, "could not write log file")
|
||||||
}
|
}
|
||||||
count, _ := calcRestartCountByLogDir(tempDirPath)
|
count, _ := calcRestartCountByLogDir(tempDirPath)
|
||||||
|
@ -438,14 +438,14 @@ func TestPodLogDirectoryGC(t *testing.T) {
|
|||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
fakeOS.ReadDirFn = func(string) ([]os.FileInfo, error) {
|
fakeOS.ReadDirFn = func(string) ([]os.DirEntry, error) {
|
||||||
var fileInfos []os.FileInfo
|
var dirEntries []os.DirEntry
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
mockFI := containertest.NewMockFileInfo(ctrl)
|
mockDE := containertest.NewMockDirEntry(ctrl)
|
||||||
mockFI.EXPECT().Name().Return(file)
|
mockDE.EXPECT().Name().Return(file)
|
||||||
fileInfos = append(fileInfos, mockFI)
|
dirEntries = append(dirEntries, mockDE)
|
||||||
}
|
}
|
||||||
return fileInfos, nil
|
return dirEntries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// allSourcesReady == true, pod log directories without corresponding pod should be removed.
|
// allSourcesReady == true, pod log directories without corresponding pod should be removed.
|
||||||
|
@ -19,16 +19,16 @@ package logs
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
apitesting "k8s.io/cri-api/pkg/apis/testing"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
apitesting "k8s.io/cri-api/pkg/apis/testing"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
)
|
)
|
||||||
@ -72,7 +72,7 @@ func TestLogOptions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReadLogs(t *testing.T) {
|
func TestReadLogs(t *testing.T) {
|
||||||
file, err := ioutil.TempFile("", "TestFollowLogs")
|
file, err := os.CreateTemp("", "TestFollowLogs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create temp file")
|
t.Fatalf("unable to create temp file")
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package lifecycle
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -225,7 +225,7 @@ func TestRunHandlerExecFailure(t *testing.T) {
|
|||||||
func TestRunHandlerHttpFailure(t *testing.T) {
|
func TestRunHandlerHttpFailure(t *testing.T) {
|
||||||
expectedErr := fmt.Errorf("fake http error")
|
expectedErr := fmt.Errorf("fake http error")
|
||||||
expectedResp := http.Response{
|
expectedResp := http.Response{
|
||||||
Body: ioutil.NopCloser(strings.NewReader(expectedErr.Error())),
|
Body: io.NopCloser(strings.NewReader(expectedErr.Error())),
|
||||||
}
|
}
|
||||||
fakeHTTPGetter := fakeHTTP{err: expectedErr, resp: &expectedResp}
|
fakeHTTPGetter := fakeHTTP{err: expectedErr, resp: &expectedResp}
|
||||||
handlerRunner := NewHandlerRunner(&fakeHTTPGetter, &fakeContainerCommandRunner{}, nil)
|
handlerRunner := NewHandlerRunner(&fakeHTTPGetter, &fakeContainerCommandRunner{}, nil)
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -36,7 +35,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetAllLogs(t *testing.T) {
|
func TestGetAllLogs(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-get-all-logs")
|
dir, err := os.MkdirTemp("", "test-get-all-logs")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
testLogs := []string{
|
testLogs := []string{
|
||||||
@ -75,7 +74,7 @@ func TestGetAllLogs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRotateLogs(t *testing.T) {
|
func TestRotateLogs(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-rotate-logs")
|
dir, err := os.MkdirTemp("", "test-rotate-logs")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
@ -162,7 +161,7 @@ func TestRotateLogs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClean(t *testing.T) {
|
func TestClean(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-clean")
|
dir, err := os.MkdirTemp("", "test-clean")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
@ -233,7 +232,7 @@ func TestClean(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanupUnusedLog(t *testing.T) {
|
func TestCleanupUnusedLog(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-cleanup-unused-log")
|
dir, err := os.MkdirTemp("", "test-cleanup-unused-log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
@ -285,7 +284,7 @@ func TestRemoveExcessLog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
dir, err := ioutil.TempDir("", "test-remove-excess-log")
|
dir, err := os.MkdirTemp("", "test-remove-excess-log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
@ -319,11 +318,11 @@ func TestRemoveExcessLog(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCompressLog(t *testing.T) {
|
func TestCompressLog(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-compress-log")
|
dir, err := os.MkdirTemp("", "test-compress-log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
testFile, err := ioutil.TempFile(dir, "test-rotate-latest-log")
|
testFile, err := os.CreateTemp(dir, "test-rotate-latest-log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer testFile.Close()
|
defer testFile.Close()
|
||||||
testContent := "test log content"
|
testContent := "test log content"
|
||||||
@ -350,7 +349,7 @@ func TestCompressLog(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRotateLatestLog(t *testing.T) {
|
func TestRotateLatestLog(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test-rotate-latest-log")
|
dir, err := os.MkdirTemp("", "test-rotate-latest-log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
@ -387,7 +386,7 @@ func TestRotateLatestLog(t *testing.T) {
|
|||||||
if test.runtimeError != nil {
|
if test.runtimeError != nil {
|
||||||
f.InjectError("ReopenContainerLog", test.runtimeError)
|
f.InjectError("ReopenContainerLog", test.runtimeError)
|
||||||
}
|
}
|
||||||
testFile, err := ioutil.TempFile(dir, "test-rotate-latest-log")
|
testFile, err := os.CreateTemp(dir, "test-rotate-latest-log")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer testFile.Close()
|
defer testFile.Close()
|
||||||
testLog := testFile.Name()
|
testLog := testFile.Name()
|
||||||
|
@ -19,13 +19,12 @@ package dns
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
|
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
@ -455,7 +454,7 @@ func (c *Configurer) SetupDNSinContainerizedMounter(mounterPath string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(resolvePath, []byte(dnsString), 0600); err != nil {
|
if err := os.WriteFile(resolvePath, []byte(dnsString), 0600); err != nil {
|
||||||
klog.ErrorS(err, "Could not write dns nameserver in the file", "path", resolvePath)
|
klog.ErrorS(err, "Could not write dns nameserver in the file", "path", resolvePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package dns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -596,7 +595,7 @@ func TestGetPodDNSCustom(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolvConfContent := []byte(fmt.Sprintf("nameserver %s\nsearch %s\n", testHostNameserver, testHostDomain))
|
resolvConfContent := []byte(fmt.Sprintf("nameserver %s\nsearch %s\n", testHostNameserver, testHostDomain))
|
||||||
tmpfile, err := ioutil.TempFile("", "tmpResolvConf")
|
tmpfile, err := os.CreateTemp("", "tmpResolvConf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package nodeshutdown
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -67,7 +66,7 @@ type state struct {
|
|||||||
|
|
||||||
// atomicWrite atomically writes data to a file specified by filename.
|
// atomicWrite atomically writes data to a file specified by filename.
|
||||||
func atomicWrite(filename string, data []byte, perm os.FileMode) error {
|
func atomicWrite(filename string, data []byte, perm os.FileMode) error {
|
||||||
f, err := ioutil.TempFile(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
|
f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ package systemd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -193,7 +192,7 @@ InhibitDelayMaxSec=%.0f
|
|||||||
`, inhibitDelayMax.Seconds())
|
`, inhibitDelayMax.Seconds())
|
||||||
|
|
||||||
logindOverridePath := filepath.Join(logindConfigDirectory, kubeletLogindConf)
|
logindOverridePath := filepath.Join(logindConfigDirectory, kubeletLogindConf)
|
||||||
if err := ioutil.WriteFile(logindOverridePath, []byte(inhibitOverride), 0644); err != nil {
|
if err := os.WriteFile(logindOverridePath, []byte(inhibitOverride), 0644); err != nil {
|
||||||
return fmt.Errorf("failed writing logind shutdown inhibit override file %v: %w", logindOverridePath, err)
|
return fmt.Errorf("failed writing logind shutdown inhibit override file %v: %w", logindOverridePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ package operationexecutor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -35,7 +35,7 @@ var _ OperationGenerator = &fakeOperationGenerator{}
|
|||||||
var socketDir string
|
var socketDir string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
d, err := ioutil.TempDir("", "operation_executor_test")
|
d, err := os.MkdirTemp("", "operation_executor_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package pluginmanager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -81,7 +80,7 @@ func (f *fakePluginHandler) Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
d, err := ioutil.TempDir("", "plugin_manager_test")
|
d, err := os.MkdirTemp("", "plugin_manager_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package pluginwatcher
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@ -46,7 +45,7 @@ func init() {
|
|||||||
flag.StringVar(&logLevel, "logLevel", "6", "test")
|
flag.StringVar(&logLevel, "logLevel", "6", "test")
|
||||||
flag.Lookup("v").Value.Set(logLevel)
|
flag.Lookup("v").Value.Set(logLevel)
|
||||||
|
|
||||||
d, err := ioutil.TempDir("", "plugin_test")
|
d, err := os.MkdirTemp("", "plugin_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package reconciler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -44,7 +43,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
d, err := ioutil.TempDir("", "reconciler_test")
|
d, err := os.MkdirTemp("", "reconciler_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@ -432,7 +431,7 @@ func TestServeRunInContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// copying the response body did not work
|
// copying the response body did not work
|
||||||
t.Errorf("Cannot copy resp: %#v", err)
|
t.Errorf("Cannot copy resp: %#v", err)
|
||||||
@ -475,7 +474,7 @@ func TestServeRunInContainerWithUID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// copying the response body did not work
|
// copying the response body did not work
|
||||||
t.Errorf("Cannot copy resp: %#v", err)
|
t.Errorf("Cannot copy resp: %#v", err)
|
||||||
@ -745,7 +744,7 @@ func assertHealthIsOk(t *testing.T, httpURL string) {
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Errorf("expected status code %d, got %d", http.StatusOK, resp.StatusCode)
|
t.Errorf("expected status code %d, got %d", http.StatusOK, resp.StatusCode)
|
||||||
}
|
}
|
||||||
body, readErr := ioutil.ReadAll(resp.Body)
|
body, readErr := io.ReadAll(resp.Body)
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
// copying the response body did not work
|
// copying the response body did not work
|
||||||
t.Fatalf("Cannot copy resp: %#v", readErr)
|
t.Fatalf("Cannot copy resp: %#v", readErr)
|
||||||
@ -821,7 +820,7 @@ func TestContainerLogs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error reading container logs: %v", err)
|
t.Errorf("Error reading container logs: %v", err)
|
||||||
}
|
}
|
||||||
@ -911,7 +910,7 @@ func TestCheckpointContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
assert.Equal(t, resp.StatusCode, 500)
|
assert.Equal(t, resp.StatusCode, 500)
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
assert.Equal(t, string(body), "checkpointing of other/foo/checkpointingFailure failed (Returning error for test)")
|
assert.Equal(t, string(body), "checkpointing of other/foo/checkpointingFailure failed (Returning error for test)")
|
||||||
})
|
})
|
||||||
// Now test a successful checkpoint succeeds
|
// Now test a successful checkpoint succeeds
|
||||||
@ -1111,7 +1110,7 @@ func testExecAttach(t *testing.T, verb string) {
|
|||||||
require.NoError(t, err, "POSTing")
|
require.NoError(t, err, "POSTing")
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
_, err = ioutil.ReadAll(resp.Body)
|
_, err = io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err, "reading response body")
|
assert.NoError(t, err, "reading response body")
|
||||||
|
|
||||||
require.Equal(t, test.responseStatusCode, resp.StatusCode, "response status")
|
require.Equal(t, test.responseStatusCode, resp.StatusCode, "response status")
|
||||||
@ -1453,7 +1452,7 @@ func TestFailedParseParamsSummaryHandler(t *testing.T) {
|
|||||||
resp, err := http.Post(fw.testHTTPServer.URL+"/stats/summary", "invalid/content/type", nil)
|
resp, err := http.Post(fw.testHTTPServer.URL+"/stats/summary", "invalid/content/type", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
v, err := ioutil.ReadAll(resp.Body)
|
v, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
||||||
assert.Contains(t, string(v), "parse form failed")
|
assert.Contains(t, string(v), "parse form failed")
|
||||||
@ -1463,14 +1462,14 @@ func verifyEndpointResponse(t *testing.T, fw *serverTestFramework, path string,
|
|||||||
resp, err := http.Get(fw.testHTTPServer.URL + path)
|
resp, err := http.Get(fw.testHTTPServer.URL + path)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, http.StatusMethodNotAllowed, resp.StatusCode)
|
assert.Equal(t, http.StatusMethodNotAllowed, resp.StatusCode)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, expectedResponse, string(body))
|
assert.Equal(t, expectedResponse, string(body))
|
||||||
|
|
||||||
resp, err = http.Post(fw.testHTTPServer.URL+path, "", nil)
|
resp, err = http.Post(fw.testHTTPServer.URL+path, "", nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, http.StatusMethodNotAllowed, resp.StatusCode)
|
assert.Equal(t, http.StatusMethodNotAllowed, resp.StatusCode)
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, expectedResponse, string(body))
|
assert.Equal(t, expectedResponse, string(body))
|
||||||
}
|
}
|
||||||
|
@ -211,20 +211,20 @@ func TestCRIListPodStats(t *testing.T) {
|
|||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
fakeOS := &kubecontainertest.FakeOS{}
|
fakeOS := &kubecontainertest.FakeOS{}
|
||||||
fakeOS.ReadDirFn = func(path string) ([]os.FileInfo, error) {
|
fakeOS.ReadDirFn = func(path string) ([]os.DirEntry, error) {
|
||||||
var fileInfos []os.FileInfo
|
var dirEntries []os.DirEntry
|
||||||
mockFI := kubecontainertest.NewMockFileInfo(ctrl)
|
mockDE := kubecontainertest.NewMockDirEntry(ctrl)
|
||||||
switch path {
|
switch path {
|
||||||
case kuberuntime.BuildPodLogsDirectory("sandbox0-ns", "sandbox0-name", types.UID("sandbox0-uid")):
|
case kuberuntime.BuildPodLogsDirectory("sandbox0-ns", "sandbox0-name", types.UID("sandbox0-uid")):
|
||||||
mockFI.EXPECT().Name().Return(podLogName0)
|
mockDE.EXPECT().Name().Return(podLogName0)
|
||||||
case kuberuntime.BuildPodLogsDirectory("sandbox1-ns", "sandbox1-name", types.UID("sandbox1-uid")):
|
case kuberuntime.BuildPodLogsDirectory("sandbox1-ns", "sandbox1-name", types.UID("sandbox1-uid")):
|
||||||
mockFI.EXPECT().Name().Return(podLogName1)
|
mockDE.EXPECT().Name().Return(podLogName1)
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
mockFI.EXPECT().IsDir().Return(false)
|
mockDE.EXPECT().IsDir().Return(false)
|
||||||
fileInfos = append(fileInfos, mockFI)
|
dirEntries = append(dirEntries, mockDE)
|
||||||
return fileInfos, nil
|
return dirEntries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := NewCRIStatsProvider(
|
provider := NewCRIStatsProvider(
|
||||||
|
@ -21,7 +21,7 @@ package pidlimit
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -39,7 +39,7 @@ func Stats() (*statsapi.RlimitStats, error) {
|
|||||||
// Calculate the mininum of kernel.pid_max and kernel.threads-max as they both specify the
|
// Calculate the mininum of kernel.pid_max and kernel.threads-max as they both specify the
|
||||||
// system-wide limit on the number of tasks.
|
// system-wide limit on the number of tasks.
|
||||||
for _, file := range []string{"/proc/sys/kernel/pid_max", "/proc/sys/kernel/threads-max"} {
|
for _, file := range []string{"/proc/sys/kernel/pid_max", "/proc/sys/kernel/threads-max"} {
|
||||||
if content, err := ioutil.ReadFile(file); err == nil {
|
if content, err := os.ReadFile(file); err == nil {
|
||||||
if limit, err := strconv.ParseInt(string(content[:len(content)-1]), 10, 64); err == nil {
|
if limit, err := strconv.ParseInt(string(content[:len(content)-1]), 10, 64); err == nil {
|
||||||
if taskMax == -1 || taskMax > limit {
|
if taskMax == -1 || taskMax > limit {
|
||||||
taskMax = limit
|
taskMax = limit
|
||||||
@ -71,7 +71,7 @@ func Stats() (*statsapi.RlimitStats, error) {
|
|||||||
|
|
||||||
func runningTaskCount() (int64, error) {
|
func runningTaskCount() (int64, error) {
|
||||||
// Example: 1.36 3.49 4.53 2/3518 3715089
|
// Example: 1.36 3.49 4.53 2/3518 3715089
|
||||||
bytes, err := ioutil.ReadFile("/proc/loadavg")
|
bytes, err := os.ReadFile("/proc/loadavg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ package util
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -58,7 +57,7 @@ func CreateListener(endpoint string) (net.Listener, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the socket on a tempfile and move it to the destination socket to handle improper cleanup
|
// Create the socket on a tempfile and move it to the destination socket to handle improper cleanup
|
||||||
file, err := ioutil.TempFile(filepath.Dir(addr), "")
|
file, err := os.CreateTemp(filepath.Dir(addr), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create temporary file: %v", err)
|
return nil, fmt.Errorf("failed to create temporary file: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -102,7 +101,7 @@ func TestIsUnixDomainSocket(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
f, err := ioutil.TempFile("", "test-domain-socket")
|
f, err := os.CreateTemp("", "test-domain-socket")
|
||||||
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, test.label)
|
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, test.label)
|
||||||
addr := f.Name()
|
addr := f.Name()
|
||||||
f.Close()
|
f.Close()
|
||||||
|
@ -21,7 +21,6 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -204,7 +203,7 @@ func testPipe(t *testing.T, label string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testRegularFile(t *testing.T, label string, exists bool) {
|
func testRegularFile(t *testing.T, label string, exists bool) {
|
||||||
f, err := ioutil.TempFile("", "test-file")
|
f, err := os.CreateTemp("", "test-file")
|
||||||
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, label)
|
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, label)
|
||||||
testFile := f.Name()
|
testFile := f.Name()
|
||||||
if !exists {
|
if !exists {
|
||||||
@ -218,7 +217,7 @@ func testRegularFile(t *testing.T, label string, exists bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testUnixDomainSocket(t *testing.T, label string) {
|
func testUnixDomainSocket(t *testing.T, label string) {
|
||||||
f, err := ioutil.TempFile("", "test-domain-socket")
|
f, err := os.CreateTemp("", "test-domain-socket")
|
||||||
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, label)
|
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, label)
|
||||||
testFile := f.Name()
|
testFile := f.Name()
|
||||||
f.Close()
|
f.Close()
|
||||||
@ -241,7 +240,7 @@ func testPendingUnixDomainSocket(t *testing.T, label string) {
|
|||||||
// not-yet-ready state. We need this because the Kubelet keeps an eye on file
|
// not-yet-ready state. We need this because the Kubelet keeps an eye on file
|
||||||
// changes and acts on them, leading to potential race issues as described in
|
// changes and acts on them, leading to potential race issues as described in
|
||||||
// the referenced issue above
|
// the referenced issue above
|
||||||
f, err := ioutil.TempFile("", "test-domain-socket")
|
f, err := os.CreateTemp("", "test-domain-socket")
|
||||||
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, label)
|
require.NoErrorf(t, err, "Failed to create file for test purposes: %v while setting up: %s", err, label)
|
||||||
testFile := f.Name()
|
testFile := f.Name()
|
||||||
f.Close()
|
f.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user