فهرست منبع

Merge pull request #1995 from fcrisciani/fix-ndots

Fix ndots configuration
Flavio Crisciani 7 سال پیش
والد
کامیت
e8f62679a3
2فایلهای تغییر یافته به همراه28 افزوده شده و 1 حذف شده
  1. 4 1
      libnetwork/sandbox_dns_unix.go
  2. 24 0
      libnetwork/service_common_test.go

+ 4 - 1
libnetwork/sandbox_dns_unix.go

@@ -362,7 +362,7 @@ func (sb *sandbox) rebuildDNS() error {
 dnsOpt:
 	for _, resOpt := range resOptions {
 		if strings.Contains(resOpt, "ndots") {
-			for _, option := range dnsOptionsList {
+			for i, option := range dnsOptionsList {
 				if strings.Contains(option, "ndots") {
 					parts := strings.Split(option, ":")
 					if len(parts) != 2 {
@@ -371,7 +371,10 @@ dnsOpt:
 					if num, err := strconv.Atoi(parts[1]); err != nil {
 						return fmt.Errorf("invalid number for ndots option %v", option)
 					} else if num > 0 {
+						// if the user sets ndots, we mark it as set but we remove the option to guarantee
+						// that into the container land only ndots:0
 						sb.ndotsSet = true
+						dnsOptionsList = append(dnsOptionsList[:i], dnsOptionsList[i+1:]...)
 						break dnsOpt
 					}
 				}

+ 24 - 0
libnetwork/service_common_test.go

@@ -4,6 +4,8 @@ import (
 	"net"
 	"testing"
 
+	"github.com/docker/libnetwork/resolvconf"
+	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 )
 
@@ -43,3 +45,25 @@ func TestCleanupServiceDiscovery(t *testing.T) {
 		t.Fatalf("Service record not cleaned correctly:%v", c.(*controller).svcRecords)
 	}
 }
+
+func TestDNSOptions(t *testing.T) {
+	c, err := New()
+	require.NoError(t, err)
+
+	sb, err := c.(*controller).NewSandbox("cnt1", nil)
+	require.NoError(t, err)
+	defer sb.Delete()
+	sb.(*sandbox).startResolver(false)
+
+	sb.(*sandbox).config.dnsOptionsList = []string{"ndots:5"}
+	err = sb.(*sandbox).setupDNS()
+	require.NoError(t, err)
+	err = sb.(*sandbox).rebuildDNS()
+	require.NoError(t, err)
+
+	currRC, err := resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
+	require.NoError(t, err)
+	dnsOptionsList := resolvconf.GetOptions(currRC.Content)
+	assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
+	assert.Equal(t, "ndots:0", dnsOptionsList[0], "The option must be ndots:0 instead:", dnsOptionsList[0])
+}