ReadCPUQuota attempts to read the CFS CPU quota and period from the current container context. It first attempts to read the paths relevant to cgroupv2 and falls back to reading the paths relevant go cgroupv1 Relevant paths for cgroupv2: - /proc/self/cgroup - /sys/fs/cgroup/ /cpu.max Relevant
(ctx context.Context, log slog.Logger)
| 47 | // - /sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us |
| 48 | // - /sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us |
| 49 | func ReadCPUQuota(ctx context.Context, log slog.Logger) (CPUQuota, error) { |
| 50 | quota, err := readCPUQuotaCGroupV2(ctx) |
| 51 | if err == nil { |
| 52 | return quota, nil |
| 53 | } |
| 54 | |
| 55 | log.Info(ctx, "Unable to read cgroupv2 quota, falling back to cgroupv1", slog.Error(err)) |
| 56 | return readCPUQuotaCGroupV1(ctx) |
| 57 | } |
| 58 | |
| 59 | func readCPUQuotaCGroupV2(ctx context.Context) (CPUQuota, error) { |
| 60 | fs := GetFS(ctx) |