Skip to content

Commit

Permalink
Clean patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jbemmel committed Aug 12, 2021
1 parent 93ae482 commit 7955e4f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
17 changes: 17 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,28 @@ var deployCmd = &cobra.Command{

// a set of workers that do not support concurrency
serialNodes := make(map[string]struct{})
host_entries := make([]string, 0, len(c.Nodes))
for _, n := range c.Nodes {
if n.GetRuntime().GetName() == runtime.IgniteRuntime {
serialNodes[n.Config().LongName] = struct{}{}
// decreasing the num of nodeworkers as they are used for concurrent nodes
nodeWorkers = nodeWorkers - 1
}

// Build a map of nodes with static IPs, add to /etc/hosts
if n.Config().MgmtIPv4Address != "" {
log.Infof("Adding static ipv4 /etc/hosts entry for %s:%s", n.Config().ShortName, n.Config().MgmtIPv4Address )
host_entries = append( host_entries, n.Config().ShortName + ":" + n.Config().MgmtIPv4Address )
}
if n.Config().MgmtIPv6Address != "" {
log.Infof("Adding static ipv6 /etc/hosts entry for %s:%s", n.Config().ShortName, n.Config().MgmtIPv6Address )
host_entries = append( host_entries, n.Config().ShortName + ":" + n.Config().MgmtIPv6Address )
}
}

// populate each node, bit cumbersome
for _, n := range c.Nodes {
n.Config().ExtraHosts = host_entries
}

c.CreateNodes(ctx, nodeWorkers, serialNodes)
Expand Down Expand Up @@ -225,6 +241,7 @@ func setFlags(conf *clab.Config) {
}

func enrichNodes(containers []types.GenericContainer, nodesMap map[string]nodes.Node, mgmtNet string) {

for _, c := range containers {
name = c.Labels["clab-node-name"]
if node, ok := nodesMap[name]; ok {
Expand Down
1 change: 1 addition & 0 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
16 changes: 11 additions & 5 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type NodeConfig struct {
Group string
Kind string
StartupConfig string // path to config template file that is used for startup config generation
ResetConfig bool // Flag to always regenerate from startup-config, even when modified (default:false)
ResStartupConfig string // path to config file that is actually mounted to the container and is a result of templation
Config *ConfigDispatcher
ResConfig string // path to config file that is actually mounted to the container and is a result of templation
Expand All @@ -74,6 +75,8 @@ type NodeConfig struct {
Cmd string
Env map[string]string
Binds []string // Bind mounts strings (src:dest:options)
Agents []string // Paths to YAML files for SRL agent extensions
ExtraHosts []string // Extra /etc/hosts entries for all nodes
PortBindings nat.PortMap // PortBindings define the bindings between the container ports and host ports
PortSet nat.PortSet // PortSet define the ports that should be exposed on a container
// container networking mode. if set to `host` the host networking will be used for this node, else bridged network
Expand Down Expand Up @@ -105,12 +108,15 @@ type NodeConfig struct {
// GenerateConfig generates configuration for the nodes
// out of the templ based on the node configuration and saves the result to dst
func (node *NodeConfig) GenerateConfig(dst, templ string) error {
// if startup config is not set, and the config file is already present in the node dir
// we do not regenerate the config, since we will take what was saved from the previous run
// in other words, the startup config set by a user takes preference and will trigger config generation
if utils.FileExists(dst) && (node.StartupConfig == "") {
log.Debugf("config file '%s' for node '%s' already exists and will not be generated", dst, node.ShortName)

// If the config file is already present in the node dir
// we do not regenerate the config unless ResetConfig is explicitly set
// By default, modifications to each config made by a user are preserved
if utils.FileExists(dst) && (node.StartupConfig == "" || !node.ResetConfig) {
log.Infof("config file '%s' for node '%s' already exists and will not be generated/reset", dst, node.ShortName)
return nil
} else if node.ResetConfig {
log.Infof("Resetting node '%s' to startup-config '%s'", node.ShortName, dst)
}
log.Debugf("generating config for node %s from file %s", node.ShortName, node.StartupConfig)
tpl, err := template.New(filepath.Base(node.StartupConfig)).Parse(templ)
Expand Down

0 comments on commit 7955e4f

Please sign in to comment.