]> go.fuhry.dev Git - runtime.git/commitdiff
machines/coredns_plugin: map interface name + hostname to host ID
authorDan Fuhry <dan@fuhry.com>
Fri, 13 Sep 2024 01:22:07 +0000 (21:22 -0400)
committerDan Fuhry <dan@fuhry.com>
Fri, 13 Sep 2024 01:22:07 +0000 (21:22 -0400)
Will be used soon to support querying by interface name (not complete
yet)

machines/coredns_plugin/registry.go
machines/coredns_plugin/registry_store.go

index 6615023fc77c0dcaee23ecd016726118438914bd..26a0dfcc8298d61362bbe96f6da41a7fa187d431 100644 (file)
@@ -817,6 +817,7 @@ func (r *registry) monitorEvents() {
        for {
                select {
                case event := <-r.eventsCh:
+                       r.log.Noticef("got event with thing=%s, action=%s, tags=<%+v>\n", event.ItemType, event.Event, event.Tags)
                        r.stats.eventsReceived.WithLabelValues(mbclient.KV{"thing": event.ItemType, "action": event.Event}).Add(1)
                        if event.ItemType == "host" && event.Event == "seen" {
                                if via, ok := event.Tags["via"]; !ok || via != "dhcp" {
index a8019aa6e92f7eaa227829a55f912abeb8af116a..9ba83e8d499e91ba2955c7bd2c290fdb001d4539 100644 (file)
@@ -17,13 +17,14 @@ type registryStore struct {
        mu  sync.Mutex `json:"-"`
        log *log.Logger
 
-       Sites     map[string]*machines.Site                      `json:"Sites"`
-       Domains   map[string]*machines.Domain                    `json:"Domains"`
-       Hosts     map[string]*machines.Host                      `json:"Hosts"`
-       Ifaces    map[string]*machines.Iface                     `json:"Ifaces"`
-       Records   map[string]map[recordKey][]*machines.DNSRecord `json:"Records"`
-       HostNames map[string]string                              `json:"-"`
-       Addrs     *machines.RouterAddresses                      `json:"-"`
+       Sites              map[string]*machines.Site                      `json:"Sites"`
+       Domains            map[string]*machines.Domain                    `json:"Domains"`
+       Hosts              map[string]*machines.Host                      `json:"Hosts"`
+       Ifaces             map[string]*machines.Iface                     `json:"Ifaces"`
+       Records            map[string]map[recordKey][]*machines.DNSRecord `json:"Records"`
+       HostNames          map[string]string                              `json:"-"`
+       HostInterfaceNames map[string]string                              `json:"-"`
+       Addrs              *machines.RouterAddresses                      `json:"-"`
 }
 
 type recordKey string
@@ -165,6 +166,7 @@ func (rs *registryStore) fetch(client machines.MachinesClient) error {
        rs.Addrs = ras
 
        rs.HostNames = make(map[string]string)
+       rs.HostInterfaceNames = make(map[string]string)
        rs.Hosts = make(map[string]*machines.Host)
        for _, h := range hosts {
                h.Name = strings.ToLower(h.Name)
@@ -175,6 +177,12 @@ func (rs *registryStore) fetch(client machines.MachinesClient) error {
        rs.Ifaces = make(map[string]*machines.Iface)
        for _, i := range ifaces {
                rs.Ifaces[i.ID()] = i
+               if i.Host.ID() != "" {
+                       if host, ok := rs.Hosts[i.Host.ID()]; ok {
+                               key := fmt.Sprintf("%s.%s", strings.ToLower(i.NameScrubbed), strings.ToLower(host.Name))
+                               rs.HostInterfaceNames[key] = i.ID()
+                       }
+               }
        }
        // loop through again and populate LastSeenIface
        for _, i := range ifaces {