Skip to content

Commit

Permalink
Write /etc/resolv.conf during export to allow modifying it by third p…
Browse files Browse the repository at this point in the history
…arties
  • Loading branch information
robertvolkmann committed Apr 17, 2024
1 parent 2d3f106 commit 87959ba
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 79 deletions.
21 changes: 0 additions & 21 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/metal-stack/v"
"github.com/spf13/afero"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -140,26 +139,6 @@ func (i *installer) fileExists(filename string) bool {
return !info.IsDir()
}

func (i *installer) writeResolvConf() error {
i.log.Infow("write /etc/resolv.conf")
// Must be written here because during docker build this file is synthetic
// FIXME enable systemd-resolved based approach again once we figured out why it does not work on the firewall
// most probably because the resolved must be running in the internet facing vrf.
// ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
// in ignite this file is a symlink to /proc/net/pnp, to pass integration test, remove this first
err := i.fs.Remove("/etc/resolv.conf")
if err != nil {
i.log.Infow("no /etc/resolv.conf present")
}

// FIXME migrate to dns0.eu resolvers
content := []byte(
`nameserver 8.8.8.8
nameserver 8.8.4.4
`)
return afero.WriteFile(i.fs, "/etc/resolv.conf", content, 0644)
}

func (i *installer) buildCMDLine() string {
i.log.Infow("build kernel cmdline")

Expand Down
53 changes: 0 additions & 53 deletions cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
"gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -206,58 +205,6 @@ func Test_installer_detectFirmware(t *testing.T) {
}
}

func Test_installer_writeResolvConf(t *testing.T) {
tests := []struct {
name string
fsMocks func(fs afero.Fs)
want string
wantErr error
}{
{
name: "resolv.conf gets written",
fsMocks: func(fs afero.Fs) {
require.NoError(t, afero.WriteFile(fs, "/etc/resolv.conf", []byte(""), 0755))
},
want: `nameserver 8.8.8.8
nameserver 8.8.4.4
`,
wantErr: nil,
},
{
name: "resolv.conf gets written, file is not present",
want: `nameserver 8.8.8.8
nameserver 8.8.4.4
`,
wantErr: nil,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
i := &installer{
log: zaptest.NewLogger(t).Sugar(),
fs: afero.NewMemMapFs(),
}

if tt.fsMocks != nil {
tt.fsMocks(i.fs)
}

err := i.writeResolvConf()
if diff := cmp.Diff(tt.wantErr, err, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}

content, err := afero.ReadFile(i.fs, "/etc/resolv.conf")
require.NoError(t, err)

if diff := cmp.Diff(tt.want, string(content)); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
})
}
}

func Test_installer_fixPermissions(t *testing.T) {
tests := []struct {
name string
Expand Down
3 changes: 0 additions & 3 deletions debian/context/etc/systemd/resolved.conf.d/dns.conf

This file was deleted.

2 changes: 0 additions & 2 deletions debian/context/kernel-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ if [ "${ID}" = "ubuntu" ] ; then
/tmp/linux-image* \
/tmp/linux-modules* \
intel-microcode
# Ubuntu still requires it
systemctl enable systemd-resolved
else
echo "Debian - Install kernel"

Expand Down
2 changes: 2 additions & 0 deletions export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ readonly PKG="packages.txt"
mkdir -p "${EXPORT_DIRECTORY}"
cd "${EXPORT_DIRECTORY}"
docker export "$(docker create "${DOCKER_IMAGE}")" > ${TAR}
# set /etc/resolv.conf
tar --file ${TAR} --directory=export --append etc
docker run --rm "${DOCKER_IMAGE}" bash -c "dpkg -l" > ${PKG}
lz4 -f -9 ${TAR} ${LZ4}
rm -f ${TAR}
Expand Down
2 changes: 2 additions & 0 deletions export/etc/resolv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nameserver 8.8.8.8
nameserver 8.8.4.4

0 comments on commit 87959ba

Please sign in to comment.