Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #1012

Merged
merged 2 commits into from Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cri-resmgr-webhook/handlers.go
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"

Expand Down Expand Up @@ -75,7 +75,7 @@ func stringify(r interface{}) string {
func handle(w http.ResponseWriter, r *http.Request) {
var body []byte
if r.Body != nil {
if data, err := ioutil.ReadAll(r.Body); err == nil {
if data, err := io.ReadAll(r.Body); err == nil {
body = data
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/avx/collector.go
Expand Up @@ -22,7 +22,7 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
Expand Down Expand Up @@ -110,7 +110,7 @@ type collector struct {

func enablePerfTracepoint(prog *bpf.Program, tracepoint string) (int, error) {

id, err := ioutil.ReadFile(filepath.Join(kernelTracepointPath, tracepoint, "id"))
id, err := os.ReadFile(filepath.Join(kernelTracepointPath, tracepoint, "id"))
if err != nil {
return -1, errors.Wrap(err, "unable to read tracepoint ID")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/avx/elfdump.go
Expand Up @@ -22,7 +22,6 @@ package main
import (
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"strings"
"text/template"
Expand All @@ -37,7 +36,7 @@ type Program struct {
}

func main() {
f, err := ioutil.ReadFile("../../libexec/avx512.o")
f, err := os.ReadFile("../../libexec/avx512.o")
if err != nil {
fmt.Println("Note: AVX512 eBPF ELF not available.")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/blockio/blockio.go
Expand Up @@ -18,7 +18,6 @@ package blockio

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -153,7 +152,7 @@ func getCurrentIOSchedulers() (map[string]string, error) {
}
for _, schedulerFile := range schedulerFiles {
devName := strings.SplitN(schedulerFile, "/", 5)[3]
schedulerDataB, err := ioutil.ReadFile(schedulerFile)
schedulerDataB, err := os.ReadFile(schedulerFile)
if err != nil {
// A block device may be disconnected. Continue without error.
log.Error("failed to read current IO scheduler %#v: %v\n", schedulerFile, err)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cgroups/cgroupblkio.go
Expand Up @@ -16,7 +16,6 @@ package cgroups

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -342,7 +341,7 @@ var currentPlatform platformInterface = defaultPlatform{}

// readFromFile returns file contents as a string.
func (dpm defaultPlatform) readFromFile(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
return string(content), err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cgroups/cgroupstats.go
Expand Up @@ -16,7 +16,7 @@ package cgroups

import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -89,7 +89,7 @@ type GlobalNumaStats struct {

func readCgroupFileLines(filePath string) ([]string, error) {

f, err := ioutil.ReadFile(filePath)
f, err := os.ReadFile(filePath)

if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/data.go
Expand Up @@ -16,7 +16,7 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"sigs.k8s.io/yaml"
"strings"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ func DataFromStringMap(smap map[string]string) (Data, error) {

// DataFromFile unmarshals the content of the given file into configuration data.
func DataFromFile(path string) (Data, error) {
raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
return nil, configError("failed to read file %q: %v", path, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cpuallocator/cpuallocator_test.go
Expand Up @@ -15,7 +15,6 @@
package cpuallocator

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -28,7 +27,7 @@ import (

func TestAllocatorHelper(t *testing.T) {
// Create tmpdir and decompress testdata there
tmpdir, err := ioutil.TempDir("", "cri-resource-manager-test-")
tmpdir, err := os.MkdirTemp("", "cri-resource-manager-test-")
if err != nil {
t.Fatalf("failed to create tmpdir: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cri/resource-manager/cache/cache.go
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -1532,7 +1531,7 @@ func (cch *cache) Save() error {
}

tmpPath := cch.filePath + ".saving"
if err = ioutil.WriteFile(tmpPath, data, cacheFilePerm.prefer); err != nil {
if err = os.WriteFile(tmpPath, data, cacheFilePerm.prefer); err != nil {
return cacheError("failed to write cache to file %q: %v", tmpPath, err)
}
if err := os.Rename(tmpPath, cch.filePath); err != nil {
Expand All @@ -1547,7 +1546,7 @@ func (cch *cache) Save() error {
func (cch *cache) Load() error {
cch.Debug("loading cache from file '%s'...", cch.filePath)

data, err := ioutil.ReadFile(cch.filePath)
data, err := os.ReadFile(cch.filePath)

switch {
case os.IsNotExist(err):
Expand Down
3 changes: 1 addition & 2 deletions pkg/cri/resource-manager/cache/cache_test.go
Expand Up @@ -16,7 +16,6 @@ package cache

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -52,7 +51,7 @@ type fakeContainer struct {
}

func createTmpCache() (Cache, string, error) {
dir, err := ioutil.TempDir("", "cache-test")
dir, err := os.MkdirTemp("", "cache-test")
if err != nil {
return nil, "", err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cri/resource-manager/cache/utils.go
Expand Up @@ -15,7 +15,6 @@
package cache

import (
"io/ioutil"
"os"
"path"
"strconv"
Expand Down Expand Up @@ -139,7 +138,7 @@ func getMemoryCapacity() int64 {
return memoryCapacity
}

if data, err = ioutil.ReadFile("/proc/meminfo"); err != nil {
if data, err = os.ReadFile("/proc/meminfo"); err != nil {
return -1
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/cri/resource-manager/control/page-migrate/demoter.go
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"strconv"
Expand Down Expand Up @@ -243,7 +242,7 @@ func (d *demoter) startDirtyBitResetTimer() {
func resetDirtyBit(pid string) error {
// Write magic value "4" to the clear_refs file. This resets the dirty bit.
path := "/proc/" + pid + "/clear_refs"
err := ioutil.WriteFile(path, []byte("4"), 0600)
err := os.WriteFile(path, []byte("4"), 0600)
return err
}

Expand Down Expand Up @@ -328,13 +327,13 @@ func (d *demoter) getPagesForContainer(c *container, sourceNodes idset.IDSet) (p
pidNumber := int(pidNumber64)
// Read /proc/pid/numa_maps and /proc/pid/maps
numaMapsPath := "/proc/" + pid + "/numa_maps"
numaMapsBytes, err := ioutil.ReadFile(numaMapsPath)
numaMapsBytes, err := os.ReadFile(numaMapsPath)
if err != nil {
log.Error("Could not read numa_maps: %v", err)
continue
}
mapsPath := "/proc/" + pid + "/maps"
mapsBytes, err := ioutil.ReadFile(mapsPath)
mapsBytes, err := os.ReadFile(mapsPath)
if err != nil {
log.Error("Could not read maps: %v\n", err)
os.Exit(1)
Expand Down
12 changes: 6 additions & 6 deletions pkg/cri/resource-manager/policy/builtin/static-pools/config.go
Expand Up @@ -18,7 +18,7 @@ package stp

import (
"fmt"
"io/ioutil"
"os"
"path"
"regexp"
"strconv"
Expand Down Expand Up @@ -124,7 +124,7 @@ func parseConfData(raw []byte) (pools, error) {

func readConfFile(filepath string) (pools, error) {
// Read config data
data, err := ioutil.ReadFile(filepath)
data, err := os.ReadFile(filepath)
if err != nil {
return nil, stpError("Failed to read config file: %v", err)
}
Expand All @@ -137,7 +137,7 @@ func readConfDir(confDir string) (pools, error) {

// List pools in the pools configuration directory
poolsDir := path.Join(confDir, "pools")
pools, err := ioutil.ReadDir(poolsDir)
pools, err := os.ReadDir(poolsDir)
if err != nil {
return nil, stpError("Failed to list pools config directory %s: %v", poolsDir, err)
}
Expand All @@ -159,7 +159,7 @@ func readPoolConfDir(poolDir string) (poolConfig, error) {
conf := poolConfig{Exclusive: false, CPULists: []*cpuList{}}

// Read pool's exclusivity flag
exclusive, err := ioutil.ReadFile(path.Join(poolDir, "exclusive"))
exclusive, err := os.ReadFile(path.Join(poolDir, "exclusive"))
if err != nil {
return conf, fmt.Errorf("Failed to read pool exclusive setting in %s: %v", poolDir, err)
}
Expand All @@ -168,7 +168,7 @@ func readPoolConfDir(poolDir string) (poolConfig, error) {
}

// Read socket configurations (per-socket cpu lists)
files, err := ioutil.ReadDir(poolDir)
files, err := os.ReadDir(poolDir)
if err != nil {
return conf, fmt.Errorf("Failed to list pool config directory %s: %v", poolDir, err)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func readSocketConfDir(socketDir string) ([]*cpuList, error) {
}

// Socket directory contains a set of subdirectories, one per cpu list
cpuListDirs, err := ioutil.ReadDir(socketDir)
cpuListDirs, err := os.ReadDir(socketDir)
if err != nil {
return nil, fmt.Errorf("Failed to list socket directory %s: %v", socketDir, err)
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ package stp
import (
"flag"
"fmt"
"io/ioutil"
"io"
"math/rand"
"strconv"
"strings"
Expand Down Expand Up @@ -422,7 +422,7 @@ func parseCmkCmdline(args []string) *cmkLegacyArgs {

// Create parser
cmkCmd := flag.NewFlagSet("cmk-legacy", flag.ContinueOnError)
cmkCmd.SetOutput(ioutil.Discard)
cmkCmd.SetOutput(io.Discard)
cmkCmd.StringVar(&parsedArgs.Pool, "pool", "", "pool to use")
cmkCmd.Int64Var(&parsedArgs.SocketID, "socket-id", -1, "socket id to use")
cmkCmd.BoolVar(&parsedArgs.NoAffinity, "no-affinity", false, "Do not set cpu affinity before forking the child command")
Expand Down
Expand Up @@ -16,7 +16,6 @@ package topologyaware

import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -286,7 +285,7 @@ func TestPoolCreation(t *testing.T) {
// Test pool creation with "real" sysfs data.

// Create a temporary directory for the test data.
dir, err := ioutil.TempDir("", "cri-resource-manager-test-sysfs-")
dir, err := os.MkdirTemp("", "cri-resource-manager-test-sysfs-")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -437,7 +436,7 @@ func TestWorkloadPlacement(t *testing.T) {
// server system.

// Create a temporary directory for the test data.
dir, err := ioutil.TempDir("", "cri-resource-manager-test-sysfs-")
dir, err := os.MkdirTemp("", "cri-resource-manager-test-sysfs-")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -554,7 +553,7 @@ func TestContainerMove(t *testing.T) {
// to be moved upwards in the tree.

// Create a temporary directory for the test data.
dir, err := ioutil.TempDir("", "cri-resource-manager-test-sysfs-")
dir, err := os.MkdirTemp("", "cri-resource-manager-test-sysfs-")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -720,7 +719,7 @@ func TestAffinities(t *testing.T) {
//

// Create a temporary directory for the test data.
dir, err := ioutil.TempDir("", "cri-resource-manager-test-sysfs-")
dir, err := os.MkdirTemp("", "cri-resource-manager-test-sysfs-")
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cri/resource-manager/policy/flags.go
Expand Up @@ -17,7 +17,6 @@ package policy
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -187,7 +186,7 @@ func (cs *ConstraintSet) parseCPUFromCgroup(dir string) error {
// dir is none of the previous
return policyError("failed to find cpuset.cpus for CPU cgroup constraint %q", dir)
}
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
return policyError("failed read CPU cpuset cgroup constraint %q: %v",
path, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/instrumentation/http/http_test.go
Expand Up @@ -16,7 +16,7 @@ package http

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
)
Expand Down Expand Up @@ -66,7 +66,7 @@ func checkURL(t *testing.T, srv *Server, path, response string, status int) {
t.Errorf("http.Get(%s) status %d, expected %d", url, res.StatusCode, status)
}

txt, err := ioutil.ReadAll(res.Body)
txt, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("http.Get(%s) failed to read response: %v", url, err)
}
Expand Down