github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/specgen/specgen.go (about) 1 package specgen 2 3 import ( 4 "net" 5 "strings" 6 "syscall" 7 8 "github.com/containers/common/libimage" 9 nettypes "github.com/containers/common/libnetwork/types" 10 "github.com/containers/image/v5/manifest" 11 "github.com/containers/storage/types" 12 spec "github.com/opencontainers/runtime-spec/specs-go" 13 "github.com/pkg/errors" 14 ) 15 16 // LogConfig describes the logging characteristics for a container 17 type LogConfig struct { 18 // LogDriver is the container's log driver. 19 // Optional. 20 Driver string `json:"driver,omitempty"` 21 // LogPath is the path the container's logs will be stored at. 22 // Only available if LogDriver is set to "json-file" or "k8s-file". 23 // Optional. 24 Path string `json:"path,omitempty"` 25 // Size is the maximum size of the log file 26 // Optional. 27 Size int64 `json:"size,omitempty"` 28 // A set of options to accompany the log driver. 29 // Optional. 30 Options map[string]string `json:"options,omitempty"` 31 } 32 33 // ContainerBasicConfig contains the basic parts of a container. 34 type ContainerBasicConfig struct { 35 // Name is the name the container will be given. 36 // If no name is provided, one will be randomly generated. 37 // Optional. 38 Name string `json:"name,omitempty"` 39 // Pod is the ID of the pod the container will join. 40 // Optional. 41 Pod string `json:"pod,omitempty"` 42 // Entrypoint is the container's entrypoint. 43 // If not given and Image is specified, this will be populated by the 44 // image's configuration. 45 // Optional. 46 Entrypoint []string `json:"entrypoint,omitempty"` 47 // Command is the container's command. 48 // If not given and Image is specified, this will be populated by the 49 // image's configuration. 50 // Optional. 51 Command []string `json:"command,omitempty"` 52 // EnvHost indicates that the host environment should be added to container 53 // Optional. 54 EnvHost bool `json:"env_host,omitempty"` 55 // EnvHTTPProxy indicates that the http host proxy environment variables 56 // should be added to container 57 // Optional. 58 HTTPProxy bool `json:"httpproxy,omitempty"` 59 // Env is a set of environment variables that will be set in the 60 // container. 61 // Optional. 62 Env map[string]string `json:"env,omitempty"` 63 // Terminal is whether the container will create a PTY. 64 // Optional. 65 Terminal bool `json:"terminal,omitempty"` 66 // Stdin is whether the container will keep its STDIN open. 67 Stdin bool `json:"stdin,omitempty"` 68 // Labels are key-value pairs that are used to add metadata to 69 // containers. 70 // Optional. 71 Labels map[string]string `json:"labels,omitempty"` 72 // Annotations are key-value options passed into the container runtime 73 // that can be used to trigger special behavior. 74 // Optional. 75 Annotations map[string]string `json:"annotations,omitempty"` 76 // StopSignal is the signal that will be used to stop the container. 77 // Must be a non-zero integer below SIGRTMAX. 78 // If not provided, the default, SIGTERM, will be used. 79 // Will conflict with Systemd if Systemd is set to "true" or "always". 80 // Optional. 81 StopSignal *syscall.Signal `json:"stop_signal,omitempty"` 82 // StopTimeout is a timeout between the container's stop signal being 83 // sent and SIGKILL being sent. 84 // If not provided, the default will be used. 85 // If 0 is used, stop signal will not be sent, and SIGKILL will be sent 86 // instead. 87 // Optional. 88 StopTimeout *uint `json:"stop_timeout,omitempty"` 89 // Timeout is a maximum time in seconds the container will run before 90 // main process is sent SIGKILL. 91 // If 0 is used, signal will not be sent. Container can run indefinitely 92 // Optional. 93 Timeout uint `json:"timeout,omitempty"` 94 // LogConfiguration describes the logging for a container including 95 // driver, path, and options. 96 // Optional 97 LogConfiguration *LogConfig `json:"log_configuration,omitempty"` 98 // ConmonPidFile is a path at which a PID file for Conmon will be 99 // placed. 100 // If not given, a default location will be used. 101 // Optional. 102 ConmonPidFile string `json:"conmon_pid_file,omitempty"` 103 // RawImageName is the user-specified and unprocessed input referring 104 // to a local or a remote image. 105 RawImageName string `json:"raw_image_name,omitempty"` 106 // RestartPolicy is the container's restart policy - an action which 107 // will be taken when the container exits. 108 // If not given, the default policy, which does nothing, will be used. 109 // Optional. 110 RestartPolicy string `json:"restart_policy,omitempty"` 111 // RestartRetries is the number of attempts that will be made to restart 112 // the container. 113 // Only available when RestartPolicy is set to "on-failure". 114 // Optional. 115 RestartRetries *uint `json:"restart_tries,omitempty"` 116 // OCIRuntime is the name of the OCI runtime that will be used to create 117 // the container. 118 // If not specified, the default will be used. 119 // Optional. 120 OCIRuntime string `json:"oci_runtime,omitempty"` 121 // Systemd is whether the container will be started in systemd mode. 122 // Valid options are "true", "false", and "always". 123 // "true" enables this mode only if the binary run in the container is 124 // /sbin/init or systemd. "always" unconditionally enables systemd mode. 125 // "false" unconditionally disables systemd mode. 126 // If enabled, mounts and stop signal will be modified. 127 // If set to "always" or set to "true" and conditionally triggered, 128 // conflicts with StopSignal. 129 // If not specified, "false" will be assumed. 130 // Optional. 131 Systemd string `json:"systemd,omitempty"` 132 // Determine how to handle the NOTIFY_SOCKET - do we participate or pass it through 133 // "container" - let the OCI runtime deal with it, advertise conmon's MAINPID 134 // "conmon-only" - advertise conmon's MAINPID, send READY when started, don't pass to OCI 135 // "ignore" - unset NOTIFY_SOCKET 136 SdNotifyMode string `json:"sdnotifyMode,omitempty"` 137 // Namespace is the libpod namespace the container will be placed in. 138 // Optional. 139 Namespace string `json:"namespace,omitempty"` 140 // PidNS is the container's PID namespace. 141 // It defaults to private. 142 // Mandatory. 143 PidNS Namespace `json:"pidns,omitempty"` 144 // UtsNS is the container's UTS namespace. 145 // It defaults to private. 146 // Must be set to Private to set Hostname. 147 // Mandatory. 148 UtsNS Namespace `json:"utsns,omitempty"` 149 // Hostname is the container's hostname. If not set, the hostname will 150 // not be modified (if UtsNS is not private) or will be set to the 151 // container ID (if UtsNS is private). 152 // Conflicts with UtsNS if UtsNS is not set to private. 153 // Optional. 154 Hostname string `json:"hostname,omitempty"` 155 // HostUses is a list of host usernames or UIDs to add to the container 156 // /etc/passwd file 157 HostUsers []string `json:"hostusers,omitempty"` 158 // Sysctl sets kernel parameters for the container 159 Sysctl map[string]string `json:"sysctl,omitempty"` 160 // Remove indicates if the container should be removed once it has been started 161 // and exits 162 Remove bool `json:"remove,omitempty"` 163 // ContainerCreateCommand is the command that was used to create this 164 // container. 165 // This will be shown in the output of Inspect() on the container, and 166 // may also be used by some tools that wish to recreate the container 167 // (e.g. `podman generate systemd --new`). 168 // Optional. 169 ContainerCreateCommand []string `json:"containerCreateCommand,omitempty"` 170 // PreserveFDs is a number of additional file descriptors (in addition 171 // to 0, 1, 2) that will be passed to the executed process. The total FDs 172 // passed will be 3 + PreserveFDs. 173 // set tags as `json:"-"` for not supported remote 174 // Optional. 175 PreserveFDs uint `json:"-"` 176 // Timezone is the timezone inside the container. 177 // Local means it has the same timezone as the host machine 178 // Optional. 179 Timezone string `json:"timezone,omitempty"` 180 // DependencyContainers is an array of containers this container 181 // depends on. Dependency containers must be started before this 182 // container. Dependencies can be specified by name or full/partial ID. 183 // Optional. 184 DependencyContainers []string `json:"dependencyContainers,omitempty"` 185 // PidFile is the file that saves container process id. 186 // set tags as `json:"-"` for not supported remote 187 // Optional. 188 PidFile string `json:"-"` 189 // EnvSecrets are secrets that will be set as environment variables 190 // Optional. 191 EnvSecrets map[string]string `json:"secret_env,omitempty"` 192 // InitContainerType describes if this container is an init container 193 // and if so, what type: always or once 194 InitContainerType string `json:"init_container_type"` 195 // Personality allows users to configure different execution domains. 196 // Execution domains tell Linux how to map signal numbers into signal actions. 197 // The execution domain system allows Linux to provide limited support 198 // for binaries compiled under other UNIX-like operating systems. 199 Personality *spec.LinuxPersonality `json:"personality,omitempty"` 200 // UnsetEnv unsets the specified default environment variables from the image or from buildin or containers.conf 201 // Optional. 202 UnsetEnv []string `json:"unsetenv,omitempty"` 203 // UnsetEnvAll unsetall default environment variables from the image or from buildin or containers.conf 204 // UnsetEnvAll unsets all default environment variables from the image or from buildin 205 // Optional. 206 UnsetEnvAll bool `json:"unsetenvall,omitempty"` 207 // Passwd is a container run option that determines if we are validating users/groups before running the container 208 Passwd *bool `json:"manage_password,omitempty"` 209 // PasswdEntry specifies arbitrary data to append to a file. 210 PasswdEntry string `json:"passwd_entry,omitempty"` 211 } 212 213 // ContainerStorageConfig contains information on the storage configuration of a 214 // container. 215 type ContainerStorageConfig struct { 216 // Image is the image the container will be based on. The image will be 217 // used as the container's root filesystem, and its environment vars, 218 // volumes, and other configuration will be applied to the container. 219 // Conflicts with Rootfs. 220 // At least one of Image or Rootfs must be specified. 221 Image string `json:"image"` 222 // Rootfs is the path to a directory that will be used as the 223 // container's root filesystem. No modification will be made to the 224 // directory, it will be directly mounted into the container as root. 225 // Conflicts with Image. 226 // At least one of Image or Rootfs must be specified. 227 Rootfs string `json:"rootfs,omitempty"` 228 // RootfsOverlay tells if rootfs is actually an overlay on top of base path 229 RootfsOverlay bool `json:"rootfs_overlay,omitempty"` 230 // ImageVolumeMode indicates how image volumes will be created. 231 // Supported modes are "ignore" (do not create), "tmpfs" (create as 232 // tmpfs), and "anonymous" (create as anonymous volumes). 233 // The default if unset is anonymous. 234 // Optional. 235 ImageVolumeMode string `json:"image_volume_mode,omitempty"` 236 // VolumesFrom is a set of containers whose volumes will be added to 237 // this container. The name or ID of the container must be provided, and 238 // may optionally be followed by a : and then one or more 239 // comma-separated options. Valid options are 'ro', 'rw', and 'z'. 240 // Options will be used for all volumes sourced from the container. 241 VolumesFrom []string `json:"volumes_from,omitempty"` 242 // Init specifies that an init binary will be mounted into the 243 // container, and will be used as PID1. 244 Init bool `json:"init,omitempty"` 245 // InitPath specifies the path to the init binary that will be added if 246 // Init is specified above. If not specified, the default set in the 247 // Libpod config will be used. Ignored if Init above is not set. 248 // Optional. 249 InitPath string `json:"init_path,omitempty"` 250 // Mounts are mounts that will be added to the container. 251 // These will supersede Image Volumes and VolumesFrom volumes where 252 // there are conflicts. 253 // Optional. 254 Mounts []spec.Mount `json:"mounts,omitempty"` 255 // Volumes are named volumes that will be added to the container. 256 // These will supersede Image Volumes and VolumesFrom volumes where 257 // there are conflicts. 258 // Optional. 259 Volumes []*NamedVolume `json:"volumes,omitempty"` 260 // Overlay volumes are named volumes that will be added to the container. 261 // Optional. 262 OverlayVolumes []*OverlayVolume `json:"overlay_volumes,omitempty"` 263 // Image volumes bind-mount a container-image mount into the container. 264 // Optional. 265 ImageVolumes []*ImageVolume `json:"image_volumes,omitempty"` 266 // Devices are devices that will be added to the container. 267 // Optional. 268 Devices []spec.LinuxDevice `json:"devices,omitempty"` 269 // DeviceCgroupRule are device cgroup rules that allow containers 270 // to use additional types of devices. 271 DeviceCgroupRule []spec.LinuxDeviceCgroup `json:"device_cgroup_rule,omitempty"` 272 // DevicesFrom is a way to ensure your container inherits device specific information from another container 273 DevicesFrom []string `json:"devices_from,omitempty"` 274 // HostDeviceList is used to recreate the mounted device on inherited containers 275 HostDeviceList []spec.LinuxDevice `json:"host_device_list,omitempty"` 276 // IpcNS is the container's IPC namespace. 277 // Default is private. 278 // Conflicts with ShmSize if not set to private. 279 // Mandatory. 280 IpcNS Namespace `json:"ipcns,omitempty"` 281 // ShmSize is the size of the tmpfs to mount in at /dev/shm, in bytes. 282 // Conflicts with ShmSize if IpcNS is not private. 283 // Optional. 284 ShmSize *int64 `json:"shm_size,omitempty"` 285 // WorkDir is the container's working directory. 286 // If unset, the default, /, will be used. 287 // Optional. 288 WorkDir string `json:"work_dir,omitempty"` 289 // Create the working directory if it doesn't exist. 290 // If unset, it doesn't create it. 291 // Optional. 292 CreateWorkingDir bool `json:"create_working_dir,omitempty"` 293 // StorageOpts is the container's storage options 294 // Optional. 295 StorageOpts map[string]string `json:"storage_opts,omitempty"` 296 // RootfsPropagation is the rootfs propagation mode for the container. 297 // If not set, the default of rslave will be used. 298 // Optional. 299 RootfsPropagation string `json:"rootfs_propagation,omitempty"` 300 // Secrets are the secrets that will be added to the container 301 // Optional. 302 Secrets []Secret `json:"secrets,omitempty"` 303 // Volatile specifies whether the container storage can be optimized 304 // at the cost of not syncing all the dirty files in memory. 305 Volatile bool `json:"volatile,omitempty"` 306 // ChrootDirs is an additional set of directories that need to be 307 // treated as root directories. Standard bind mounts will be mounted 308 // into paths relative to these directories. 309 ChrootDirs []string `json:"chroot_directories,omitempty"` 310 } 311 312 // ContainerSecurityConfig is a container's security features, including 313 // SELinux, Apparmor, and Seccomp. 314 type ContainerSecurityConfig struct { 315 // Privileged is whether the container is privileged. 316 // Privileged does the following: 317 // - Adds all devices on the system to the container. 318 // - Adds all capabilities to the container. 319 // - Disables Seccomp, SELinux, and Apparmor confinement. 320 // (Though SELinux can be manually re-enabled). 321 // TODO: this conflicts with things. 322 // TODO: this does more. 323 Privileged bool `json:"privileged,omitempty"` 324 // User is the user the container will be run as. 325 // Can be given as a UID or a username; if a username, it will be 326 // resolved within the container, using the container's /etc/passwd. 327 // If unset, the container will be run as root. 328 // Optional. 329 User string `json:"user,omitempty"` 330 // Groups are a list of supplemental groups the container's user will 331 // be granted access to. 332 // Optional. 333 Groups []string `json:"groups,omitempty"` 334 // CapAdd are capabilities which will be added to the container. 335 // Conflicts with Privileged. 336 // Optional. 337 CapAdd []string `json:"cap_add,omitempty"` 338 // CapDrop are capabilities which will be removed from the container. 339 // Conflicts with Privileged. 340 // Optional. 341 CapDrop []string `json:"cap_drop,omitempty"` 342 // SelinuxProcessLabel is the process label the container will use. 343 // If SELinux is enabled and this is not specified, a label will be 344 // automatically generated if not specified. 345 // Optional. 346 SelinuxOpts []string `json:"selinux_opts,omitempty"` 347 // ApparmorProfile is the name of the Apparmor profile the container 348 // will use. 349 // Optional. 350 ApparmorProfile string `json:"apparmor_profile,omitempty"` 351 // SeccompPolicy determines which seccomp profile gets applied 352 // the container. valid values: empty,default,image 353 SeccompPolicy string `json:"seccomp_policy,omitempty"` 354 // SeccompProfilePath is the path to a JSON file containing the 355 // container's Seccomp profile. 356 // If not specified, no Seccomp profile will be used. 357 // Optional. 358 SeccompProfilePath string `json:"seccomp_profile_path,omitempty"` 359 // NoNewPrivileges is whether the container will set the no new 360 // privileges flag on create, which disables gaining additional 361 // privileges (e.g. via setuid) in the container. 362 NoNewPrivileges bool `json:"no_new_privileges,omitempty"` 363 // UserNS is the container's user namespace. 364 // It defaults to host, indicating that no user namespace will be 365 // created. 366 // If set to private, IDMappings must be set. 367 // Mandatory. 368 UserNS Namespace `json:"userns,omitempty"` 369 // IDMappings are UID and GID mappings that will be used by user 370 // namespaces. 371 // Required if UserNS is private. 372 IDMappings *types.IDMappingOptions `json:"idmappings,omitempty"` 373 // ReadOnlyFilesystem indicates that everything will be mounted 374 // as read-only 375 ReadOnlyFilesystem bool `json:"read_only_filesystem,omitempty"` 376 // Umask is the umask the init process of the container will be run with. 377 Umask string `json:"umask,omitempty"` 378 // ProcOpts are the options used for the proc mount. 379 ProcOpts []string `json:"procfs_opts,omitempty"` 380 // Mask is the path we want to mask in the container. This masks the paths 381 // given in addition to the default list. 382 // Optional 383 Mask []string `json:"mask,omitempty"` 384 // Unmask is the path we want to unmask in the container. To override 385 // all the default paths that are masked, set unmask=ALL. 386 Unmask []string `json:"unmask,omitempty"` 387 } 388 389 // ContainerCgroupConfig contains configuration information about a container's 390 // cgroups. 391 type ContainerCgroupConfig struct { 392 // CgroupNS is the container's cgroup namespace. 393 // It defaults to private. 394 // Mandatory. 395 CgroupNS Namespace `json:"cgroupns,omitempty"` 396 // CgroupsMode sets a policy for how cgroups will be created in the 397 // container, including the ability to disable creation entirely. 398 CgroupsMode string `json:"cgroups_mode,omitempty"` 399 // CgroupParent is the container's Cgroup parent. 400 // If not set, the default for the current cgroup driver will be used. 401 // Optional. 402 CgroupParent string `json:"cgroup_parent,omitempty"` 403 } 404 405 // ContainerNetworkConfig contains information on a container's network 406 // configuration. 407 type ContainerNetworkConfig struct { 408 // NetNS is the configuration to use for the container's network 409 // namespace. 410 // Mandatory. 411 NetNS Namespace `json:"netns,omitempty"` 412 // PortBindings is a set of ports to map into the container. 413 // Only available if NetNS is set to bridge or slirp. 414 // Optional. 415 PortMappings []nettypes.PortMapping `json:"portmappings,omitempty"` 416 // PublishExposedPorts will publish ports specified in the image to 417 // random unused ports (guaranteed to be above 1024) on the host. 418 // This is based on ports set in Expose below, and any ports specified 419 // by the Image (if one is given). 420 // Only available if NetNS is set to Bridge or Slirp. 421 PublishExposedPorts bool `json:"publish_image_ports,omitempty"` 422 // Expose is a number of ports that will be forwarded to the container 423 // if PublishExposedPorts is set. 424 // Expose is a map of uint16 (port number) to a string representing 425 // protocol i.e map[uint16]string. Allowed protocols are "tcp", "udp", and "sctp", or some 426 // combination of the three separated by commas. 427 // If protocol is set to "" we will assume TCP. 428 // Only available if NetNS is set to Bridge or Slirp, and 429 // PublishExposedPorts is set. 430 // Optional. 431 Expose map[uint16]string `json:"expose,omitempty"` 432 // Map of networks names or ids that the container should join. 433 // You can request additional settings for each network, you can 434 // set network aliases, static ips, static mac address and the 435 // network interface name for this container on the specific network. 436 // If the map is empty and the bridge network mode is set the container 437 // will be joined to the default network. 438 Networks map[string]nettypes.PerNetworkOptions 439 // CNINetworks is a list of CNI networks to join the container to. 440 // If this list is empty, the default CNI network will be joined 441 // instead. If at least one entry is present, we will not join the 442 // default network (unless it is part of this list). 443 // Only available if NetNS is set to bridge. 444 // Optional. 445 // Deprecated: as of podman 4.0 use "Networks" instead. 446 CNINetworks []string `json:"cni_networks,omitempty"` 447 // UseImageResolvConf indicates that resolv.conf should not be managed 448 // by Podman, but instead sourced from the image. 449 // Conflicts with DNSServer, DNSSearch, DNSOption. 450 UseImageResolvConf bool `json:"use_image_resolve_conf,omitempty"` 451 // DNSServers is a set of DNS servers that will be used in the 452 // container's resolv.conf, replacing the host's DNS Servers which are 453 // used by default. 454 // Conflicts with UseImageResolvConf. 455 // Optional. 456 DNSServers []net.IP `json:"dns_server,omitempty"` 457 // DNSSearch is a set of DNS search domains that will be used in the 458 // container's resolv.conf, replacing the host's DNS search domains 459 // which are used by default. 460 // Conflicts with UseImageResolvConf. 461 // Optional. 462 DNSSearch []string `json:"dns_search,omitempty"` 463 // DNSOptions is a set of DNS options that will be used in the 464 // container's resolv.conf, replacing the host's DNS options which are 465 // used by default. 466 // Conflicts with UseImageResolvConf. 467 // Optional. 468 DNSOptions []string `json:"dns_option,omitempty"` 469 // UseImageHosts indicates that /etc/hosts should not be managed by 470 // Podman, and instead sourced from the image. 471 // Conflicts with HostAdd. 472 // Do not set omitempty here, if this is false it should be set to not get 473 // the server default. 474 // Ideally this would be a pointer so we could differentiate between an 475 // explicitly false/true and unset (containers.conf default). However 476 // specgen is stable so we can not change this right now. 477 // TODO (5.0): change to pointer 478 UseImageHosts bool `json:"use_image_hosts"` 479 // HostAdd is a set of hosts which will be added to the container's 480 // /etc/hosts file. 481 // Conflicts with UseImageHosts. 482 // Optional. 483 HostAdd []string `json:"hostadd,omitempty"` 484 // NetworkOptions are additional options for each network 485 // Optional. 486 NetworkOptions map[string][]string `json:"network_options,omitempty"` 487 } 488 489 // ContainerResourceConfig contains information on container resource limits. 490 type ContainerResourceConfig struct { 491 // ResourceLimits are resource limits to apply to the container., 492 // Can only be set as root on cgroups v1 systems, but can be set as 493 // rootless as well for cgroups v2. 494 // Optional. 495 ResourceLimits *spec.LinuxResources `json:"resource_limits,omitempty"` 496 // Rlimits are POSIX rlimits to apply to the container. 497 // Optional. 498 Rlimits []spec.POSIXRlimit `json:"r_limits,omitempty"` 499 // OOMScoreAdj adjusts the score used by the OOM killer to determine 500 // processes to kill for the container's process. 501 // Optional. 502 OOMScoreAdj *int `json:"oom_score_adj,omitempty"` 503 // Weight per cgroup per device, can override BlkioWeight 504 WeightDevice map[string]spec.LinuxWeightDevice `json:"weightDevice,omitempty"` 505 // IO read rate limit per cgroup per device, bytes per second 506 ThrottleReadBpsDevice map[string]spec.LinuxThrottleDevice `json:"throttleReadBpsDevice,omitempty"` 507 // IO write rate limit per cgroup per device, bytes per second 508 ThrottleWriteBpsDevice map[string]spec.LinuxThrottleDevice `json:"throttleWriteBpsDevice,omitempty"` 509 // IO read rate limit per cgroup per device, IO per second 510 ThrottleReadIOPSDevice map[string]spec.LinuxThrottleDevice `json:"throttleReadIOPSDevice,omitempty"` 511 // IO write rate limit per cgroup per device, IO per second 512 ThrottleWriteIOPSDevice map[string]spec.LinuxThrottleDevice `json:"throttleWriteIOPSDevice,omitempty"` 513 // CgroupConf are key-value options passed into the container runtime 514 // that are used to configure cgroup v2. 515 // Optional. 516 CgroupConf map[string]string `json:"unified,omitempty"` 517 // CPU period of the cpuset, determined by --cpus 518 CPUPeriod uint64 `json:"cpu_period,omitempty"` 519 // CPU quota of the cpuset, determined by --cpus 520 CPUQuota int64 `json:"cpu_quota,omitempty"` 521 } 522 523 // ContainerHealthCheckConfig describes a container healthcheck with attributes 524 // like command, retries, interval, start period, and timeout. 525 type ContainerHealthCheckConfig struct { 526 HealthConfig *manifest.Schema2HealthConfig `json:"healthconfig,omitempty"` 527 } 528 529 // SpecGenerator creates an OCI spec and Libpod configuration options to create 530 // a container based on the given configuration. 531 // swagger:model SpecGenerator 532 type SpecGenerator struct { 533 ContainerBasicConfig 534 ContainerStorageConfig 535 ContainerSecurityConfig 536 ContainerCgroupConfig 537 ContainerNetworkConfig 538 ContainerResourceConfig 539 ContainerHealthCheckConfig 540 541 image *libimage.Image `json:"-"` 542 resolvedImageName string `json:"-"` 543 } 544 545 // SetImage sets the associated for the generator. 546 func (s *SpecGenerator) SetImage(image *libimage.Image, resolvedImageName string) { 547 s.image = image 548 s.resolvedImageName = resolvedImageName 549 } 550 551 // Image returns the associated image for the generator. 552 // May be nil if no image has been set yet. 553 func (s *SpecGenerator) GetImage() (*libimage.Image, string) { 554 return s.image, s.resolvedImageName 555 } 556 557 type Secret struct { 558 Source string 559 Target string 560 UID uint32 561 GID uint32 562 Mode uint32 563 } 564 565 var ( 566 // ErrNoStaticIPRootless is used when a rootless user requests to assign a static IP address 567 // to a pod or container 568 ErrNoStaticIPRootless error = errors.New("rootless containers and pods cannot be assigned static IP addresses") 569 // ErrNoStaticMACRootless is used when a rootless user requests to assign a static MAC address 570 // to a pod or container 571 ErrNoStaticMACRootless error = errors.New("rootless containers and pods cannot be assigned static MAC addresses") 572 ) 573 574 // NewSpecGenerator returns a SpecGenerator struct given one of two mandatory inputs 575 func NewSpecGenerator(arg string, rootfs bool) *SpecGenerator { 576 csc := ContainerStorageConfig{} 577 if rootfs { 578 csc.Rootfs = arg 579 // check if rootfs should use overlay 580 lastColonIndex := strings.LastIndex(csc.Rootfs, ":") 581 if lastColonIndex != -1 && lastColonIndex+1 < len(csc.Rootfs) && csc.Rootfs[lastColonIndex+1:] == "O" { 582 csc.RootfsOverlay = true 583 csc.Rootfs = csc.Rootfs[:lastColonIndex] 584 } 585 } else { 586 csc.Image = arg 587 } 588 return &SpecGenerator{ 589 ContainerStorageConfig: csc, 590 } 591 } 592 593 // NewSpecGenerator returns a SpecGenerator struct given one of two mandatory inputs 594 func NewSpecGeneratorWithRootfs(rootfs string) *SpecGenerator { 595 csc := ContainerStorageConfig{Rootfs: rootfs} 596 return &SpecGenerator{ContainerStorageConfig: csc} 597 }