mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-30 11:01:12 +02:00
fix(init): use /proc/net/pnp as resolv.conf (#87)
This commit is contained in:
parent
325ae5cbf7
commit
2aed5157fd
@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/pkg/version"
|
||||
)
|
||||
|
||||
@ -24,12 +23,6 @@ ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
`
|
||||
|
||||
const resolvConfTemplate = `
|
||||
{{- range $_, $ip := . -}}
|
||||
nameserver {{ $ip }}
|
||||
{{- end -}}
|
||||
`
|
||||
|
||||
const osReleaseTemplate = `
|
||||
NAME="{{ .Name }}"
|
||||
ID={{ .ID }}
|
||||
@ -67,30 +60,12 @@ func Hosts(s, hostname, ip string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResolvConf renders a valid /etc/resolv.conf file and writes it to disk.
|
||||
func ResolvConf(s string, userdata userdata.UserData) (err error) {
|
||||
tmpl, err := template.New("").Parse(resolvConfTemplate)
|
||||
if err != nil {
|
||||
// ResolvConf symlinks /proc/net/pnp to /etc/resolv.conf. See
|
||||
// https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt.
|
||||
func ResolvConf(s string) (err error) {
|
||||
if err = os.Symlink("/proc/net/pnp", path.Join(s, "/etc/resolv.conf")); err != nil {
|
||||
return
|
||||
}
|
||||
var buf []byte
|
||||
writer := bytes.NewBuffer(buf)
|
||||
ip, err := DefaultGateway()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
nameservers := []string{ip}
|
||||
if userdata.OS.Network != nil {
|
||||
nameservers = append(nameservers, userdata.OS.Network.Nameservers...)
|
||||
}
|
||||
err = tmpl.Execute(writer, nameservers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(path.Join(s, "/etc/resolv.conf"), writer.Bytes(), 0644); err != nil {
|
||||
return fmt.Errorf("write /etc/resolv.conf: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func Prepare(s string, userdata userdata.UserData) (err error) {
|
||||
return
|
||||
}
|
||||
// Create /etc/resolv.conf.
|
||||
if err = etc.ResolvConf(s, userdata); err != nil {
|
||||
if err = etc.ResolvConf(s); err != nil {
|
||||
return
|
||||
}
|
||||
// Create /etc/os-release.
|
||||
|
@ -57,9 +57,7 @@ type OS struct {
|
||||
|
||||
// Network represents the operating system networking specific configuration
|
||||
// options.
|
||||
type Network struct {
|
||||
Nameservers []string `yaml:"nameservers,omitempty"`
|
||||
}
|
||||
type Network struct{}
|
||||
|
||||
// Security represents the operating system security specific configuration
|
||||
// options.
|
||||
|
Loading…
x
Reference in New Issue
Block a user