Skip to content

Commit 288fb68

Browse files
Merge pull request #9237 from mheon/backports_300_RC3
Backports for v3.0,0-RC3
2 parents 9e2cdc4 + c5c946b commit 288fb68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1242
-468
lines changed

RELEASE_NOTES.md

Lines changed: 161 additions & 198 deletions
Large diffs are not rendered by default.

cmd/podman/common/completion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ func AutocompleteNetworkFlag(cmd *cobra.Command, args []string, toComplete strin
817817
"allow_host_loopback=": getBoolCompletion,
818818
"cidr=": nil,
819819
"enable_ipv6=": getBoolCompletion,
820+
"mtu=": nil,
820821
"outbound_addr=": nil,
821822
"outbound_addr6=": nil,
822823
"port_handler=": func(_ string) ([]string, cobra.ShellCompDirective) {

cmd/podman/common/volumes.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ func getBindMount(args []string) (spec.Mount, error) {
353353
default:
354354
return newMount, errors.Wrapf(util.ErrBadMntOption, "%s mount option must be 'private' or 'shared'", kv[0])
355355
}
356+
case "consistency":
357+
// Often used on MACs and mistakenly on Linux platforms.
358+
// Since Docker ignores this option so shall we.
359+
continue
356360
default:
357361
return newMount, errors.Wrapf(util.ErrBadMntOption, kv[0])
358362
}
@@ -437,6 +441,10 @@ func getTmpfsMount(args []string) (spec.Mount, error) {
437441
}
438442
newMount.Destination = filepath.Clean(kv[1])
439443
setDest = true
444+
case "consistency":
445+
// Often used on MACs and mistakenly on Linux platforms.
446+
// Since Docker ignores this option so shall we.
447+
continue
440448
default:
441449
return newMount, errors.Wrapf(util.ErrBadMntOption, kv[0])
442450
}
@@ -534,6 +542,10 @@ func getNamedVolume(args []string) (*specgen.NamedVolume, error) {
534542
}
535543
newVolume.Dest = filepath.Clean(kv[1])
536544
setDest = true
545+
case "consistency":
546+
// Often used on MACs and mistakenly on Linux platforms.
547+
// Since Docker ignores this option so shall we.
548+
continue
537549
default:
538550
return nil, errors.Wrapf(util.ErrBadMntOption, kv[0])
539551
}
@@ -581,6 +593,10 @@ func getImageVolume(args []string) (*specgen.ImageVolume, error) {
581593
default:
582594
return nil, errors.Wrapf(util.ErrBadMntOption, "invalid rw value %q", kv[1])
583595
}
596+
case "consistency":
597+
// Often used on MACs and mistakenly on Linux platforms.
598+
// Since Docker ignores this option so shall we.
599+
continue
584600
default:
585601
return nil, errors.Wrapf(util.ErrBadMntOption, kv[0])
586602
}

cmd/podman/pods/create.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -171,33 +171,6 @@ func create(cmd *cobra.Command, args []string) error {
171171
if err != nil {
172172
return err
173173
}
174-
createOptions.Net.Network = specgen.Namespace{}
175-
if cmd.Flag("network").Changed {
176-
netInput, err := cmd.Flags().GetString("network")
177-
if err != nil {
178-
return err
179-
}
180-
parts := strings.SplitN(netInput, ":", 2)
181-
182-
n := specgen.Namespace{}
183-
switch {
184-
case netInput == "bridge":
185-
n.NSMode = specgen.Bridge
186-
case netInput == "host":
187-
n.NSMode = specgen.Host
188-
case netInput == "slirp4netns", strings.HasPrefix(netInput, "slirp4netns:"):
189-
n.NSMode = specgen.Slirp
190-
if len(parts) > 1 {
191-
createOptions.Net.NetworkOptions = make(map[string][]string)
192-
createOptions.Net.NetworkOptions[parts[0]] = strings.Split(parts[1], ",")
193-
}
194-
default:
195-
// Container and NS mode are presently unsupported
196-
n.NSMode = specgen.Bridge
197-
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
198-
}
199-
createOptions.Net.Network = n
200-
}
201174
if len(createOptions.Net.PublishPorts) > 0 {
202175
if !createOptions.Infra {
203176
return errors.Errorf("you must have an infra container to publish port bindings to the host")

docs/source/markdown/podman-create.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ Valid _mode_ values are:
635635
- **private**: create a new namespace for the container (default)
636636
- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options:
637637
- **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false.
638+
- **mtu=MTU**: Specify the MTU to use for this network. (Default is `65520`).
638639
- **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`).
639640
- **enable_ipv6=true|false**: Enable IPv6. Default is false. (Required for `outbound_addr6`).
640641
- **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only).

docs/source/markdown/podman-run.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ Valid _mode_ values are:
671671
- **private**: create a new namespace for the container (default)
672672
- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options:
673673
- **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false.
674+
- **mtu=MTU**: Specify the MTU to use for this network. (Default is `65520`).
674675
- **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`).
675676
- **enable_ipv6=true|false**: Enable IPv6. Default is false. (Required for `outbound_addr6`).
676677
- **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only).

libpod/container.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,18 @@ func networkDisabled(c *Container) (bool, error) {
10731073
return false, nil
10741074
}
10751075

1076+
func (c *Container) HostNetwork() bool {
1077+
if c.config.CreateNetNS || c.config.NetNsCtr != "" {
1078+
return false
1079+
}
1080+
for _, ns := range c.config.Spec.Linux.Namespaces {
1081+
if ns.Type == spec.NetworkNamespace {
1082+
return false
1083+
}
1084+
}
1085+
return true
1086+
}
1087+
10761088
// ContainerState returns containerstate struct
10771089
func (c *Container) ContainerState() (*ContainerState, error) {
10781090
if !c.batched {

libpod/container_internal_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (c *Container) resolveWorkDir() error {
213213
// we need to return the full error.
214214
return errors.Wrapf(err, "error detecting workdir %q on container %s", workdir, c.ID())
215215
}
216+
return nil
216217
}
217218

218219
// Ensure container entrypoint is created (if required).

libpod/kube.go

Lines changed: 119 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
4949
}
5050

5151
extraHost := make([]v1.HostAlias, 0)
52+
hostNetwork := false
5253
if p.HasInfraContainer() {
5354
infraContainer, err := p.getInfraContainer()
5455
if err != nil {
@@ -69,9 +70,9 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
6970
return nil, servicePorts, err
7071
}
7172
servicePorts = containerPortsToServicePorts(ports)
72-
73+
hostNetwork = p.config.InfraContainer.HostNetwork
7374
}
74-
pod, err := p.podWithContainers(allContainers, ports)
75+
pod, err := p.podWithContainers(allContainers, ports, hostNetwork)
7576
if err != nil {
7677
return nil, servicePorts, err
7778
}
@@ -167,13 +168,14 @@ func containersToServicePorts(containers []v1.Container) []v1.ServicePort {
167168
return sps
168169
}
169170

170-
func (p *Pod) podWithContainers(containers []*Container, ports []v1.ContainerPort) (*v1.Pod, error) {
171+
func (p *Pod) podWithContainers(containers []*Container, ports []v1.ContainerPort, hostNetwork bool) (*v1.Pod, error) {
171172
deDupPodVolumes := make(map[string]*v1.Volume)
172173
first := true
173174
podContainers := make([]v1.Container, 0, len(containers))
175+
dnsInfo := v1.PodDNSConfig{}
174176
for _, ctr := range containers {
175177
if !ctr.IsInfra() {
176-
ctr, volumes, err := containerToV1Container(ctr)
178+
ctr, volumes, _, err := containerToV1Container(ctr)
177179
if err != nil {
178180
return nil, err
179181
}
@@ -196,17 +198,33 @@ func (p *Pod) podWithContainers(containers []*Container, ports []v1.ContainerPor
196198
vol := vol
197199
deDupPodVolumes[vol.Name] = &vol
198200
}
201+
} else {
202+
_, _, infraDNS, err := containerToV1Container(ctr)
203+
if err != nil {
204+
return nil, err
205+
}
206+
if infraDNS != nil {
207+
if servers := infraDNS.Nameservers; len(servers) > 0 {
208+
dnsInfo.Nameservers = servers
209+
}
210+
if searches := infraDNS.Searches; len(searches) > 0 {
211+
dnsInfo.Searches = searches
212+
}
213+
if options := infraDNS.Options; len(options) > 0 {
214+
dnsInfo.Options = options
215+
}
216+
}
199217
}
200218
}
201219
podVolumes := make([]v1.Volume, 0, len(deDupPodVolumes))
202220
for _, vol := range deDupPodVolumes {
203221
podVolumes = append(podVolumes, *vol)
204222
}
205223

206-
return addContainersAndVolumesToPodObject(podContainers, podVolumes, p.Name()), nil
224+
return addContainersAndVolumesToPodObject(podContainers, podVolumes, p.Name(), &dnsInfo, hostNetwork), nil
207225
}
208226

209-
func addContainersAndVolumesToPodObject(containers []v1.Container, volumes []v1.Volume, podName string) *v1.Pod {
227+
func addContainersAndVolumesToPodObject(containers []v1.Container, volumes []v1.Volume, podName string, dnsOptions *v1.PodDNSConfig, hostNetwork bool) *v1.Pod {
210228
tm := v12.TypeMeta{
211229
Kind: "Pod",
212230
APIVersion: "v1",
@@ -225,8 +243,12 @@ func addContainersAndVolumesToPodObject(containers []v1.Container, volumes []v1.
225243
CreationTimestamp: v12.Now(),
226244
}
227245
ps := v1.PodSpec{
228-
Containers: containers,
229-
Volumes: volumes,
246+
Containers: containers,
247+
Volumes: volumes,
248+
HostNetwork: hostNetwork,
249+
}
250+
if dnsOptions != nil {
251+
ps.DNSConfig = dnsOptions
230252
}
231253
p := v1.Pod{
232254
TypeMeta: tm,
@@ -241,75 +263,111 @@ func addContainersAndVolumesToPodObject(containers []v1.Container, volumes []v1.
241263
func simplePodWithV1Containers(ctrs []*Container) (*v1.Pod, error) {
242264
kubeCtrs := make([]v1.Container, 0, len(ctrs))
243265
kubeVolumes := make([]v1.Volume, 0)
266+
hostNetwork := true
267+
podDNS := v1.PodDNSConfig{}
244268
for _, ctr := range ctrs {
245-
kubeCtr, kubeVols, err := containerToV1Container(ctr)
269+
if !ctr.HostNetwork() {
270+
hostNetwork = false
271+
}
272+
kubeCtr, kubeVols, ctrDNS, err := containerToV1Container(ctr)
246273
if err != nil {
247274
return nil, err
248275
}
249276
kubeCtrs = append(kubeCtrs, kubeCtr)
250277
kubeVolumes = append(kubeVolumes, kubeVols...)
251-
}
252-
return addContainersAndVolumesToPodObject(kubeCtrs, kubeVolumes, strings.ReplaceAll(ctrs[0].Name(), "_", "")), nil
253278

279+
// Combine DNS information in sum'd structure
280+
if ctrDNS != nil {
281+
// nameservers
282+
if servers := ctrDNS.Nameservers; servers != nil {
283+
if podDNS.Nameservers == nil {
284+
podDNS.Nameservers = make([]string, 0)
285+
}
286+
for _, s := range servers {
287+
if !util.StringInSlice(s, podDNS.Nameservers) { // only append if it does not exist
288+
podDNS.Nameservers = append(podDNS.Nameservers, s)
289+
}
290+
}
291+
}
292+
// search domains
293+
if domains := ctrDNS.Searches; domains != nil {
294+
if podDNS.Searches == nil {
295+
podDNS.Searches = make([]string, 0)
296+
}
297+
for _, d := range domains {
298+
if !util.StringInSlice(d, podDNS.Searches) { // only append if it does not exist
299+
podDNS.Searches = append(podDNS.Searches, d)
300+
}
301+
}
302+
}
303+
// dns options
304+
if options := ctrDNS.Options; options != nil {
305+
if podDNS.Options == nil {
306+
podDNS.Options = make([]v1.PodDNSConfigOption, 0)
307+
}
308+
podDNS.Options = append(podDNS.Options, options...)
309+
}
310+
} // end if ctrDNS
311+
}
312+
return addContainersAndVolumesToPodObject(kubeCtrs, kubeVolumes, strings.ReplaceAll(ctrs[0].Name(), "_", ""), &podDNS, hostNetwork), nil
254313
}
255314

256315
// containerToV1Container converts information we know about a libpod container
257316
// to a V1.Container specification.
258-
func containerToV1Container(c *Container) (v1.Container, []v1.Volume, error) {
317+
func containerToV1Container(c *Container) (v1.Container, []v1.Volume, *v1.PodDNSConfig, error) {
259318
kubeContainer := v1.Container{}
260319
kubeVolumes := []v1.Volume{}
261320
kubeSec, err := generateKubeSecurityContext(c)
262321
if err != nil {
263-
return kubeContainer, kubeVolumes, err
322+
return kubeContainer, kubeVolumes, nil, err
264323
}
265324

266325
if len(c.config.Spec.Linux.Devices) > 0 {
267326
// TODO Enable when we can support devices and their names
268327
kubeContainer.VolumeDevices = generateKubeVolumeDeviceFromLinuxDevice(c.Spec().Linux.Devices)
269-
return kubeContainer, kubeVolumes, errors.Wrapf(define.ErrNotImplemented, "linux devices")
328+
return kubeContainer, kubeVolumes, nil, errors.Wrapf(define.ErrNotImplemented, "linux devices")
270329
}
271330

272331
if len(c.config.UserVolumes) > 0 {
273332
// TODO When we until we can resolve what the volume name should be, this is disabled
274333
// Volume names need to be coordinated "globally" in the kube files.
275334
volumeMounts, volumes, err := libpodMountsToKubeVolumeMounts(c)
276335
if err != nil {
277-
return kubeContainer, kubeVolumes, err
336+
return kubeContainer, kubeVolumes, nil, err
278337
}
279338
kubeContainer.VolumeMounts = volumeMounts
280339
kubeVolumes = append(kubeVolumes, volumes...)
281340
}
282341

283342
envVariables, err := libpodEnvVarsToKubeEnvVars(c.config.Spec.Process.Env)
284343
if err != nil {
285-
return kubeContainer, kubeVolumes, err
344+
return kubeContainer, kubeVolumes, nil, err
286345
}
287346

288347
portmappings, err := c.PortMappings()
289348
if err != nil {
290-
return kubeContainer, kubeVolumes, err
349+
return kubeContainer, kubeVolumes, nil, err
291350
}
292351
ports, err := ocicniPortMappingToContainerPort(portmappings)
293352
if err != nil {
294-
return kubeContainer, kubeVolumes, err
353+
return kubeContainer, kubeVolumes, nil, err
295354
}
296355

297-
containerCommands := c.Command()
298-
kubeContainer.Name = removeUnderscores(c.Name())
356+
// Handle command and arguments.
357+
if ep := c.Entrypoint(); len(ep) > 0 {
358+
// If we have an entrypoint, set the container's command as
359+
// arguments.
360+
kubeContainer.Command = ep
361+
kubeContainer.Args = c.Command()
362+
} else {
363+
kubeContainer.Command = c.Command()
364+
}
299365

366+
kubeContainer.Name = removeUnderscores(c.Name())
300367
_, image := c.Image()
301368
kubeContainer.Image = image
302369
kubeContainer.Stdin = c.Stdin()
303370

304-
// prepend the entrypoint of the container to command
305-
if ep := c.Entrypoint(); len(c.Entrypoint()) > 0 {
306-
ep = append(ep, containerCommands...)
307-
containerCommands = ep
308-
}
309-
kubeContainer.Command = containerCommands
310-
// TODO need to figure out how we handle command vs entry point. Kube appears to prefer entrypoint.
311-
// right now we just take the container's command
312-
//container.Args = args
313371
kubeContainer.WorkingDir = c.WorkingDir()
314372
kubeContainer.Ports = ports
315373
// This should not be applicable
@@ -355,7 +413,38 @@ func containerToV1Container(c *Container) (v1.Container, []v1.Volume, error) {
355413
}
356414
}
357415

358-
return kubeContainer, kubeVolumes, nil
416+
// Obtain the DNS entries from the container
417+
dns := v1.PodDNSConfig{}
418+
419+
// DNS servers
420+
if servers := c.config.DNSServer; len(servers) > 0 {
421+
dnsServers := make([]string, 0)
422+
for _, server := range servers {
423+
dnsServers = append(dnsServers, server.String())
424+
}
425+
dns.Nameservers = dnsServers
426+
}
427+
428+
// DNS search domains
429+
if searches := c.config.DNSSearch; len(searches) > 0 {
430+
dns.Searches = searches
431+
}
432+
433+
// DNS options
434+
if options := c.config.DNSOption; len(options) > 0 {
435+
dnsOptions := make([]v1.PodDNSConfigOption, 0)
436+
for _, option := range options {
437+
// the option can be "k:v" or just "k", no delimiter is required
438+
opts := strings.SplitN(option, ":", 2)
439+
dnsOpt := v1.PodDNSConfigOption{
440+
Name: opts[0],
441+
Value: &opts[1],
442+
}
443+
dnsOptions = append(dnsOptions, dnsOpt)
444+
}
445+
dns.Options = dnsOptions
446+
}
447+
return kubeContainer, kubeVolumes, &dns, nil
359448
}
360449

361450
// ocicniPortMappingToContainerPort takes an ocicni portmapping and converts

0 commit comments

Comments
 (0)