Skip to content

Commit

Permalink
Add network aliases to node (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzagozen authored Oct 31, 2024
1 parent 5e9647b commit 5c25be6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func (c *CLab) createNodeCfg(nodeName string, nodeDef *types.NodeDefinition, idx
DNS: c.Config.Topology.GetNodeDns(nodeName),
Certificate: c.Config.Topology.GetCertificateConfig(nodeName),
Healthcheck: c.Config.Topology.GetHealthCheckConfig(nodeName),
Aliases: c.Config.Topology.GetNodeAliases(nodeName),
}
var err error

Expand Down
14 changes: 14 additions & 0 deletions docs/manual/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,17 @@ When the node is configured with a healthcheck the health status is visible in t

[^1]: [docker runtime resources constraints](https://docs.docker.com/config/containers/resource_constraints/).
[^2]: this deployment model makes two containers to use a shared network namespace, similar to a Kubernetes pod construct.

### aliases

To define additional hostnames for the node use the `aliases` configuration option. Other containers on the same network can use these aliases to communicate with the node.

```yaml
topology:
nodes:
r1:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux
aliases:
- r1.example.com
```
1 change: 1 addition & 0 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ func (d *DockerRuntime) processNetworkMode(
IPv4Address: node.MgmtIPv4Address,
IPv6Address: node.MgmtIPv6Address,
},
Aliases: node.Aliases,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/podman/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (r *PodmanRuntime) createContainerSpec(ctx context.Context, cfg *types.Node
// Static IPs & Macs are properties of a network attachment
nets := map[string]netTypes.PerNetworkOptions{netName: {
StaticIPs: staticIPs,
Aliases: nil,
Aliases: cfg.Aliases,
StaticMAC: hwAddr,
InterfaceName: "",
}}
Expand Down
9 changes: 9 additions & 0 deletions schemas/clab.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@
"healthcheck": {
"type": "object",
"$ref": "#/definitions/healthcheck-config"
},
"aliases": {
"type": "array",
"description": "list of additional network aliases for the node",
"markdownDescription": "list of [aliases](https://containerlab.dev/manual/nodes/#aliases) for the node",
"items": {
"type": "string"
},
"uniqueItems": true
}
},
"allOf": [
Expand Down
2 changes: 2 additions & 0 deletions tests/01-smoke/01-linux-nodes.clab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ topology:
- 56180:80
mgmt-ipv4: 172.20.20.100
mgmt-ipv6: 3fff:172:20:20::100
aliases:
- l2.mydomain.com
dns:
servers:
- 8.8.8.8
Expand Down
9 changes: 9 additions & 0 deletions types/node_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type NodeDefinition struct {
Certificate *CertificateConfig `yaml:"certificate,omitempty"`
// Healthcheck configuration
HealthCheck *HealthcheckConfig `yaml:"healthcheck,omitempty"`
// Network aliases
Aliases []string `yaml:"aliases,omitempty"`
}

// Interface compliance.
Expand Down Expand Up @@ -388,6 +390,13 @@ func (n *NodeDefinition) GetHealthcheckConfig() *HealthcheckConfig {
return n.HealthCheck
}

func (n *NodeDefinition) GetAliases() []string {
if n == nil {
return nil
}
return n.Aliases
}

// ImportEnvs imports all environment variales defined in the shell
// if __IMPORT_ENVS is set to true.
func (n *NodeDefinition) ImportEnvs() {
Expand Down
7 changes: 7 additions & 0 deletions types/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,10 @@ func (t *Topology) GetHealthCheckConfig(name string) *HealthcheckConfig {

return nil
}

func (t *Topology) GetNodeAliases(name string) []string {
if ndef, ok := t.Nodes[name]; ok {
return ndef.GetAliases()
}
return nil
}
2 changes: 2 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ type NodeConfig struct {
Certificate *CertificateConfig
// Healthcheck configuration parameters
Healthcheck *HealthcheckConfig
// Network aliases
Aliases []string `json:"aliases,omitempty"`
// NSPath string `json:"nspath,omitempty"` // network namespace path for this node
// list of ports to publish with mysocketctl
Publish []string `json:"publish,omitempty"`
Expand Down

0 comments on commit 5c25be6

Please sign in to comment.