Skip to content

Commit

Permalink
Allow empty list of nameservers
Browse files Browse the repository at this point in the history
DNS will obviously not find anything, but at least it still spins up
on an offline machine.

Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed Dec 24, 2024
1 parent 87eab7a commit fc1d5ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
6 changes: 0 additions & 6 deletions pkg/services/dns/dns_config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
package dns

import (
"errors"
"net"
"net/netip"

"github.com/miekg/dns"
log "github.com/sirupsen/logrus"
)

var errEmptyResolvConf = errors.New("no DNS servers configured in /etc/resolv.conf")

func getDNSHostAndPort() ([]string, error) {
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
Expand All @@ -31,8 +28,5 @@ func getDNSHostAndPort() ([]string, error) {
}
}

if len(hosts) == 0 {
return []string{}, errEmptyResolvConf
}
return hosts, nil
}
11 changes: 3 additions & 8 deletions pkg/services/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dns

import (
"context"
"errors"
"net"
"testing"
"time"
Expand All @@ -24,11 +23,7 @@ var _ = ginkgo.Describe("dns add test", func() {
var server *Server

ginkgo.BeforeEach(func() {
var err error
server, err = New(nil, nil, []types.Zone{})
if errors.Is(err, errEmptyResolvConf) {
ginkgo.Skip("Skipping test, no DNS Servers found")
}
server, _ = New(nil, nil, []types.Zone{})
})

ginkgo.It("should add dns zone with ip", func() {
Expand Down Expand Up @@ -235,10 +230,10 @@ type ARecord struct {
func TestDNS(t *testing.T) {
log.Infof("starting test DNS servers")
nameserver, cleanup, err := startDNSServer()
if errors.Is(err, errEmptyResolvConf) {
require.NoError(t, err)
if len(nameserver) == 0 {
t.Skip("Failed to setup start DNS server, skipping test")
}
require.NoError(t, err)
defer cleanup()
time.Sleep(100 * time.Millisecond)
log.Infof("test DNS servers started")
Expand Down

0 comments on commit fc1d5ab

Please sign in to comment.