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

Function setContainerQuotaCGroupV2

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

Source from the content-addressed store, hash-verified

154}
155
156func setContainerQuotaCGroupV2(ctx context.Context, containerID string, quota xunix.CPUQuota) error {
157 var (
158 fs = xunix.GetFS(ctx)
159 cgroupBase = fmt.Sprintf("/sys/fs/cgroup/docker/%s/init.scope/", containerID)
160 )
161
162 var content string
163 if quota.Quota < 0 {
164 content = fmt.Sprintf("max %d\n", quota.Period)
165 } else {
166 content = fmt.Sprintf("%d %d\n", quota.Quota, quota.Period)
167 }
168
169 err := afero.WriteFile(fs, filepath.Join(cgroupBase, "cpu.max"), []byte(content), 0o644)
170 if err != nil {
171 return xerrors.Errorf("write cpu.max to inner container cgroup: %w", err)
172 }
173
174 return nil
175}
176
177func setContainerQuotaCGroupV1(ctx context.Context, containerID string, quota xunix.CPUQuota) error {
178 var (

Callers 1

SetContainerQuotaFunction · 0.85

Calls 2

GetFSFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected