Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample changes for dualstack testing. #108

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type NetworkConfig struct {
Name string `json:"name"` // Name is the Network Name. We would also use this as the Type of HNS Network
Type string `json:"type"` // As per SPEC, Type is Name of the Binary
Ipam IpamConfig `json:"ipam"`
Ipamv6 IpamConfig `json:"ipamv6"`
DNS cniTypes.DNS `json:"dns"`
OptionalFlags OptionalFlags `json:"optionalFlags"`
RuntimeConfig RuntimeConfig `json:"runtimeConfig"`
Expand Down Expand Up @@ -225,6 +226,30 @@ func (config *NetworkConfig) GetNetworkInfo(podNamespace string) (ninfo *network
subnets = append(subnets, subnet)
}

if config.OptionalFlags.EnableDualStack && config.Ipamv6.Subnet != "" {
ip, s, _ := net.ParseCIDR(config.Ipamv6.Subnet)
if ip.To4() == nil && len(ip) == net.IPv6len {
gatewayIP := make(net.IP, len(ip))
copy(gatewayIP, ip)
// Find the first IP in the subnet (usually the gateway)
for i := len(gatewayIP) - 1; i >= 0; i-- {
gatewayIP[i]++
if gatewayIP[i] != 0 {
break
}
}
if config.Ipamv6.Routes != nil && len(config.Ipamv6.Routes) > 0 && config.Ipamv6.Routes[0].GW != nil {
gatewayIP = config.Ipamv6.Routes[0].GW
}
subnet := network.SubnetInfo{
AddressPrefix: *s,
GatewayAddress: gatewayIP,
Policies: []network.Policy{},
}
subnets = append(subnets, subnet)
}
}

if len(config.DNS.Search) > 0 {
if podNamespace != "" {
config.DNS.Search[0] = podNamespace + "." + config.DNS.Search[0]
Expand Down
78 changes: 78 additions & 0 deletions example/cni_dualstack_sample.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"cniVersion": "0.2.0",
"name": "ContainerHostA",
"type": "sdnbridge",
"master": "Ethernet",
"capabilities": {
"portMappings": true,
"dns" : true
},
"ipam": {
"environment": "azure",
"subnet": "192.168.100.0/24",
"routes": [
{
"GW": "192.168.100.2"
}
]
},
"ipamv6": {
"environment": "azure",
"subnet": "10::06/64",
"routes": [
{
"GW": "10::02"
}
]
},
"dns": {
"Nameservers": [
"168.63.129.16"
],
"Search": [
"svc.cluster.local"
]
},
"optionalFlags" : {
"localRoutedPortMapping" : true,
"allowAclPortMapping" : true,
"enableDualStack" : true
},
"AdditionalArgs": [
{
"Name": "EndpointPolicy",
"Value": {
"Type": "OutBoundNAT",
"Settings": {
"Exceptions": [
"192.168.100.0/24",
"192.168.100.2/32"
]
}
}
}
,{
"Name": "EndpointPolicy",
"Value": {
"Type":"ACL",
"Settings": {
"Action": "Allow",
"Direction": "Out",
"Priority": 2000
}
}
}
,{
"Name": "EndpointPolicy",
"Value": {
"Type":"ACL",
"Settings": {
"Action": "Allow",
"Direction": "In",
"Priority": 2000
}
}
}

]
}
14 changes: 13 additions & 1 deletion scripts/autogencniconf/generateCNIConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum WKOptionalKeysFlag {
Ipam = 2 #[WKOptionalKeysFlag]::NoWKOptKeys -shl 1
Dns = 4 #[WKOptionalKeysFlag]::NoWKOptKeys -shl 2
MaxFlags = 8 #[WKOptionalKeysFlag]::NoWKOptKeys -shl 3
Ipamv6 = 16 #[WKOptionalKeysFlag]::NoWKOptKeys -shl 4
}

class Policy {
Expand Down Expand Up @@ -181,7 +182,7 @@ class CniConf {
# Set optional fields to be populated
$this.OptKeyParams = $this.OptKeyParams -bor [OptionalKeysFlag]::Capabilities -bor [OptionalKeysFlag]::Master
# Set wellknown optional fields to be populated
$this.WKOptKeyParams = $this.WKOptKeyParams -bor [WKOptionalKeysFlag]::Dns -bor [WKOptionalKeysFlag]::Ipam
$this.WKOptKeyParams = $this.WKOptKeyParams -bor [WKOptionalKeysFlag]::Dns -bor [WKOptionalKeysFlag]::Ipam -bor [WKOptionalKeysFlag]::Ipamv6
}

EnsureMandatoryParametersPresent([System.Object] $cniArgs) {
Expand Down Expand Up @@ -245,6 +246,17 @@ class CniConf {
$this.CniBase.Add('ipam', $ipamFields)
}

([WKOptionalKeysFlag]::Ipamv6).value__ {
$ipamFields = [System.Collections.Specialized.OrderedDictionary]::new()
$ipamFields.Add('environment', 'azure')
$ipamFields.Add('subnet', $this.Args.Subnet)
$routes = @()
$routes += (@{'GW'=$this.Args.Gateway;})
$ipamFields.Add('routes', $routes)

$this.CniBase.Add('ipamv6', $ipamFields)
}

([WKOptionalKeysFlag]::Dns).value__ {
$dnsFields = [System.Collections.Specialized.OrderedDictionary]::new()
$nameservers = @()
Expand Down
Loading