aboutsummaryrefslogtreecommitdiff
path: root/libpod/options.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-03-22 14:39:09 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-03-27 10:12:18 -0400
commit72f03f0c2587be4ff3ff9c83d28964cc7c1a135c (patch)
tree25e1824dff64b5069eb4b1fd4e16ebad6185b8b5 /libpod/options.go
parentb20594ea51ba1fb21cb727a8b224415335e04ac7 (diff)
downloadpodman-72f03f0c2587be4ff3ff9c83d28964cc7c1a135c.tar.gz
podman-72f03f0c2587be4ff3ff9c83d28964cc7c1a135c.tar.bz2
podman-72f03f0c2587be4ff3ff9c83d28964cc7c1a135c.zip
Add support to disable creation of network config files
Specifically, we want to be able to specify whether resolv.conf and /etc/hosts will be create and bind-mounted into the container. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/options.go')
-rw-r--r--libpod/options.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 1bf3ff9e6..a36309ed7 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -997,6 +997,9 @@ func WithDNSSearch(searchDomains []string) CtrCreateOption {
if ctr.valid {
return ErrCtrFinalized
}
+ if ctr.config.NoCreateResolvConf {
+ return errors.Wrapf(ErrInvalidArg, "cannot add DNS search domains if container will not create /etc/resolv.conf")
+ }
ctr.config.DNSSearch = searchDomains
return nil
}
@@ -1008,6 +1011,9 @@ func WithDNS(dnsServers []string) CtrCreateOption {
if ctr.valid {
return ErrCtrFinalized
}
+ if ctr.config.NoCreateResolvConf {
+ return errors.Wrapf(ErrInvalidArg, "cannot add DNS servers if container will not create /etc/resolv.conf")
+ }
var dns []net.IP
for _, i := range dnsServers {
result := net.ParseIP(i)
@@ -1027,6 +1033,9 @@ func WithDNSOption(dnsOptions []string) CtrCreateOption {
if ctr.valid {
return ErrCtrFinalized
}
+ if ctr.config.NoCreateResolvConf {
+ return errors.Wrapf(ErrInvalidArg, "cannot add DNS options if container will not create /etc/resolv.conf")
+ }
ctr.config.DNSOption = dnsOptions
return nil
}
@@ -1038,6 +1047,11 @@ func WithHosts(hosts []string) CtrCreateOption {
if ctr.valid {
return ErrCtrFinalized
}
+
+ if ctr.config.NoCreateHosts {
+ return errors.Wrapf(ErrInvalidArg, "cannot add hosts if container will not create /etc/hosts")
+ }
+
ctr.config.HostAdd = hosts
return nil
}
@@ -1184,6 +1198,44 @@ func WithCtrNamespace(ns string) CtrCreateOption {
}
}
+// WithNoCreateResolvConf tells the container not to bind-mount resolv.conf in.
+// This conflicts with other DNS-related options.
+func WithNoCreateResolvConf() CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ if len(ctr.config.DNSServer) != 0 ||
+ len(ctr.config.DNSSearch) != 0 ||
+ len(ctr.config.DNSOption) != 0 {
+ return errors.Wrapf(ErrInvalidArg, "not creating resolv.conf conflicts with DNS options")
+ }
+
+ ctr.config.NoCreateResolvConf = true
+
+ return nil
+ }
+}
+
+// WithNoCreateHosts tells the container not to bind-mount /etc/hosts in.
+// This conflicts with WithHosts().
+func WithNoCreateHosts() CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ if len(ctr.config.HostAdd) != 0 {
+ return errors.Wrapf(ErrInvalidArg, "not creating /etc/hosts conflicts with adding to the hosts file")
+ }
+
+ ctr.config.NoCreateHosts = true
+
+ return nil
+ }
+}
+
// withIsInfra sets the container to be an infra container. This means the container will be sometimes hidden
// and expected to be the first container in the pod.
func withIsInfra() CtrCreateOption {