|
17 | 17 | package main
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "context" |
20 | 21 | "errors"
|
21 | 22 | "fmt"
|
22 | 23 | "path/filepath"
|
23 | 24 | "strings"
|
24 | 25 |
|
| 26 | + "github.com/containerd/containerd/containers" |
25 | 27 | "github.com/containerd/containerd/oci"
|
| 28 | + "github.com/containerd/nerdctl/pkg/infoutil" |
26 | 29 | "github.com/containerd/nerdctl/pkg/rootlessutil"
|
27 | 30 | "github.com/docker/go-units"
|
28 | 31 | "github.com/opencontainers/runtime-spec/specs-go"
|
@@ -112,6 +115,24 @@ func generateCgroupOpts(cmd *cobra.Command, id string) ([]oci.SpecOpts, error) {
|
112 | 115 | opts = append(opts, oci.WithPidsLimit(int64(pidsLimit)))
|
113 | 116 | }
|
114 | 117 |
|
| 118 | + cgroupConf, err := cmd.Flags().GetStringSlice("cgroup-conf") |
| 119 | + if err != nil { |
| 120 | + return nil, err |
| 121 | + } |
| 122 | + if len(cgroupConf) > 0 && infoutil.CgroupsVersion() == "1" { |
| 123 | + return nil, errors.New("cannot use --cgroup-conf without cgroup v2") |
| 124 | + } |
| 125 | + |
| 126 | + unifieds := make(map[string]string) |
| 127 | + for _, unified := range cgroupConf { |
| 128 | + splitUnified := strings.SplitN(unified, "=", 2) |
| 129 | + if len(splitUnified) < 2 { |
| 130 | + return nil, errors.New("--cgroup-conf must be formatted KEY=VALUE") |
| 131 | + } |
| 132 | + unifieds[splitUnified[0]] = splitUnified[1] |
| 133 | + } |
| 134 | + opts = append(opts, withUnified(unifieds)) |
| 135 | + |
115 | 136 | cgroupns, err := cmd.Flags().GetString("cgroupns")
|
116 | 137 | if err != nil {
|
117 | 138 | return nil, err
|
@@ -190,3 +211,16 @@ func validateDeviceMode(mode string) error {
|
190 | 211 | }
|
191 | 212 | return nil
|
192 | 213 | }
|
| 214 | + |
| 215 | +func withUnified(unified map[string]string) oci.SpecOpts { |
| 216 | + return func(_ context.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) (err error) { |
| 217 | + if unified == nil { |
| 218 | + return nil |
| 219 | + } |
| 220 | + s.Linux.Resources.Unified = make(map[string]string) |
| 221 | + for k, v := range unified { |
| 222 | + s.Linux.Resources.Unified[k] = v |
| 223 | + } |
| 224 | + return nil |
| 225 | + } |
| 226 | +} |
0 commit comments