@@ -19,14 +19,11 @@ package cm
19
19
import (
20
20
"errors"
21
21
"fmt"
22
- "os"
23
- "path/filepath"
24
22
"strconv"
25
23
"strings"
26
24
27
25
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
28
26
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
29
-
30
27
v1 "k8s.io/api/core/v1"
31
28
"k8s.io/apimachinery/pkg/util/sets"
32
29
)
@@ -123,22 +120,6 @@ func (c *cgroupV1impl) GetCgroupConfig(name CgroupName, resource v1.ResourceName
123
120
return nil , fmt .Errorf ("unsupported resource %v for cgroup %v" , resource , name )
124
121
}
125
122
126
- // Set resource config for the specified resource type on the cgroup
127
- func (c * cgroupV1impl ) SetCgroupConfig (name CgroupName , resource v1.ResourceName , resourceConfig * ResourceConfig ) error {
128
- cgroupPaths := c .buildCgroupPaths (name )
129
- cgroupResourcePath , found := cgroupPaths [string (resource )]
130
- if ! found {
131
- return fmt .Errorf ("failed to build %v cgroup fs path for cgroup %v" , resource , name )
132
- }
133
- switch resource {
134
- case v1 .ResourceCPU :
135
- return c .setCgroupCPUConfig (cgroupResourcePath , resourceConfig )
136
- case v1 .ResourceMemory :
137
- return c .setCgroupMemoryConfig (cgroupResourcePath , resourceConfig )
138
- }
139
- return nil
140
- }
141
-
142
123
func (c * cgroupV1impl ) getCgroupCPUConfig (cgroupPath string ) (* ResourceConfig , error ) {
143
124
cpuQuotaStr , errQ := fscommon .GetCgroupParamString (cgroupPath , "cpu.cfs_quota_us" )
144
125
if errQ != nil {
@@ -159,33 +140,6 @@ func (c *cgroupV1impl) getCgroupCPUConfig(cgroupPath string) (*ResourceConfig, e
159
140
return & ResourceConfig {CPUShares : & cpuShares , CPUQuota : & cpuQuota , CPUPeriod : & cpuPeriod }, nil
160
141
}
161
142
162
- func (c * cgroupV1impl ) setCgroupCPUConfig (cgroupPath string , resourceConfig * ResourceConfig ) error {
163
- var cpuQuotaStr , cpuPeriodStr , cpuSharesStr string
164
- if resourceConfig .CPUQuota != nil {
165
- cpuQuotaStr = strconv .FormatInt (* resourceConfig .CPUQuota , 10 )
166
- if err := os .WriteFile (filepath .Join (cgroupPath , "cpu.cfs_quota_us" ), []byte (cpuQuotaStr ), 0700 ); err != nil {
167
- return fmt .Errorf ("failed to write %v to %v: %w" , cpuQuotaStr , cgroupPath , err )
168
- }
169
- }
170
- if resourceConfig .CPUPeriod != nil {
171
- cpuPeriodStr = strconv .FormatUint (* resourceConfig .CPUPeriod , 10 )
172
- if err := os .WriteFile (filepath .Join (cgroupPath , "cpu.cfs_period_us" ), []byte (cpuPeriodStr ), 0700 ); err != nil {
173
- return fmt .Errorf ("failed to write %v to %v: %w" , cpuPeriodStr , cgroupPath , err )
174
- }
175
- }
176
- if resourceConfig .CPUShares != nil {
177
- cpuSharesStr = strconv .FormatUint (* resourceConfig .CPUShares , 10 )
178
- if err := os .WriteFile (filepath .Join (cgroupPath , "cpu.shares" ), []byte (cpuSharesStr ), 0700 ); err != nil {
179
- return fmt .Errorf ("failed to write %v to %v: %w" , cpuSharesStr , cgroupPath , err )
180
- }
181
- }
182
- return nil
183
- }
184
-
185
- func (c * cgroupV1impl ) setCgroupMemoryConfig (cgroupPath string , resourceConfig * ResourceConfig ) error {
186
- return writeCgroupMemoryLimit (filepath .Join (cgroupPath , cgroupv1MemLimitFile ), resourceConfig )
187
- }
188
-
189
143
func (c * cgroupV1impl ) getCgroupMemoryConfig (cgroupPath string ) (* ResourceConfig , error ) {
190
144
return readCgroupMemoryConfig (cgroupPath , cgroupv1MemLimitFile )
191
145
}
0 commit comments