diff options
author | baude <bbaude@redhat.com> | 2020-11-02 09:49:13 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-11-02 12:08:25 -0600 |
commit | 49d860ffd92e389d8d7ab7f0a6918e48d76a3f2f (patch) | |
tree | d4de3ffb49bbea85dbc1a97fc961a41a2c0fc415 /plugins | |
parent | 5ea68141aea03ba7ffeca44a899a1e7854549bdf (diff) |
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: baude <bbaude@redhat.com>
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/meta/dnsname/config.go | 5 | ||||
-rw-r--r-- | plugins/meta/dnsname/files.go | 8 | ||||
-rw-r--r-- | plugins/meta/dnsname/main.go | 5 |
3 files changed, 13 insertions, 5 deletions
diff --git a/plugins/meta/dnsname/config.go b/plugins/meta/dnsname/config.go index f8fda57..4d1d59d 100644 --- a/plugins/meta/dnsname/config.go +++ b/plugins/meta/dnsname/config.go @@ -41,7 +41,10 @@ var ( // DNSNameConf represents the cni config with the domain name attribute type DNSNameConf struct { 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 diff --git a/plugins/meta/dnsname/files.go b/plugins/meta/dnsname/files.go index 16d7810..5e9a2b4 100644 --- a/plugins/meta/dnsname/files.go +++ b/plugins/meta/dnsname/files.go @@ -87,7 +87,7 @@ func generateDNSMasqConfig(config dnsNameFile) ([]byte, error) { } // 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) if err != nil { return err @@ -98,7 +98,11 @@ func appendToFile(path, podname string, ips []*net.IPNet) error { } }() 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 { return err } diff --git a/plugins/meta/dnsname/main.go b/plugins/meta/dnsname/main.go index 271d495..c81e1dd 100644 --- a/plugins/meta/dnsname/main.go +++ b/plugins/meta/dnsname/main.go @@ -57,7 +57,6 @@ func cmdAdd(args *skel.CmdArgs) error { if err != nil { return err } - dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name) if err != nil { return err @@ -85,7 +84,8 @@ func cmdAdd(args *skel.CmdArgs) error { if err := checkForDNSMasqConfFile(dnsNameConf); err != nil { 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 } // Now we need to HUP @@ -231,6 +231,7 @@ func parseConfig(stdin []byte, args string) (*DNSNameConf, *current.Result, stri if err := json.Unmarshal(stdin, &conf); err != nil { return nil, nil, "", errors.Wrap(err, "failed to parse network configuration") } + // Parse previous result. var result *current.Result if conf.RawPrevResult != nil { |