mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
Add network options to podman pod create
Enables most of the network-related functionality from `podman run` in `podman pod create`. Custom CNI networks can be specified, host networking is supported, DNS options can be configured. Also enables host networking in `podman play kube`. Fixes #2808 Fixes #3837 Fixes #4432 Fixes #4718 Fixes #4770 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -1784,6 +1784,9 @@ func WithInfraContainerPorts(bindings []ocicni.PortMapping) PodCreateOption {
|
||||
if pod.valid {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot set pod ports as no infra container is being created")
|
||||
}
|
||||
pod.config.InfraContainer.PortBindings = bindings
|
||||
return nil
|
||||
}
|
||||
@ -1796,6 +1799,10 @@ func WithPodStaticIP(ip net.IP) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot set pod static IP as no infra container is being created")
|
||||
}
|
||||
|
||||
if pod.config.InfraContainer.HostNetwork {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot set static IP if host network is specified")
|
||||
}
|
||||
@ -1817,6 +1824,10 @@ func WithPodStaticMAC(mac net.HardwareAddr) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot set pod static MAC as no infra container is being created")
|
||||
}
|
||||
|
||||
if pod.config.InfraContainer.HostNetwork {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot set static MAC if host network is specified")
|
||||
}
|
||||
@ -1839,6 +1850,10 @@ func WithPodUseImageResolvConf() PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod DNS as no infra container is being created")
|
||||
}
|
||||
|
||||
if len(pod.config.InfraContainer.DNSServer) != 0 ||
|
||||
len(pod.config.InfraContainer.DNSSearch) != 0 ||
|
||||
len(pod.config.InfraContainer.DNSOption) != 0 {
|
||||
@ -1858,6 +1873,10 @@ func WithPodDNS(dnsServer []string) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod DNS as no infra container is being created")
|
||||
}
|
||||
|
||||
if pod.config.InfraContainer.UseImageResolvConf {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot add DNS servers if pod will not create /etc/resolv.conf")
|
||||
}
|
||||
@ -1875,6 +1894,10 @@ func WithPodDNSSearch(dnsSearch []string) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod DNS as no infra container is being created")
|
||||
}
|
||||
|
||||
if pod.config.InfraContainer.UseImageResolvConf {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot add DNS search domains if pod will not create /etc/resolv.conf")
|
||||
}
|
||||
@ -1892,6 +1915,10 @@ func WithPodDNSOption(dnsOption []string) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod DNS as no infra container is being created")
|
||||
}
|
||||
|
||||
if pod.config.InfraContainer.UseImageResolvConf {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot add DNS options if pod will not create /etc/resolv.conf")
|
||||
}
|
||||
@ -1910,6 +1937,10 @@ func WithPodUseImageHosts() PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod hosts as no infra container is being created")
|
||||
}
|
||||
|
||||
if len(pod.config.InfraContainer.HostAdd) != 0 {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "not creating /etc/hosts conflicts with adding to the hosts file")
|
||||
}
|
||||
@ -1927,6 +1958,10 @@ func WithPodHosts(hosts []string) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod hosts as no infra container is being created")
|
||||
}
|
||||
|
||||
if pod.config.InfraContainer.UseImageHosts {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot add to /etc/hosts if container is using image hosts")
|
||||
}
|
||||
@ -1944,6 +1979,10 @@ func WithPodNetworks(networks []string) PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod CNI networks as no infra container is being created")
|
||||
}
|
||||
|
||||
if (pod.config.InfraContainer.StaticIP != nil || pod.config.InfraContainer.StaticMAC != nil) &&
|
||||
len(networks) > 1 {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot join more than one CNI network if setting a static IP or MAC address")
|
||||
@ -1966,6 +2005,10 @@ func WithPodHostNetwork() PodCreateOption {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
|
||||
if !pod.config.InfraContainer.HasInfraContainer {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "cannot configure pod host networking as no infra container is being created")
|
||||
}
|
||||
|
||||
if len(pod.config.InfraContainer.PortBindings) > 0 ||
|
||||
pod.config.InfraContainer.StaticIP != nil ||
|
||||
pod.config.InfraContainer.StaticMAC != nil ||
|
||||
|
Reference in New Issue
Block a user