Skip to content
Snippets Groups Projects
Commit 49d860ff authored by baude's avatar baude
Browse files

pass aliases to dns masq


when podman passes us aliases, we need to make sure we pass this onto
the dnsmasq file so container name resolution will honor them.

Signed-off-by: default avatarbaude <bbaude@redhat.com>
parent 5ea68141
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,10 @@ The dnsname plugin can be enabled in the cni network configuration file. ...@@ -27,7 +27,10 @@ The dnsname plugin can be enabled in the cni network configuration file.
}, },
{ {
"type": "dnsname", "type": "dnsname",
"domainName": "foobar.com" "domainName": "foobar.com",
"capabilities": {
"aliases": true
}
} }
] ]
} }
...@@ -43,6 +46,10 @@ Much like the implementation of DNSMasq for libvirt, this plugin will only set u ...@@ -43,6 +46,10 @@ Much like the implementation of DNSMasq for libvirt, this plugin will only set u
interfaces associated with the CNI network. The DNSMasq services are not configured or managed by systemd but rather interfaces associated with the CNI network. The DNSMasq services are not configured or managed by systemd but rather
only by the plugin itself. only by the plugin itself.
## Network aliases
The dnsname plugin is capable of not only adding the container name for DNS resolution but also adding network aliases. These
aliases are also added to the DNSMasq host file.
## Reporting issues ## Reporting issues
If you are using dnsname code compiled directly from github, then reporting bugs and problem to the dnsname github issues tracker If you are using dnsname code compiled directly from github, then reporting bugs and problem to the dnsname github issues tracker
is appropriate. In the case that you are using code compiled and provided by a Linux distribution, you should file the problem is appropriate. In the case that you are using code compiled and provided by a Linux distribution, you should file the problem
......
...@@ -23,14 +23,7 @@ should already exist. ...@@ -23,14 +23,7 @@ should already exist.
## Configure a CNI network for Podman ## Configure a CNI network for Podman
1. Create a new network using `podman network create`. For example, `podman network create foobar` will suffice. 1. Create a new network using `podman network create`. For example, `podman network create foobar` will suffice.
2. Using your favorite editor, edit `/etc/cni/net.d/foobar.conflist` and add the following with the plugins stanza:
```
{
"type": "dnsname",
"domainName": "podman.io"
}
```
The following example [configuration file](example/cni-podman1.conflist) shows a usable example for Podman. The following example [configuration file](example/cni-podman1.conflist) shows a usable example for Podman.
## Example: container name resolution ## Example: container name resolution
......
...@@ -41,7 +41,10 @@ var ( ...@@ -41,7 +41,10 @@ var (
// DNSNameConf represents the cni config with the domain name attribute // DNSNameConf represents the cni config with the domain name attribute
type DNSNameConf struct { type DNSNameConf struct {
types.NetConf types.NetConf
DomainName string `json:"domainName"` DomainName string `json:"domainName"`
RuntimeConfig struct { // The capability arg
Aliases map[string][]string `json:"aliases"`
} `json:"runtimeConfig,omitempty"`
} }
// dnsNameFile describes the plugin's attributes // dnsNameFile describes the plugin's attributes
......
...@@ -87,7 +87,7 @@ func generateDNSMasqConfig(config dnsNameFile) ([]byte, error) { ...@@ -87,7 +87,7 @@ func generateDNSMasqConfig(config dnsNameFile) ([]byte, error) {
} }
// appendToFile appends a new entry to the dnsmasqs hosts file // appendToFile appends a new entry to the dnsmasqs hosts file
func appendToFile(path, podname string, ips []*net.IPNet) error { func appendToFile(path, podname string, aliases []string, ips []*net.IPNet) error {
f, err := openFile(path) f, err := openFile(path)
if err != nil { if err != nil {
return err return err
...@@ -98,7 +98,11 @@ func appendToFile(path, podname string, ips []*net.IPNet) error { ...@@ -98,7 +98,11 @@ func appendToFile(path, podname string, ips []*net.IPNet) error {
} }
}() }()
for _, ip := range ips { for _, ip := range ips {
entry := fmt.Sprintf("%s\t%s\n", ip.IP.String(), podname) entry := fmt.Sprintf("%s\t%s", ip.IP.String(), podname)
for _, alias := range aliases {
entry += fmt.Sprintf(" %s", alias)
}
entry += "\n"
if _, err = f.WriteString(entry); err != nil { if _, err = f.WriteString(entry); err != nil {
return err return err
} }
......
...@@ -57,7 +57,6 @@ func cmdAdd(args *skel.CmdArgs) error { ...@@ -57,7 +57,6 @@ func cmdAdd(args *skel.CmdArgs) error {
if err != nil { if err != nil {
return err return err
} }
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name) dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name)
if err != nil { if err != nil {
return err return err
...@@ -85,7 +84,8 @@ func cmdAdd(args *skel.CmdArgs) error { ...@@ -85,7 +84,8 @@ func cmdAdd(args *skel.CmdArgs) error {
if err := checkForDNSMasqConfFile(dnsNameConf); err != nil { if err := checkForDNSMasqConfFile(dnsNameConf); err != nil {
return err return err
} }
if err := appendToFile(dnsNameConf.AddOnHostsFile, podname, ips); err != nil { aliases := netConf.RuntimeConfig.Aliases[netConf.Name]
if err := appendToFile(dnsNameConf.AddOnHostsFile, podname, aliases, ips); err != nil {
return err return err
} }
// Now we need to HUP // Now we need to HUP
...@@ -231,6 +231,7 @@ func parseConfig(stdin []byte, args string) (*DNSNameConf, *current.Result, stri ...@@ -231,6 +231,7 @@ func parseConfig(stdin []byte, args string) (*DNSNameConf, *current.Result, stri
if err := json.Unmarshal(stdin, &conf); err != nil { if err := json.Unmarshal(stdin, &conf); err != nil {
return nil, nil, "", errors.Wrap(err, "failed to parse network configuration") return nil, nil, "", errors.Wrap(err, "failed to parse network configuration")
} }
// Parse previous result. // Parse previous result.
var result *current.Result var result *current.Result
if conf.RawPrevResult != nil { if conf.RawPrevResult != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment