diff --git a/clab/config.go b/clab/config.go index 36770007f..034522cc6 100644 --- a/clab/config.go +++ b/clab/config.go @@ -537,7 +537,7 @@ func (c *CLab) verifyVirtSupport() error { return err } - return fmt.Errorf("virtualization seems to be not supported and it is required by vrnetlab routers. Check if virtualization can been enabled") + return fmt.Errorf("virtualization seems to be not supported and it is required for VM based nodes. Check if virtualization can be enabled") } // checkEndpoint runs checks on the endpoint syntax diff --git a/cmd/deploy.go b/cmd/deploy.go index 039790b6e..aaa8d4e51 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -128,10 +128,29 @@ var deployCmd = &cobra.Command{ // a set of workers that do not support concurrency serialNodes := make(map[string]struct{}) + + // extraHosts holds host entries for nodes with static IPv4/6 addresses + // these entries will be used by container runtime to populate /etc/hosts file + extraHosts := make([]string, 0, len(c.Nodes)) + for _, n := range c.Nodes { if n.GetRuntime().GetName() == runtime.IgniteRuntime { serialNodes[n.Config().LongName] = struct{}{} } + + if n.Config().MgmtIPv4Address != "" { + log.Debugf("Adding static ipv4 /etc/hosts entry for %s:%s", n.Config().ShortName, n.Config().MgmtIPv4Address) + extraHosts = append(extraHosts, n.Config().ShortName+":"+n.Config().MgmtIPv4Address) + } + + if n.Config().MgmtIPv6Address != "" { + log.Debugf("Adding static ipv6 /etc/hosts entry for %s:%s", n.Config().ShortName, n.Config().MgmtIPv6Address) + extraHosts = append(extraHosts, n.Config().ShortName+":"+n.Config().MgmtIPv6Address) + } + } + + for _, n := range c.Nodes { + n.Config().ExtraHosts = extraHosts } nodesStaticWg, nodesDynWg := c.CreateNodes(ctx, nodeWorkers, serialNodes) @@ -153,7 +172,7 @@ var deployCmd = &cobra.Command{ } log.Debug("enriching nodes with IP information...") - enrichNodes(containers, c.Nodes, c.Config.Mgmt.Network) + enrichNodes(containers, c.Nodes) if err := c.GenerateInventories(); err != nil { return err @@ -226,7 +245,7 @@ func setFlags(conf *clab.Config) { } } -func enrichNodes(containers []types.GenericContainer, nodesMap map[string]nodes.Node, mgmtNet string) { +func enrichNodes(containers []types.GenericContainer, nodesMap map[string]nodes.Node) { for _, c := range containers { name = c.Labels["clab-node-name"] if node, ok := nodesMap[name]; ok { diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index 4e360a4f7..265ac97ee 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -64,7 +64,7 @@ func (c *DockerRuntime) Init(opts ...runtime.RuntimeOption) error { func (c *DockerRuntime) WithKeepMgmtNet() { c.config.KeepMgmtNet = true } -func (c *DockerRuntime) GetName() string { return runtimeName } +func (*DockerRuntime) GetName() string { return runtimeName } func (c *DockerRuntime) Config() runtime.RuntimeConfig { return c.config } func (c *DockerRuntime) WithConfig(cfg *runtime.RuntimeConfig) { @@ -264,6 +264,7 @@ func (c *DockerRuntime) CreateContainer(ctx context.Context, node *types.NodeCon Sysctls: node.Sysctls, Privileged: true, NetworkMode: container.NetworkMode(c.Mgmt.Network), + ExtraHosts: node.ExtraHosts, // add static /etc/hosts entries } containerNetworkingConfig := &network.NetworkingConfig{} @@ -435,7 +436,7 @@ func (c *DockerRuntime) GetContainer(ctx context.Context, containerID string) (* return &ctrs[0], nil } -func (c *DockerRuntime) buildFilterString(gfilters []*types.GenericFilter) filters.Args { +func (*DockerRuntime) buildFilterString(gfilters []*types.GenericFilter) filters.Args { filter := filters.NewArgs() for _, filterentry := range gfilters { filterstring := filterentry.Field @@ -533,8 +534,8 @@ func (c *DockerRuntime) Exec(ctx context.Context, id string, cmd []string) ([]by return outBuf.Bytes(), errBuf.Bytes(), nil } -// ExecNotWait executes cmd on container identified with id but doesn't wait for output nor attaches stodout/err -func (c *DockerRuntime) ExecNotWait(ctx context.Context, id string, cmd []string) error { +// ExecNotWait executes cmd on container identified with id but doesn't wait for output nor attaches stdout/err +func (c *DockerRuntime) ExecNotWait(_ context.Context, id string, cmd []string) error { execConfig := dockerTypes.ExecConfig{Tty: false, AttachStdout: false, AttachStderr: false, Cmd: cmd} respID, err := c.Client.ContainerExecCreate(context.Background(), id, execConfig) if err != nil { diff --git a/types/types.go b/types/types.go index bba04dabc..94b292090 100644 --- a/types/types.go +++ b/types/types.go @@ -92,6 +92,7 @@ type NodeConfig struct { TLSAnchor string NSPath string // network namespace path for this node Publish []string //list of ports to publish with mysocketctl + ExtraHosts []string // Extra /etc/hosts entries for all nodes // container labels Labels map[string]string // Slice of pointers to local endpoints @@ -106,7 +107,7 @@ type NodeConfig struct { } // GenerateConfig generates configuration for the nodes -// out of the templ based on the node configuration and saves the result to dst +// out of the template based on the node configuration and saves the result to dst func (node *NodeConfig) GenerateConfig(dst, templ string) error { // If the config file is already present in the node dir