Skip to content

Commit b02110f

Browse files
authored
Dualstack overlay cni (#1925)
1 parent 61aae03 commit b02110f

23 files changed

+1394
-256
lines changed

.pipelines/singletenancy/aks-swift/e2e-step-template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ steps:
111111
112112
- task: AzureCLI@2
113113
inputs:
114-
azureSubscription: "Azure Container Networking - Test"
114+
azureSubscription: $(AZURE_TEST_AGENT_SERVICE_CONNECTION)
115115
scriptLocation: "inlineScript"
116116
scriptType: "bash"
117117
addSpnToEnvironment: true

.pipelines/singletenancy/cilium/cilium-e2e-step-template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ steps:
143143
144144
- task: AzureCLI@2
145145
inputs:
146-
azureSubscription: "Azure Container Networking - Test"
146+
azureSubscription: $(AZURE_TEST_AGENT_SERVICE_CONNECTION)
147147
scriptLocation: "inlineScript"
148148
scriptType: "bash"
149149
addSpnToEnvironment: true

.pipelines/singletenancy/overlay/overlay-e2e-step-template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ steps:
148148
149149
- task: AzureCLI@2
150150
inputs:
151-
azureSubscription: "Azure Container Networking - Test"
151+
azureSubscription: $(AZURE_TEST_AGENT_SERVICE_CONNECTION)
152152
scriptLocation: "inlineScript"
153153
scriptType: "bash"
154154
addSpnToEnvironment: true

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy-tran
6565
CNI_SWIFT_BUILD_DIR = $(BUILD_DIR)/cni-swift
6666
CNI_OVERLAY_BUILD_DIR = $(BUILD_DIR)/cni-overlay
6767
CNI_BAREMETAL_BUILD_DIR = $(BUILD_DIR)/cni-baremetal
68+
CNI_DUALSTACK_BUILD_DIR = $(BUILD_DIR)/cni-dualstack
6869
CNS_BUILD_DIR = $(BUILD_DIR)/cns
6970
NPM_BUILD_DIR = $(BUILD_DIR)/npm
7071
TOOLS_DIR = $(REPO_ROOT)/build/tools
@@ -94,6 +95,7 @@ CNI_MULTITENANCY_TRANSPARENT_VLAN_ARCHIVE_NAME = azure-vnet-cni-multitenancy-tra
9495
CNI_SWIFT_ARCHIVE_NAME = azure-vnet-cni-swift-$(GOOS)-$(GOARCH)-$(CNI_VERSION).$(ARCHIVE_EXT)
9596
CNI_OVERLAY_ARCHIVE_NAME = azure-vnet-cni-overlay-$(GOOS)-$(GOARCH)-$(CNI_VERSION).$(ARCHIVE_EXT)
9697
CNI_BAREMETAL_ARCHIVE_NAME = azure-vnet-cni-baremetal-$(GOOS)-$(GOARCH)-$(CNI_VERSION).$(ARCHIVE_EXT)
98+
CNI_DUALSTACK_ARCHIVE_NAME = azure-vnet-cni-overlay-dualstack-$(GOOS)-$(GOARCH)-$(CNI_VERSION).$(ARCHIVE_EXT)
9799
CNM_ARCHIVE_NAME = azure-vnet-cnm-$(GOOS)-$(GOARCH)-$(ACN_VERSION).$(ARCHIVE_EXT)
98100
CNS_ARCHIVE_NAME = azure-cns-$(GOOS)-$(GOARCH)-$(CNS_VERSION).$(ARCHIVE_EXT)
99101
NPM_ARCHIVE_NAME = azure-npm-$(GOOS)-$(GOARCH)-$(NPM_VERSION).$(ARCHIVE_EXT)
@@ -624,6 +626,12 @@ endif
624626
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_OVERLAY_BUILD_DIR)
625627
cd $(CNI_OVERLAY_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_OVERLAY_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config
626628

629+
$(MKDIR) $(CNI_DUALSTACK_BUILD_DIR)
630+
cp cni/azure-$(GOOS)-swift-overlay-dualstack.conflist $(CNI_DUALSTACK_BUILD_DIR)/10-azure.conflist
631+
cp telemetry/azure-vnet-telemetry.config $(CNI_DUALSTACK_BUILD_DIR)/azure-vnet-telemetry.config
632+
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_DUALSTACK_BUILD_DIR)
633+
cd $(CNI_DUALSTACK_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_DUALSTACK_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config
634+
627635
#baremetal mode is windows only (at least for now)
628636
ifeq ($(GOOS),windows)
629637
$(MKDIR) $(CNI_BAREMETAL_BUILD_DIR)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"cniVersion":"0.3.0",
3+
"name":"azure",
4+
"plugins":[
5+
{
6+
"type":"azure-vnet",
7+
"mode":"transparent",
8+
"ipsToRouteViaHost":["169.254.20.10"],
9+
"ipam":{
10+
"type":"azure-cns",
11+
"mode":"dualStackOverlay"
12+
}
13+
},
14+
{
15+
"type":"portmap",
16+
"capabilities":{
17+
"portMappings":true
18+
},
19+
"snat":true
20+
}
21+
]
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"cniVersion": "0.3.0",
3+
"name": "azure",
4+
"adapterName" : "",
5+
"plugins": [
6+
{
7+
"type": "azure-vnet",
8+
"mode": "bridge",
9+
"bridge": "azure0",
10+
"capabilities": {
11+
"portMappings": true,
12+
"dns": true
13+
},
14+
"ipam": {
15+
"type": "azure-cns",
16+
"mode": "dualStackOverlay"
17+
},
18+
"dns": {
19+
"Nameservers": [
20+
"10.0.0.10",
21+
"168.63.129.16"
22+
],
23+
"Search": [
24+
"svc.cluster.local"
25+
]
26+
},
27+
"AdditionalArgs": [
28+
{
29+
"Name": "EndpointPolicy",
30+
"Value": {
31+
"Type": "OutBoundNAT",
32+
"ExceptionList": [
33+
"10.240.0.0/16",
34+
"10.0.0.0/8"
35+
]
36+
}
37+
},
38+
{
39+
"Name": "EndpointPolicy",
40+
"Value": {
41+
"Type": "ROUTE",
42+
"DestinationPrefix": "10.0.0.0/8",
43+
"NeedEncap": true
44+
}
45+
}
46+
]
47+
}
48+
]
49+
}

