diff --git a/libnetwork/internal/resolvconf/resolvconf.go b/libnetwork/internal/resolvconf/resolvconf.go index e99a4b85a767d..e9f1122758775 100644 --- a/libnetwork/internal/resolvconf/resolvconf.go +++ b/libnetwork/internal/resolvconf/resolvconf.go @@ -22,13 +22,11 @@ import ( "bufio" "bytes" "context" - _ "embed" "fmt" "io" "io/fs" "net/netip" "os" - "slices" "strconv" "strings" "text/template" @@ -145,7 +143,7 @@ func (rc *ResolvConf) SetHeader(c string) { // NameServers returns addresses used in nameserver directives. func (rc *ResolvConf) NameServers() []netip.Addr { - return slices.Clone(rc.nameServers) + return append([]netip.Addr(nil), rc.nameServers...) } // OverrideNameServers replaces the current set of nameservers. @@ -156,7 +154,7 @@ func (rc *ResolvConf) OverrideNameServers(nameServers []netip.Addr) { // Search returns the current DNS search domains. func (rc *ResolvConf) Search() []string { - return slices.Clone(rc.search) + return append([]string(nil), rc.search...) } // OverrideSearch replaces the current DNS search domains. @@ -173,7 +171,7 @@ func (rc *ResolvConf) OverrideSearch(search []string) { // Options returns the current options. func (rc *ResolvConf) Options() []string { - return slices.Clone(rc.options) + return append([]string(nil), rc.options...) } // Option finds the last option named search, and returns (value, true) if @@ -196,7 +194,7 @@ func (rc *ResolvConf) Option(search string) (string, bool) { // OverrideOptions replaces the current DNS options. func (rc *ResolvConf) OverrideOptions(options []string) { - rc.options = slices.Clone(options) + rc.options = append([]string(nil), options...) rc.md.NDotsFrom = "" if _, exists := rc.Option("ndots"); exists { rc.md.NDotsFrom = "override" @@ -318,7 +316,7 @@ func (rc *ResolvConf) TransformForIntNS( } rc.md.Transform = "internal resolver" - return slices.Clone(rc.md.ExtNameServers), nil + return append([]ExtDNSEntry(nil), rc.md.ExtNameServers...), nil } // Generate returns content suitable for writing to a resolv.conf file. If comments diff --git a/libnetwork/internal/resolvconf/resolvconf_test.go b/libnetwork/internal/resolvconf/resolvconf_test.go index 21605178df8cb..94f4ff09c9eeb 100644 --- a/libnetwork/internal/resolvconf/resolvconf_test.go +++ b/libnetwork/internal/resolvconf/resolvconf_test.go @@ -221,15 +221,15 @@ func TestRCModify(t *testing.T) { rc.OverrideSearch(tc.overrideSearch) rc.OverrideOptions(tc.overrideOptions) - assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateComparable(netip.Addr{}))) - assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch)) - assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions)) + assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateEmpty(), cmpopts.EquateComparable(netip.Addr{}))) + assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch, cmpopts.EquateEmpty())) + assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions, cmpopts.EquateEmpty())) } if tc.addOption != "" { options := rc.Options() rc.AddOption(tc.addOption) - assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption))) + assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption), cmpopts.EquateEmpty())) } d := t.TempDir()