MCPcopy Create free account
hub / github.com/containerd/nerdctl / generateNamespaceOpts

Function generateNamespaceOpts

pkg/cmd/container/run_linux.go:121–155  ·  view source on GitHub ↗

generateNamespaceOpts help to validate the namespace options exposed via run and return the correct opts.

(
	ctx context.Context,
	client *containerd.Client,
	uts string,
	internalLabels *internalLabels,
	options types.ContainerCreateOptions,
)

Source from the content-addressed store, hash-verified

119
120// generateNamespaceOpts help to validate the namespace options exposed via run and return the correct opts.
121func generateNamespaceOpts(
122 ctx context.Context,
123 client *containerd.Client,
124 uts string,
125 internalLabels *internalLabels,
126 options types.ContainerCreateOptions,
127) ([]oci.SpecOpts, error) {
128 var opts []oci.SpecOpts
129
130 switch uts {
131 case "host":
132 opts = append(opts, oci.WithHostNamespace(specs.UTSNamespace))
133 case "":
134 // Default, do nothing. Every container gets its own UTS ns by default.
135 default:
136 return nil, fmt.Errorf("unknown uts value. valid value(s) are 'host', got: %q", uts)
137 }
138
139 stateDir := internalLabels.stateDir
140 ipcOpts, ipcLabel, err := generateIPCOpts(ctx, client, options.IPC, options.ShmSize, stateDir)
141 if err != nil {
142 return nil, err
143 }
144 internalLabels.ipc = ipcLabel
145 opts = append(opts, ipcOpts...)
146
147 pidOpts, pidLabel, err := generatePIDOpts(ctx, client, options.Pid)
148 if err != nil {
149 return nil, err
150 }
151 internalLabels.pidContainer = pidLabel
152 opts = append(opts, pidOpts...)
153
154 return opts, nil
155}
156
157func generateIPCOpts(ctx context.Context, client *containerd.Client, ipcFlag string, shmSize string, stateDir string) ([]oci.SpecOpts, string, error) {
158 ipcFlag = strings.ToLower(ipcFlag)

Callers 1

setPlatformOptionsFunction · 0.85

Calls 2

generateIPCOptsFunction · 0.85
generatePIDOptsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…