cni/network/cnsclient.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
type cnsclient interface {
1010
RequestIPAddress(ctx context.Context, ipconfig cns.IPConfigRequest) (*cns.IPConfigResponse, error)
1111
ReleaseIPAddress(ctx context.Context, ipconfig cns.IPConfigRequest) error
12+
RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) (*cns.IPConfigsResponse, error)
13+
ReleaseIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) error
1214
GetNetworkContainer(ctx context.Context, orchestratorContext []byte) (*cns.GetNetworkContainerResponse, error)
1315
GetAllNetworkContainers(ctx context.Context, orchestratorContext []byte) ([]cns.GetNetworkContainerResponse, error)
1416
}

cni/network/invoker_azure.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
cniTypesCurr "github.com/containernetworking/cni/pkg/types/100"
1919
)
2020

21+
const (
22+
bytesSize4 = 4
23+
bytesSize16 = 16
24+
)
25+
2126
type AzureIPAMInvoker struct {
2227
plugin delegatePlugin
2328
nwInfo *network.NetworkInfo
@@ -122,7 +127,7 @@ func (invoker *AzureIPAMInvoker) deleteIpamState() {
122127
}
123128
}
124129

125-
func (invoker *AzureIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConfig, _ *cniSkel.CmdArgs, options map[string]interface{}) error {
130+
func (invoker *AzureIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConfig, _ *cniSkel.CmdArgs, options map[string]interface{}) error { //nolint
126131
if nwCfg == nil {
127132
return invoker.plugin.Errorf("nil nwCfg passed to CNI ADD, stack: %+v", string(debug.Stack()))
128133
}
@@ -135,25 +140,28 @@ func (invoker *AzureIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkCo
135140
if err := invoker.plugin.DelegateDel(nwCfg.IPAM.Type, nwCfg); err != nil {
136141
return invoker.plugin.Errorf("Attempted to release address with error: %v", err)
137142
}
138-
} else if len(address.IP.To4()) == 4 {
143+
} else if len(address.IP.To4()) == bytesSize4 { //nolint:gocritic
139144
nwCfg.IPAM.Address = address.IP.String()
140-
log.Printf("Releasing ipv4 address :%s pool: %s",
141-
nwCfg.IPAM.Address, nwCfg.IPAM.Subnet)
145+
log.Printf("Releasing ipv4 address :%s pool: %s", nwCfg.IPAM.Address, nwCfg.IPAM.Subnet)
142146
if err := invoker.plugin.DelegateDel(nwCfg.IPAM.Type, nwCfg); err != nil {
143147
log.Printf("Failed to release ipv4 address: %v", err)
144-
return invoker.plugin.Errorf("Failed to release ipv4 address: %v", err)
148+
return invoker.plugin.Errorf("Failed to release ipv4 address: %v with error: ", nwCfg.IPAM.Address, err)
145149
}
146-
} else if len(address.IP.To16()) == 16 {
150+
} else if len(address.IP.To16()) == bytesSize16 {
147151
nwCfgIpv6 := *nwCfg
148152
nwCfgIpv6.IPAM.Environment = common.OptEnvironmentIPv6NodeIpam
149153
nwCfgIpv6.IPAM.Type = ipamV6
150154
nwCfgIpv6.IPAM.Address = address.IP.String()
151155
if len(invoker.nwInfo.Subnets) > 1 {
152-
nwCfgIpv6.IPAM.Subnet = invoker.nwInfo.Subnets[1].Prefix.String()
156+
for _, subnet := range invoker.nwInfo.Subnets {
157+
if subnet.Prefix.IP.To4() == nil {
158+
nwCfgIpv6.IPAM.Subnet = subnet.Prefix.String()
159+
break
160+
}
161+
}
153162
}
154163

155-
log.Printf("Releasing ipv6 address :%s pool: %s",
156-
nwCfgIpv6.IPAM.Address, nwCfgIpv6.IPAM.Subnet)
164+
log.Printf("Releasing ipv6 address :%s pool: %s", nwCfgIpv6.IPAM.Address, nwCfgIpv6.IPAM.Subnet)
157165
if err := invoker.plugin.DelegateDel(nwCfgIpv6.IPAM.Type, &nwCfgIpv6); err != nil {
158166
log.Printf("Failed to release ipv6 address: %v", err)
159167
return invoker.plugin.Errorf("Failed to release ipv6 address: %v", err)

0 commit comments

Comments
 (0)