github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/specgen/podspecgen.go (about) 1 package specgen 2 3 import ( 4 "net" 5 6 "github.com/containers/common/libnetwork/types" 7 storageTypes "github.com/containers/storage/types" 8 spec "github.com/opencontainers/runtime-spec/specs-go" 9 ) 10 11 // PodBasicConfig contains basic configuration options for pods. 12 type PodBasicConfig struct { 13 // Name is the name of the pod. 14 // If not provided, a name will be generated when the pod is created. 15 // Optional. 16 Name string `json:"name,omitempty"` 17 // Hostname is the pod's hostname. If not set, the name of the pod will 18 // be used (if a name was not provided here, the name auto-generated for 19 // the pod will be used). This will be used by the infra container and 20 // all containers in the pod as long as the UTS namespace is shared. 21 // Optional. 22 Hostname string `json:"hostname,omitempty"` 23 // ExitPolicy determines the pod's exit and stop behaviour. 24 ExitPolicy string `json:"exit_policy,omitempty"` 25 // Labels are key-value pairs that are used to add metadata to pods. 26 // Optional. 27 Labels map[string]string `json:"labels,omitempty"` 28 // NoInfra tells the pod not to create an infra container. If this is 29 // done, many networking-related options will become unavailable. 30 // Conflicts with setting any options in PodNetworkConfig, and the 31 // InfraCommand and InfraImages in this struct. 32 // Optional. 33 NoInfra bool `json:"no_infra,omitempty"` 34 // InfraConmonPidFile is a custom path to store the infra container's 35 // conmon PID. 36 InfraConmonPidFile string `json:"infra_conmon_pid_file,omitempty"` 37 // InfraCommand sets the command that will be used to start the infra 38 // container. 39 // If not set, the default set in the Libpod configuration file will be 40 // used. 41 // Conflicts with NoInfra=true. 42 // Optional. 43 InfraCommand []string `json:"infra_command,omitempty"` 44 // InfraImage is the image that will be used for the infra container. 45 // If not set, the default set in the Libpod configuration file will be 46 // used. 47 // Conflicts with NoInfra=true. 48 // Optional. 49 InfraImage string `json:"infra_image,omitempty"` 50 // InfraName is the name that will be used for the infra container. 51 // If not set, the default set in the Libpod configuration file will be 52 // used. 53 // Conflicts with NoInfra=true. 54 // Optional. 55 InfraName string `json:"infra_name,omitempty"` 56 // SharedNamespaces instructs the pod to share a set of namespaces. 57 // Shared namespaces will be joined (by default) by every container 58 // which joins the pod. 59 // If not set and NoInfra is false, the pod will set a default set of 60 // namespaces to share. 61 // Conflicts with NoInfra=true. 62 // Optional. 63 SharedNamespaces []string `json:"shared_namespaces,omitempty"` 64 // PodCreateCommand is the command used to create this pod. 65 // This will be shown in the output of Inspect() on the pod, and may 66 // also be used by some tools that wish to recreate the pod 67 // (e.g. `podman generate systemd --new`). 68 // Optional. 69 // ShareParent determines if all containers in the pod will share the pod's cgroup as the cgroup parent 70 ShareParent *bool `json:"share_parent,omitempty"` 71 PodCreateCommand []string `json:"pod_create_command,omitempty"` 72 // Pid sets the process id namespace of the pod 73 // Optional (defaults to private if unset). This sets the PID namespace of the infra container 74 // This configuration will then be shared with the entire pod if PID namespace sharing is enabled via --share 75 Pid Namespace `json:"pidns,omitempty"` 76 // Userns is used to indicate which kind of Usernamespace to enter. 77 // Any containers created within the pod will inherit the pod's userns settings. 78 // Optional 79 Userns Namespace `json:"userns,omitempty"` 80 // Devices contains user specified Devices to be added to the Pod 81 Devices []string `json:"pod_devices,omitempty"` 82 // Sysctl sets kernel parameters for the pod 83 Sysctl map[string]string `json:"sysctl,omitempty"` 84 } 85 86 // PodNetworkConfig contains networking configuration for a pod. 87 type PodNetworkConfig struct { 88 // NetNS is the configuration to use for the infra container's network 89 // namespace. This network will, by default, be shared with all 90 // containers in the pod. 91 // Cannot be set to FromContainer and FromPod. 92 // Setting this to anything except default conflicts with NoInfra=true. 93 // Defaults to Bridge as root and Slirp as rootless. 94 // Mandatory. 95 NetNS Namespace `json:"netns,omitempty"` 96 // PortMappings is a set of ports to map into the infra container. 97 // As, by default, containers share their network with the infra 98 // container, this will forward the ports to the entire pod. 99 // Only available if NetNS is set to Bridge or Slirp. 100 // Optional. 101 PortMappings []types.PortMapping `json:"portmappings,omitempty"` 102 // Map of networks names to ids the container should join to. 103 // You can request additional settings for each network, you can 104 // set network aliases, static ips, static mac address and the 105 // network interface name for this container on the specific network. 106 // If the map is empty and the bridge network mode is set the container 107 // will be joined to the default network. 108 Networks map[string]types.PerNetworkOptions 109 // CNINetworks is a list of CNI networks to join the container to. 110 // If this list is empty, the default CNI network will be joined 111 // instead. If at least one entry is present, we will not join the 112 // default network (unless it is part of this list). 113 // Only available if NetNS is set to bridge. 114 // Optional. 115 // Deprecated: as of podman 4.0 use "Networks" instead. 116 CNINetworks []string `json:"cni_networks,omitempty"` 117 // NoManageResolvConf indicates that /etc/resolv.conf should not be 118 // managed by the pod. Instead, each container will create and manage a 119 // separate resolv.conf as if they had not joined a pod. 120 // Conflicts with NoInfra=true and DNSServer, DNSSearch, DNSOption. 121 // Optional. 122 NoManageResolvConf bool `json:"no_manage_resolv_conf,omitempty"` 123 // DNSServer is a set of DNS servers that will be used in the infra 124 // container's resolv.conf, which will, by default, be shared with all 125 // containers in the pod. 126 // If not provided, the host's DNS servers will be used, unless the only 127 // server set is a localhost address. As the container cannot connect to 128 // the host's localhost, a default server will instead be set. 129 // Conflicts with NoInfra=true. 130 // Optional. 131 DNSServer []net.IP `json:"dns_server,omitempty"` 132 // DNSSearch is a set of DNS search domains that will be used in the 133 // infra container's resolv.conf, which will, by default, be shared with 134 // all containers in the pod. 135 // If not provided, DNS search domains from the host's resolv.conf will 136 // be used. 137 // Conflicts with NoInfra=true. 138 // Optional. 139 DNSSearch []string `json:"dns_search,omitempty"` 140 // DNSOption is a set of DNS options that will be used in the infra 141 // container's resolv.conf, which will, by default, be shared with all 142 // containers in the pod. 143 // Conflicts with NoInfra=true. 144 // Optional. 145 DNSOption []string `json:"dns_option,omitempty"` 146 // NoManageHosts indicates that /etc/hosts should not be managed by the 147 // pod. Instead, each container will create a separate /etc/hosts as 148 // they would if not in a pod. 149 // Conflicts with HostAdd. 150 NoManageHosts bool `json:"no_manage_hosts,omitempty"` 151 // HostAdd is a set of hosts that will be added to the infra container's 152 // /etc/hosts that will, by default, be shared with all containers in 153 // the pod. 154 // Conflicts with NoInfra=true and NoManageHosts. 155 // Optional. 156 HostAdd []string `json:"hostadd,omitempty"` 157 // NetworkOptions are additional options for each network 158 // Optional. 159 NetworkOptions map[string][]string `json:"network_options,omitempty"` 160 } 161 162 // PodStorageConfig contains all of the storage related options for the pod and its infra container. 163 type PodStorageConfig struct { 164 // Mounts are mounts that will be added to the pod. 165 // These will supersede Image Volumes and VolumesFrom volumes where 166 // there are conflicts. 167 // Optional. 168 Mounts []spec.Mount `json:"mounts,omitempty"` 169 // Volumes are named volumes that will be added to the pod. 170 // These will supersede Image Volumes and VolumesFrom volumes where 171 // there are conflicts. 172 // Optional. 173 Volumes []*NamedVolume `json:"volumes,omitempty"` 174 // Overlay volumes are named volumes that will be added to the pod. 175 // Optional. 176 OverlayVolumes []*OverlayVolume `json:"overlay_volumes,omitempty"` 177 // Image volumes bind-mount a container-image mount into the pod's infra container. 178 // Optional. 179 ImageVolumes []*ImageVolume `json:"image_volumes,omitempty"` 180 // VolumesFrom is a set of containers whose volumes will be added to 181 // this pod. The name or ID of the container must be provided, and 182 // may optionally be followed by a : and then one or more 183 // comma-separated options. Valid options are 'ro', 'rw', and 'z'. 184 // Options will be used for all volumes sourced from the container. 185 VolumesFrom []string `json:"volumes_from,omitempty"` 186 } 187 188 // PodCgroupConfig contains configuration options about a pod's cgroups. 189 // This will be expanded in future updates to pods. 190 type PodCgroupConfig struct { 191 // CgroupParent is the parent for the Cgroup that the pod will create. 192 // This pod cgroup will, in turn, be the default cgroup parent for all 193 // containers in the pod. 194 // Optional. 195 CgroupParent string `json:"cgroup_parent,omitempty"` 196 } 197 198 // PodSpecGenerator describes options to create a pod 199 // swagger:model PodSpecGenerator 200 type PodSpecGenerator struct { 201 PodBasicConfig 202 PodNetworkConfig 203 PodCgroupConfig 204 PodResourceConfig 205 PodStorageConfig 206 PodSecurityConfig 207 InfraContainerSpec *SpecGenerator `json:"-"` 208 209 // The ID of the pod's service container. 210 ServiceContainerID string `json:"serviceContainerID,omitempty"` 211 } 212 213 type PodResourceConfig struct { 214 // ResourceLimits contains linux specific CPU data for the pod 215 ResourceLimits *spec.LinuxResources `json:"resource_limits,omitempty"` 216 // CPU period of the cpuset, determined by --cpus 217 CPUPeriod uint64 `json:"cpu_period,omitempty"` 218 // CPU quota of the cpuset, determined by --cpus 219 CPUQuota int64 `json:"cpu_quota,omitempty"` 220 // ThrottleReadBpsDevice contains the rate at which the devices in the pod can be read from/accessed 221 ThrottleReadBpsDevice map[string]spec.LinuxThrottleDevice `json:"throttleReadBpsDevice,omitempty"` 222 } 223 224 type PodSecurityConfig struct { 225 SecurityOpt []string `json:"security_opt,omitempty"` 226 // IDMappings are UID and GID mappings that will be used by user 227 // namespaces. 228 // Required if UserNS is private. 229 IDMappings *storageTypes.IDMappingOptions `json:"idmappings,omitempty"` 230 } 231 232 // NewPodSpecGenerator creates a new pod spec 233 func NewPodSpecGenerator() *PodSpecGenerator { 234 return &PodSpecGenerator{} 235 }