Skip to content
Snippets Groups Projects
Commit 96c26afb authored by kaiyou's avatar kaiyou
Browse files

Add some useful logging

parent 3bc8f9f7
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,10 @@ func (c *Config) Complete() error {
for _, mount := range cluster.RequiredMounts(&c.Cluster, &c.Node) {
c.Container.Mounts[mount] = path.Join(c.Container.Data, mount)
}
// Set the container IP mask if required
if len(c.Container.IP.Mask) == 0 {
c.Container.IP.Mask = c.Container.IP.IP.DefaultMask()
}
// Additional container settings
c.Container.Name = c.Node.Name
c.Container.Capabilities = additionalCapabilities
......@@ -71,7 +75,7 @@ func init() {
// Container settings
Hepto.Flags().StringVar(&config.Container.Master, "iface", "eth0", "Master network interface")
Hepto.Flags().IPNetVar(&config.Container.IP, "ip", net.IPNet{}, "IP address for the public interface")
Hepto.Flags().IPVar(&config.Container.IP.IP, "ip", net.IP{}, "IP address for the public interface")
Hepto.Flags().IPVar(&config.Container.GW, "gw", net.IP{}, "IP address of the network gateway")
Hepto.Flags().IPSliceVar(&config.Container.DNS, "dns", defaultDNS, "DNS server IP addresses")
Hepto.Flags().StringToStringVar(&config.Container.Mounts, "bind", map[string]string{}, "Additional bind mounts")
......
......@@ -47,7 +47,7 @@ func waitForIP() net.IP {
time.Sleep(time.Second)
target := fmt.Sprintf("[%s]:53", config.Container.DNS[0].String())
config.Logger.Info("connecting outbound to guess IP", "target", target)
conn, err := net.Dial("udp", fmt.Sprintf("[%s]:53", target))
conn, err := net.Dial("udp", target)
if err != nil {
config.Logger.Error(err, "could not connect")
continue
......
package selfcontain
import (
"errors"
"fmt"
"io/ioutil"
"net"
......@@ -24,47 +23,47 @@ const ACCEPT_DFTRTR = "net.ipv6.conf.eth0.accept_ra_defrtr"
func (c *Container) SetupNetworking(etc string) error {
ifaceName, err := c.setupIPVlan(c.config.Master, 1500)
if err != nil {
return err
return fmt.Errorf("could not create interface: %w", err)
}
netns, err := c.findNetNS()
if err != nil {
return err
return fmt.Errorf("unable to find netns: %w", err)
}
err = netns.Do(func(_ ns.NetNS) error {
// Rename the interface
iface, err := netlink.LinkByName(ifaceName)
if err != nil {
return err
return fmt.Errorf("could not find interface: %w", err)
}
err = netlink.LinkSetName(iface, "eth0")
if err != nil {
return err
return fmt.Errorf("could not rename: %w", err)
}
err = netlink.LinkSetUp(iface)
if err != nil {
return err
return fmt.Errorf("could not set the interface up: %w", err)
}
// Setup addresses and routes
err = setupAddress(iface, c.config.IP)
if err != nil {
return err
return fmt.Errorf("could not set the address: %w", err)
}
err = setupGw(iface, c.config.GW)
if err != nil {
return err
return fmt.Errorf("could not set the gateway: %w", err)
}
// Setup DNS
err = setupDNS(c.config.DNS, etc)
if err != nil {
return err
return fmt.Errorf("could not set the DNS: %w", err)
}
err = setupHosts(etc)
if err != nil {
return err
return fmt.Errorf("could not write hosts file: %w", err)
}
err = setupCerts(etc)
if err != nil {
return err
return fmt.Errorf("could not set certificates: %w", err)
}
return nil
})
......@@ -203,5 +202,5 @@ func setupCerts(etc string) error {
}
return nil
}
return errors.New("no certificate available")
return fmt.Errorf("no certificate available")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment