From 6d47e797fa378a04a05382a660ba3783c866cbe9 Mon Sep 17 00:00:00 2001 From: Leonid Kondrashov Date: Fri, 30 Jan 2026 17:03:39 +0800 Subject: [PATCH] Retrieve DNS from k8s only on orchestrator creation Signed-off-by: Leonid Kondrashov --- ctriface/iface.go | 22 +--------------------- ctriface/orch.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ctriface/iface.go b/ctriface/iface.go index 0ac07fefa..62436afeb 100644 --- a/ctriface/iface.go +++ b/ctriface/iface.go @@ -26,9 +26,7 @@ import ( "context" "fmt" "os" - "os/exec" "path/filepath" - "strings" "sync" "syscall" "time" @@ -340,24 +338,6 @@ func (o *Orchestrator) getImage(ctx context.Context, imageName string) (*contain return o.imageManager.GetImage(ctx, imageName, o.snapshotter != "proxy") } -func getK8sDNS() []string { - //using googleDNS as a backup - dnsIPs := []string{"8.8.8.8"} - //get k8s DNS clusterIP - cmd := exec.Command( - "kubectl", "get", "service", "-n", "kube-system", "kube-dns", "-o=custom-columns=:.spec.clusterIP", "--no-headers", - ) - stdoutStderr, err := cmd.CombinedOutput() - if err != nil { - log.Warnf("Failed to Fetch k8s dns clusterIP %v\n%s\n", err, stdoutStderr) - log.Warnf("Using google dns %s\n", dnsIPs[0]) - } else { - //adding k8s DNS clusterIP to the list - dnsIPs = []string{strings.TrimSpace(string(stdoutStderr)), dnsIPs[0]} - } - return dnsIPs -} - func (o *Orchestrator) getVMConfig(vm *misc.VM) *proto.CreateVMRequest { kernelArgs := "ro noapic reboot=k panic=1 pci=off nomodules systemd.log_color=false systemd.unit=firecracker.target init=/sbin/overlay-init tsc=reliable quiet 8250.nr_uarts=0 ipv6.disable=1" @@ -377,7 +357,7 @@ func (o *Orchestrator) getVMConfig(vm *misc.VM) *proto.CreateVMRequest { IPConfig: &proto.IPConfiguration{ PrimaryAddr: vm.GetPrimaryAddr(), GatewayAddr: vm.GetGatewayAddr(), - Nameservers: getK8sDNS(), + Nameservers: o.dns, }, }, }}, diff --git a/ctriface/orch.go b/ctriface/orch.go index b6ec2be04..9f2c38a13 100644 --- a/ctriface/orch.go +++ b/ctriface/orch.go @@ -25,6 +25,7 @@ package ctriface import ( "encoding/json" "os" + "os/exec" "os/signal" "path/filepath" "strings" @@ -104,6 +105,7 @@ type Orchestrator struct { snapshotsDir string isMetricsMode bool netPoolSize int + dns []string vethPrefix string clonePrefix string @@ -123,6 +125,8 @@ func NewOrchestrator(snapshotter, hostIface string, opts ...OrchestratorOption) o.vethPrefix = "172.17" o.clonePrefix = "172.18" + o.dns = getK8sDNS() + for _, opt := range opts { opt(o) } @@ -166,6 +170,24 @@ func NewOrchestrator(snapshotter, hostIface string, opts ...OrchestratorOption) return o } +func getK8sDNS() []string { + //using googleDNS as a backup + dnsIPs := []string{"8.8.8.8"} + //get k8s DNS clusterIP + cmd := exec.Command( + "kubectl", "get", "service", "-n", "kube-system", "kube-dns", "-o=custom-columns=:.spec.clusterIP", "--no-headers", + ) + stdoutStderr, err := cmd.CombinedOutput() + if err != nil { + log.Warnf("Failed to Fetch k8s dns clusterIP %v\n%s\n", err, stdoutStderr) + log.Warnf("Using google dns %s\n", dnsIPs[0]) + } else { + //adding k8s DNS clusterIP to the list + dnsIPs = []string{strings.TrimSpace(string(stdoutStderr)), dnsIPs[0]} + } + return dnsIPs +} + func (o *Orchestrator) setupCloseHandler() { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM)