Andrew Rynhard 0bdaff1a90 feat: perform upgrades via container
This moves to performing upgrades via a container.

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
2019-08-27 09:44:50 -07:00

86 lines
2.1 KiB
Go

/* 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 main
import (
"log"
"github.com/talos-systems/talos/internal/app/networkd/pkg/networkd"
"github.com/talos-systems/talos/internal/app/networkd/pkg/nic"
"github.com/talos-systems/talos/internal/app/networkd/pkg/reg"
"github.com/talos-systems/talos/pkg/constants"
"github.com/talos-systems/talos/pkg/grpc/factory"
"github.com/talos-systems/talos/pkg/userdata"
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime)
}
func main() {
var (
netconf networkd.NetConf
ud *userdata.UserData
)
nwd, err := networkd.New()
if err != nil {
log.Fatal(err)
}
// Convert links to nic
log.Println("discovering local network interfaces")
netconf, err = nwd.Discover()
if err != nil {
log.Fatal(err)
}
// Load up userdata
ud, err = userdata.Open(constants.UserDataPath)
if err != nil {
log.Printf("failed to read userdata %s, using defaults: %+v", constants.UserDataPath, err)
}
log.Println("overlaying userdata network configuration")
// Update nic with userdata specified options
if err = netconf.OverlayUserData(ud); err != nil {
log.Fatal(err)
}
// Configure specified interface
netIfaces := make([]*nic.NetworkInterface, 0, len(netconf))
for link, opts := range netconf {
var iface *nic.NetworkInterface
log.Printf("creating interface %s", link.Name)
iface, err = nic.Create(link, opts...)
if err != nil {
log.Fatal(err)
}
netIfaces = append(netIfaces, iface)
}
// kick off the addressing mechanism
// Add any necessary routes
log.Println("configuring interface addressing")
if err = nwd.Configure(netIfaces...); err != nil {
log.Fatal(err)
}
log.Println("interface configuration")
nwd.PrintState()
log.Println("starting renewal watcher")
// handle dhcp renewal
go nwd.Renew(netIfaces...)
log.Fatalf("%+v", factory.ListenAndServe(
reg.NewRegistrator(nwd),
factory.Network("unix"),
factory.SocketPath(constants.NetworkdSocketPath),
),
)
}