chore(dns-server): implement resolver for service records that watches container changes

This commit is contained in:
Pavel Sviderski
2025-04-30 14:13:48 +10:00
parent db3016fe89
commit 70e9385032
3 changed files with 146 additions and 1 deletions
+18
View File
@@ -3,11 +3,13 @@ package api
import (
"encoding/json"
"fmt"
"net/netip"
"strings"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/go-units"
"github.com/psviderski/uncloud/internal/machine/docker"
)
const (
@@ -90,6 +92,22 @@ func (c *Container) HumanState() (string, error) {
c.State.ExitCode, units.HumanDuration(time.Now().UTC().Sub(finishedAt))), nil
}
// UncloudNetworkIP returns the IP address of the container in the uncloud Docker network.
func (c *Container) UncloudNetworkIP() netip.Addr {
network, ok := c.NetworkSettings.Networks[docker.NetworkName]
if !ok {
// Container is not connected to the uncloud Docker network (could be host network).
return netip.Addr{}
}
ip, err := netip.ParseAddr(network.IPAddress)
if err != nil {
return netip.Addr{}
}
return ip
}
func (c *Container) UnmarshalJSON(data []byte) error {
// A temporary type that's identical to Container but doesn't have the UnmarshalJSON method.
type ContainerAlias Container