summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-10-29 14:46:38 +0100
committerGitHub <noreply@github.com>2019-10-29 14:46:38 +0100
commit815bd568b225710fcc8b425c1d5143b2c8606de1 (patch)
tree2fffce829ce1282e6d635bb102fb1b32c8bbd229 /pkg
parent25f1b1540a700a80904cf0b2862a73da03200bb9 (diff)
parent2f6b8b94e87bb3645d34e59dd3b748dba4aa4d2c (diff)
downloadpodman-815bd568b225710fcc8b425c1d5143b2c8606de1.tar.gz
podman-815bd568b225710fcc8b425c1d5143b2c8606de1.tar.bz2
podman-815bd568b225710fcc8b425c1d5143b2c8606de1.zip
Merge pull request #4187 from baude/dnspluginenable
enable dnsplugin for network create
Diffstat (limited to 'pkg')
-rw-r--r--pkg/adapter/network.go14
-rw-r--r--pkg/network/config.go14
-rw-r--r--pkg/network/netconflist.go21
3 files changed, 44 insertions, 5 deletions
diff --git a/pkg/adapter/network.go b/pkg/adapter/network.go
index d407984ce..9659ae339 100644
--- a/pkg/adapter/network.go
+++ b/pkg/adapter/network.go
@@ -155,15 +155,14 @@ func (r *LocalRuntime) removeNetwork(ctx context.Context, name string, container
// NetworkCreate creates a CNI network
func (r *LocalRuntime) NetworkCreate(cli *cliconfig.NetworkCreateValues) (string, error) {
- var (
- err error
- )
-
isGateway := true
ipMasq := true
subnet := &cli.Network
ipRange := cli.IPRange
-
+ runtimeConfig, err := r.GetConfig()
+ if err != nil {
+ return "", err
+ }
// if range is provided, make sure it is "in" network
if cli.IsSet("subnet") {
// if network is provided, does it conflict with existing CNI or live networks
@@ -245,6 +244,11 @@ func (r *LocalRuntime) NetworkCreate(cli *cliconfig.NetworkCreateValues) (string
plugins = append(plugins, bridge)
plugins = append(plugins, network.NewPortMapPlugin())
plugins = append(plugins, network.NewFirewallPlugin())
+ // if we find the dnsname plugin, we add configuration for it
+ if network.HasDNSNamePlugin(runtimeConfig.CNIPluginDir) && !cli.DisableDNS {
+ // Note: in the future we might like to allow for dynamic domain names
+ plugins = append(plugins, network.NewDNSNamePlugin(network.DefaultPodmanDomainName))
+ }
ncList["plugins"] = plugins
b, err := json.MarshalIndent(ncList, "", " ")
if err != nil {
diff --git a/pkg/network/config.go b/pkg/network/config.go
index 7eaa83833..37eb0dd64 100644
--- a/pkg/network/config.go
+++ b/pkg/network/config.go
@@ -14,6 +14,9 @@ const (
// CNIDeviceName is the default network device name and in
// reality should have an int appended to it (cni-podman4)
CNIDeviceName = "cni-podman"
+ // DefaultPodmanDomainName is used for the dnsname plugin to define
+ // a localized domain name for a created network
+ DefaultPodmanDomainName = "dns.podman"
)
// GetDefaultPodmanNetwork outputs the default network for podman
@@ -97,3 +100,14 @@ type FirewallConfig struct {
func (f FirewallConfig) Bytes() ([]byte, error) {
return json.MarshalIndent(f, "", "\t")
}
+
+// DNSNameConfig describes the dns container name resolution plugin config
+type DNSNameConfig struct {
+ PluginType string `json:"type"`
+ DomainName string `json:"domainName"`
+}
+
+// Bytes outputs the configuration as []byte
+func (d DNSNameConfig) Bytes() ([]byte, error) {
+ return json.MarshalIndent(d, "", "\t")
+}
diff --git a/pkg/network/netconflist.go b/pkg/network/netconflist.go
index c3b11b409..e19051b88 100644
--- a/pkg/network/netconflist.go
+++ b/pkg/network/netconflist.go
@@ -2,6 +2,8 @@ package network
import (
"net"
+ "os"
+ "path/filepath"
)
// NcList describes a generic map
@@ -111,3 +113,22 @@ func NewFirewallPlugin() FirewallConfig {
Backend: "iptables",
}
}
+
+// NewDNSNamePlugin creates the dnsname config with a given
+// domainname
+func NewDNSNamePlugin(domainName string) DNSNameConfig {
+ return DNSNameConfig{
+ PluginType: "dnsname",
+ DomainName: domainName,
+ }
+}
+
+// HasDNSNamePlugin looks to see if the dnsname cni plugin is present
+func HasDNSNamePlugin(paths []string) bool {
+ for _, p := range paths {
+ if _, err := os.Stat(filepath.Join(p, "dnsname")); err == nil {
+ return true
+ }
+ }
+ return false
+}