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, )
| 119 | |
| 120 | // generateNamespaceOpts help to validate the namespace options exposed via run and return the correct opts. |
| 121 | func 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 | |
| 157 | func generateIPCOpts(ctx context.Context, client *containerd.Client, ipcFlag string, shmSize string, stateDir string) ([]oci.SpecOpts, string, error) { |
| 158 | ipcFlag = strings.ToLower(ipcFlag) |
no test coverage detected
searching dependent graphs…