Skip to content

Commit

Permalink
fix: set proper hostname on docker nodes
Browse files Browse the repository at this point in the history
Before this change, every node had `os.Hostname()` of `talos-127-0-1-1`
which breaks resolving node hostname into the IP address (used in new
controller-runtime to fetch kubelet pod status).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Feb 9, 2021
1 parent a07cfbd commit b526c2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package container

import (
"bytes"
"context"
"encoding/base64"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -44,7 +46,13 @@ func (c *Container) Configuration(context.Context) ([]byte, error) {

// Hostname implements the platform.Platform interface.
func (c *Container) Hostname(context.Context) (hostname []byte, err error) {
return nil, nil
hostname, err = ioutil.ReadFile("/etc/hostname")

if err == nil {
hostname = bytes.TrimSpace(hostname)
}

return
}

// Mode implements the platform.Platform interface.
Expand Down
6 changes: 6 additions & 0 deletions internal/app/machined/pkg/system/services/networkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func (n *Networkd) Runner(r runtime.Runtime) (runner.Runner, error) {
{Type: "bind", Destination: filepath.Dir(constants.NetworkSocketPath), Source: filepath.Dir(constants.NetworkSocketPath), Options: []string{"rbind", "rw"}},
}

if r.State().Platform().Mode() == runtime.ModeContainer {
mounts = append(mounts,
specs.Mount{Type: "bind", Destination: "/etc/hostname", Source: "/etc/hostname", Options: []string{"rbind", "ro"}},
)
}

env := []string{}
for key, val := range r.Config().Machine().Env() {
env = append(env, fmt.Sprintf("%s=%s", key, val))
Expand Down

0 comments on commit b526c2c

Please sign in to comment.