Skip to content

Commit 33a941b

Browse files
committedMar 29, 2024
fix: remove deprecated
1 parent c01c86e commit 33a941b

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed
 

‎pkg/cgroups/v1.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cgroups
22

33
import (
44
"bufio"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"runtime"
@@ -37,12 +36,12 @@ func newCGroupsv1(path string) (cgroupsv1, error) {
3736
func (cg cgroupsv1) SetMemSwpLimit(memory, swap int) error {
3837
if memory > 0 {
3938
memFile := filepath.Join(cg.dirs["memory"], "memory.limit_in_bytes")
40-
if err := ioutil.WriteFile(memFile, []byte(strconv.Itoa(memory*1024*1024)), 0644); err != nil {
39+
if err := os.WriteFile(memFile, []byte(strconv.Itoa(memory*1024*1024)), 0644); err != nil {
4140
return err
4241
}
4342
if swap > 0 {
4443
memswFile := filepath.Join(cg.dirs["memory"], "memory.memsw.limit_in_bytes")
45-
if err := ioutil.WriteFile(memswFile, []byte(strconv.Itoa((memory+swap)*1024*1024)), 0644); err != nil {
44+
if err := os.WriteFile(memswFile, []byte(strconv.Itoa((memory+swap)*1024*1024)), 0644); err != nil {
4645
return err
4746
}
4847
}
@@ -55,7 +54,7 @@ func (cg cgroupsv1) SetMemSwpLimit(memory, swap int) error {
5554
func (cg cgroupsv1) SetPidsLimit(pids int) error {
5655
if pids > 0 {
5756
pidsFile := filepath.Join(cg.dirs["pids"], "pids.max")
58-
if err := ioutil.WriteFile(pidsFile, []byte(strconv.Itoa(pids)), 0644); err != nil {
57+
if err := os.WriteFile(pidsFile, []byte(strconv.Itoa(pids)), 0644); err != nil {
5958
return err
6059
}
6160
}
@@ -66,13 +65,13 @@ func (cg cgroupsv1) SetPidsLimit(pids int) error {
6665
func (cg cgroupsv1) SetCPULimit(cpus float64) error {
6766
if int(cpus) > 0 && int(cpus) < runtime.NumCPU() {
6867
cpuPeriodFile := filepath.Join(cg.dirs["cpu"], "cpu.cfs_period_us")
69-
if err := ioutil.WriteFile(cpuPeriodFile, []byte(strconv.Itoa(constants.DefaultCfsPeriod)),
68+
if err := os.WriteFile(cpuPeriodFile, []byte(strconv.Itoa(constants.DefaultCfsPeriod)),
7069
0644); err != nil {
7170
return err
7271
}
7372

7473
cpuQuotaFile := filepath.Join(cg.dirs["cpu"], "cpu.cfs_quota_us")
75-
if err := ioutil.WriteFile(cpuQuotaFile, []byte(strconv.Itoa(int(cpus*constants.DefaultCfsPeriod))),
74+
if err := os.WriteFile(cpuQuotaFile, []byte(strconv.Itoa(int(cpus*constants.DefaultCfsPeriod))),
7675
0644); err != nil {
7776
return err
7877
}
@@ -86,7 +85,7 @@ func (cg cgroupsv1) AddProcess() error {
8685
pid := os.Getpid()
8786
for _, dir := range cg.dirs {
8887
procsFile := filepath.Join(dir, "cgroup.procs")
89-
if err := ioutil.WriteFile(procsFile, []byte(strconv.Itoa(pid)), 0700); err != nil {
88+
if err := os.WriteFile(procsFile, []byte(strconv.Itoa(pid)), 0700); err != nil {
9089
return err
9190
}
9291
}

‎pkg/cgroups/v2.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cgroups
33
import (
44
"bufio"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"runtime"
@@ -22,7 +21,7 @@ func createKokerGroup() error {
2221
}
2322

2423
// Enable controllers
25-
return ioutil.WriteFile(filepath.Join(kokerCGroup, "cgroup.subtree_control"),
24+
return os.WriteFile(filepath.Join(kokerCGroup, "cgroup.subtree_control"),
2625
[]byte("+cpu +memory +pids"), 0644)
2726
}
2827

@@ -42,12 +41,12 @@ func newCGroupsv2(path string) (cgroupsv2, error) {
4241
func (cg cgroupsv2) SetMemSwpLimit(memory, swap int) error {
4342
if memory > 0 {
4443
memFile := filepath.Join(cg.dir, "memory.max")
45-
if err := ioutil.WriteFile(memFile, []byte(strconv.Itoa(memory*1024*1024)), 0644); err != nil {
44+
if err := os.WriteFile(memFile, []byte(strconv.Itoa(memory*1024*1024)), 0644); err != nil {
4645
return err
4746
}
4847
if swap > 0 {
4948
memswFile := filepath.Join(cg.dir, "memory.swap.max")
50-
if err := ioutil.WriteFile(memswFile, []byte(strconv.Itoa((memory+swap)*1024*1024)), 0644); err != nil {
49+
if err := os.WriteFile(memswFile, []byte(strconv.Itoa((memory+swap)*1024*1024)), 0644); err != nil {
5150
return err
5251
}
5352
}
@@ -60,7 +59,7 @@ func (cg cgroupsv2) SetMemSwpLimit(memory, swap int) error {
6059
func (cg cgroupsv2) SetPidsLimit(pids int) error {
6160
if pids > 0 {
6261
pidsFile := filepath.Join(cg.dir, "pids.max")
63-
if err := ioutil.WriteFile(pidsFile, []byte(strconv.Itoa(pids)), 0644); err != nil {
62+
if err := os.WriteFile(pidsFile, []byte(strconv.Itoa(pids)), 0644); err != nil {
6463
return err
6564
}
6665
}
@@ -73,7 +72,7 @@ func (cg cgroupsv2) SetCPULimit(cpus float64) error {
7372
cpuFile := filepath.Join(cg.dir, "cpu.max")
7473
cpuVal := fmt.Sprintf("%d%d", int(cpus*constants.DefaultCfsPeriod),
7574
constants.DefaultCfsPeriod)
76-
if err := ioutil.WriteFile(cpuFile, []byte(cpuVal), 0644); err != nil {
75+
if err := os.WriteFile(cpuFile, []byte(cpuVal), 0644); err != nil {
7776
return err
7877
}
7978
}
@@ -85,7 +84,7 @@ func (cg cgroupsv2) AddProcess() error {
8584
// Get pid
8685
pid := os.Getpid()
8786
procsFile := filepath.Join(cg.dir, "cgroup.procs")
88-
return ioutil.WriteFile(procsFile, []byte(strconv.Itoa(pid)), 0700)
87+
return os.WriteFile(procsFile, []byte(strconv.Itoa(pid)), 0700)
8988
}
9089

9190
// Remove removes CGroups

‎pkg/images/repository.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func LoadRepository() error {
3939
lock.Lock()
4040
defer lock.Unlock()
4141
if _, err := os.Stat(repositoryPath); os.IsNotExist(err) {
42-
ioutil.WriteFile(repositoryPath, []byte("{}"), 0644)
42+
os.WriteFile(repositoryPath, []byte("{}"), 0644)
4343
imgRepo = make(repository)
4444
return nil
4545
}
@@ -71,7 +71,7 @@ func SaveRepository() error {
7171
if err != nil {
7272
return errors.Wrap(err, "unable to marshal image regsitry")
7373
}
74-
if err = ioutil.WriteFile(repositoryPath, b, 0644); err != nil {
74+
if err = os.WriteFile(repositoryPath, b, 0644); err != nil {
7575
return errors.Wrap(err, "unable to save repository to file")
7676
}
7777
return nil

0 commit comments

Comments
 (0)
Please sign in to comment.