Repository: containerd/containerd
File: cmd/ctr/commands/run/run_unix.go (Go)

Code before:

		if burst := cliContext.Uint64("cpu-burst"); burst != 0 {
			opts = append(opts, oci.WithCPUBurst(burst))
		}

		joinNs := cliContext.StringSlice("with-ns")
		for _, ns := range joinNs {
			nsType, nsPath, ok := strings.Cut(ns, ":")
			if !ok {
				return nil, errors.New("joining a Linux namespace using --with-ns requires the format 'nstype:path'")
			}
			if !validNamespace(nsType) {
				return nil, errors.New("the Linux namespace type specified in --with-ns is not valid: " + nsType)
			}
			opts = append(opts, oci.WithLinuxNamespace(specs.LinuxNamespace{
				Type: specs.LinuxNamespaceType(nsType),
				Path: nsPath,
			}))
		}
		var cdiDeviceIDs []string
		if cliContext.IsSet("gpus") {
			for _, id := range cliContext.IntSlice("gpus") {
				cdiDeviceID := fmt.Sprintf("nvidia.com/gpu=%d", id)
				cdiDeviceIDs = append(cdiDeviceIDs, cdiDeviceID)
			}
		}
		if cliContext.IsSet("allow-new-privs") {
			opts = append(opts, oci.WithNewPrivileges)
		}
		if cliContext.IsSet("cgroup") {
			// NOTE: can be set to "" explicitly for disabling cgroup.
			opts = append(opts, oci.WithCgroup(cliContext.String("cgroup")))
		}
		limit := cliContext.Uint64("memory-limit")
		if limit != 0 {
			opts = append(opts, oci.WithMemoryLimit(limit))
		}
		for _, dev := range cliContext.StringSlice("device") {
			if parser.IsQualifiedName(dev) {
				cdiDeviceIDs = append(cdiDeviceIDs, dev)
				continue
			}
			opts = append(opts, oci.WithDevices(dev, "", "rwm"))
		}
		if len(cdiDeviceIDs) > 0 {
			opts = append(opts, withStaticCDIRegistry())
		}
		opts = append(opts, cdispec.WithCDIDevices(cdiDeviceIDs...))

		rootfsPropagation := cliContext.String("rootfs-propagation")
		if rootfsPropagation != "" {

Review comment (suggestion):
@mxpv would you prefer that this be opt-out? (I wanted to ask that before removing the code that this calls).

Code after:
				return nil, errors.New("cpus and quota/period should be used separately")
			}
			opts = append(opts, oci.WithCPUCFS(quota, period))
		}

		if burst := cliContext.Uint64("cpu-burst"); burst != 0 {
			opts = append(opts, oci.WithCPUBurst(burst))
		}

		joinNs := cliContext.StringSlice("with-ns")
		for _, ns := range joinNs {
			nsType, nsPath, ok := strings.Cut(ns, ":")
			if !ok {
				return nil, errors.New("joining a Linux namespace using --with-ns requires the format 'nstype:path'")
			}
			if !validNamespace(nsType) {
				return nil, errors.New("the Linux namespace type specified in --with-ns is not valid: " + nsType)
			}
			opts = append(opts, oci.WithLinuxNamespace(specs.LinuxNamespace{
				Type: specs.LinuxNamespaceType(nsType),
				Path: nsPath,
			}))
		}
		var cdiDeviceIDs []string
		if cliContext.IsSet("gpus") {
			for _, id := range cliContext.IntSlice("gpus") {
				cdiDeviceID := fmt.Sprintf("nvidia.com/gpu=%d", id)
				cdiDeviceIDs = append(cdiDeviceIDs, cdiDeviceID)
			}
		}
		if cliContext.IsSet("allow-new-privs") {
			opts = append(opts, oci.WithNewPrivileges)
		}
		if cliContext.IsSet("cgroup") {
			// NOTE: can be set to "" explicitly for disabling cgroup.
			opts = append(opts, oci.WithCgroup(cliContext.String("cgroup")))
		}
		limit := cliContext.Uint64("memory-limit")
		if limit != 0 {
			opts = append(opts, oci.WithMemoryLimit(limit))
		}
		for _, dev := range cliContext.StringSlice("device") {
			if parser.IsQualifiedName(dev) {
				cdiDeviceIDs = append(cdiDeviceIDs, dev)
				continue
			}
			opts = append(opts, oci.WithDevices(dev, "", "rwm"))
		}
		if len(cdiDeviceIDs) > 0 {
			opts = append(opts, withStaticCDIRegistry())
		}