MCPcopy Create free account
hub / github.com/coder/envbox / setContainerQuotaCGroupV1

Function setContainerQuotaCGroupV1

dockerutil/container.go:177–194  ·  view source on GitHub ↗
(ctx context.Context, containerID string, quota xunix.CPUQuota)

Source from the content-addressed store, hash-verified

175}
176
177func setContainerQuotaCGroupV1(ctx context.Context, containerID string, quota xunix.CPUQuota) error {
178 var (
179 fs = xunix.GetFS(ctx)
180 cgroupBase = fmt.Sprintf("/sys/fs/cgroup/cpu,cpuacct/docker/%s/syscont-cgroup-root/", containerID)
181 )
182
183 err := afero.WriteFile(fs, filepath.Join(cgroupBase, "cpu.cfs_period_us"), []byte(strconv.Itoa(quota.Period)), 0o644)
184 if err != nil {
185 return xerrors.Errorf("write cpu.cfs_period_us to inner container cgroup: %w", err)
186 }
187
188 err = afero.WriteFile(fs, filepath.Join(cgroupBase, "cpu.cfs_quota_us"), []byte(strconv.Itoa(quota.Quota)), 0o644)
189 if err != nil {
190 return xerrors.Errorf("write cpu.cfs_quota_us to inner container cgroup: %w", err)
191 }
192
193 return nil
194}
195
196func generateBindMounts(mounts []xunix.Mount) []string {
197 binds := make([]string, 0, len(mounts))

Callers 1

SetContainerQuotaFunction · 0.85

Calls 2

GetFSFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected