Skip to content

Commit

Permalink
Merge pull request k8snetworkplumbingwg#250 from Ayush21298/dualstack…
Browse files Browse the repository at this point in the history
…-dev

Add support for dualstack / multiple IP ranges
  • Loading branch information
dougbtv authored Nov 3, 2022
2 parents bb9db21 + 144a634 commit acddfd5
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 236 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,71 @@ The same applies for the usage of IPv6:
}
```

### Example IPAM config for assigning multiple IP addresses

`ipRanges` field can be used to provide a list of range configurations for assigning multiple IP addresses.

```
{
"cniVersion": "0.3.0",
"name": "whereaboutsexample",
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"ipRanges": [{
"range": "192.168.10.1/24"
}, {
"range": "176.168.10.1/16"
}]
}
}
```

The above can also be used in combination with basic `range` field as below:

```
{
"cniVersion": "0.3.0",
"name": "whereaboutsexample",
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"ipRanges": [{
"range": "192.168.10.1/24"
}, {
"range": "176.168.10.1/16"
}],
"range": "abcd::1/64"
}
}
```

### Example DualStack config

Similar to above, `ipRanges` can be used for configuring DualStack

```
{
"cniVersion": "0.3.0",
"name": "whereaboutsexample",
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"ipRanges": [{
"range": "192.168.10.1/24"
}, {
"range": "abcd::1/64"
}]
}
}
```

## Core Parameters

**Required**
Expand Down
26 changes: 14 additions & 12 deletions cmd/whereabouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,31 @@ func cmdAdd(args *skel.CmdArgs, client *kubernetes.KubernetesIPAM, cniVersion st
result.Routes = client.Config.Routes

logging.Debugf("Beginning IPAM for ContainerID: %v", args.ContainerID)
var newip net.IPNet
var newips []net.IPNet

ctx, cancel := context.WithTimeout(context.Background(), types.AddTimeLimit)
defer cancel()

newip, err := kubernetes.IPManagement(ctx, types.Allocate, client.Config, client)
newips, err := kubernetes.IPManagement(ctx, types.Allocate, client.Config, client)
if err != nil {
logging.Errorf("Error at storage engine: %s", err)
return fmt.Errorf("error at storage engine: %w", err)
}

// Determine if v4 or v6.
var useVersion string
if allocate.IsIPv4(newip.IP) {
useVersion = "4"
} else {
useVersion = "6"
}
for _, newip := range newips {
// Determine if v4 or v6.
if allocate.IsIPv4(newip.IP) {
useVersion = "4"
} else {
useVersion = "6"
}

result.IPs = append(result.IPs, &current.IPConfig{
Version: useVersion,
Address: newip,
Gateway: client.Config.Gateway})
result.IPs = append(result.IPs, &current.IPConfig{
Version: useVersion,
Address: newip,
Gateway: client.Config.Gateway})
}

// Assign all the static IP elements.
for _, v := range client.Config.Addresses {
Expand Down
Loading

0 comments on commit acddfd5

Please sign in to comment.