-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use container DNS when in container mode
More specifically, pick up `/etc/resolv.conf` contents by default when in container mode, and use that as a base resolver for the host DNS. Fixes #8303 Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
- Loading branch information
Showing
36 changed files
with
327 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
internal/app/machined/pkg/runtime/v1alpha1/platform/container/internal/files/hostname.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
// Package files provides internal methods to container platform to read files. | ||
package files | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
|
||
"github.com/siderolabs/talos/pkg/machinery/resources/network" | ||
) | ||
|
||
// ReadHostname reads and parses /etc/hostname file. | ||
func ReadHostname(path string) (network.HostnameSpecSpec, error) { | ||
hostname, err := os.ReadFile(path) | ||
if err != nil { | ||
return network.HostnameSpecSpec{}, err | ||
} | ||
|
||
hostname = bytes.TrimSpace(hostname) | ||
|
||
hostnameSpec := network.HostnameSpecSpec{ | ||
ConfigLayer: network.ConfigPlatform, | ||
} | ||
|
||
if err = hostnameSpec.ParseFQDN(string(hostname)); err != nil { | ||
return network.HostnameSpecSpec{}, err | ||
} | ||
|
||
return hostnameSpec, nil | ||
} |
23 changes: 23 additions & 0 deletions
23
...rnal/app/machined/pkg/runtime/v1alpha1/platform/container/internal/files/hostname_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package files_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/container/internal/files" | ||
) | ||
|
||
func TestReadHostname(t *testing.T) { | ||
t.Parallel() | ||
|
||
spec, err := files.ReadHostname("testdata/hostname") | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "foo", spec.Hostname) | ||
require.Equal(t, "example.com", spec.Domainname) | ||
} |
Oops, something went wrong.