(ctx context.Context, containerID string, quota xunix.CPUQuota)
| 154 | } |
| 155 | |
| 156 | func 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 | |
| 177 | func setContainerQuotaCGroupV1(ctx context.Context, containerID string, quota xunix.CPUQuota) error { |
| 178 | var ( |
no test coverage detected