Skip to content

Commit

Permalink
fix: use correct default search domain
Browse files Browse the repository at this point in the history
Search domain should be domain name of the hostname, not the FQDN.

Bug introduced in #9844

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Dec 24, 2024
1 parent 82ea44a commit 1d5c6b3
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (ctrl *ResolverConfigController) getDefault(cfg talosconfig.Config, hostnam
return spec
}

spec.SearchDomains = []string{hostnameStatus.FQDN()}
spec.SearchDomains = []string{hostnameStatus.Domainname}

return spec
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/siderolabs/go-pointer"
"github.com/siderolabs/go-procfs/procfs"
"github.com/siderolabs/go-retry/retry"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -107,11 +108,88 @@ func (suite *ResolverConfigSuite) TestDefaults() {
netip.MustParseAddr(constants.DefaultSecondaryResolver),
}, r.TypedSpec().DNSServers,
)
asrt.Empty(r.TypedSpec().SearchDomains)
asrt.Equal(network.ConfigDefault, r.TypedSpec().ConfigLayer)
},
)
}

func (suite *ResolverConfigSuite) TestWithHostnameStatus() {
suite.Require().NoError(suite.runtime.RegisterController(&netctrl.ResolverConfigController{}))

hostnameStatus := network.NewHostnameStatus(network.NamespaceName, network.HostnameID)
hostnameStatus.TypedSpec().Hostname = "foo"
hostnameStatus.TypedSpec().Domainname = "example.org"
suite.Require().NoError(suite.state.Create(suite.ctx, hostnameStatus))

u, err := url.Parse("https://foo:6443")
suite.Require().NoError(err)

cfg := config.NewMachineConfig(
container.NewV1Alpha1(
&v1alpha1.Config{
ConfigVersion: "v1alpha1",
MachineConfig: &v1alpha1.MachineConfig{
MachineNetwork: &v1alpha1.NetworkConfig{},
},
ClusterConfig: &v1alpha1.ClusterConfig{
ControlPlane: &v1alpha1.ControlPlaneConfig{
Endpoint: &v1alpha1.Endpoint{
URL: u,
},
},
},
},
),
)

suite.Require().NoError(suite.state.Create(suite.ctx, cfg))

suite.startRuntime()

suite.assertResolvers(
[]string{
"default/resolvers",
}, func(r *network.ResolverSpec, asrt *assert.Assertions) {
asrt.Equal(
[]netip.Addr{
netip.MustParseAddr(constants.DefaultPrimaryResolver),
netip.MustParseAddr(constants.DefaultSecondaryResolver),
}, r.TypedSpec().DNSServers,
)
asrt.Equal([]string{"example.org"}, r.TypedSpec().SearchDomains)
asrt.Equal(network.ConfigDefault, r.TypedSpec().ConfigLayer)
},
)

// make domain name empty
hostnameStatus.TypedSpec().Domainname = ""
suite.Require().NoError(suite.state.Update(suite.ctx, hostnameStatus))

suite.assertResolvers(
[]string{
"default/resolvers",
}, func(r *network.ResolverSpec, asrt *assert.Assertions) {
asrt.Empty(r.TypedSpec().SearchDomains)
},
)

// bring back domain name, but disable via machine config
hostnameStatus.TypedSpec().Domainname = "example.org"
suite.Require().NoError(suite.state.Update(suite.ctx, hostnameStatus))

cfg.Container().RawV1Alpha1().MachineConfig.MachineNetwork.NetworkDisableSearchDomain = pointer.To(true)
suite.Require().NoError(suite.state.Update(suite.ctx, cfg))

suite.assertResolvers(
[]string{
"default/resolvers",
}, func(r *network.ResolverSpec, asrt *assert.Assertions) {
asrt.Empty(r.TypedSpec().SearchDomains)
},
)
}

func (suite *ResolverConfigSuite) TestCmdline() {
suite.Require().NoError(
suite.runtime.RegisterController(
Expand All @@ -133,6 +211,7 @@ func (suite *ResolverConfigSuite) TestCmdline() {
netip.MustParseAddr("10.0.0.2"),
}, r.TypedSpec().DNSServers,
)
asrt.Empty(r.TypedSpec().SearchDomains)
},
)
}
Expand Down

0 comments on commit 1d5c6b3

Please sign in to comment.