Skip to content

Commit edd2ae7

Browse files
Support hyper-v and process based containers with cricontainerd (*COW) (#417)
Support hyper-v and process based containers with cricontainerd (*COW)
1 parent e0605e9 commit edd2ae7

39 files changed

+5433
-554
lines changed

Gopkg.lock

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cni/ipam/ipam.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error {
138138
var result *cniTypesCurr.Result
139139
var err error
140140

141-
log.Printf("[cni-ipam] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v}.",
142-
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path)
141+
log.Printf("[cni-ipam] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.",
142+
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData)
143143

144144
defer func() { log.Printf("[cni-ipam] ADD command completed with result:%+v err:%v.", result, err) }()
145145

@@ -259,8 +259,8 @@ func (plugin *ipamPlugin) Get(args *cniSkel.CmdArgs) error {
259259
func (plugin *ipamPlugin) Delete(args *cniSkel.CmdArgs) error {
260260
var err error
261261

262-
log.Printf("[cni-ipam] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v}.",
263-
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path)
262+
log.Printf("[cni-ipam] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.",
263+
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData)
264264

265265
defer func() { log.Printf("[cni-ipam] DEL command completed with err:%v.", err) }()
266266

cni/network/multitenancy.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"errors"
66
"fmt"
77
"net"
8+
"strconv"
9+
"strings"
810

911
"github.com/Azure/azure-container-networking/cni"
1012
"github.com/Azure/azure-container-networking/cns"
@@ -119,13 +121,17 @@ func convertToCniResult(networkConfig *cns.GetNetworkContainerResponse, ifName s
119121
}
120122
}
121123

124+
var sb strings.Builder
125+
sb.WriteString("Adding cnetAddressspace routes ")
122126
for _, ipRouteSubnet := range networkConfig.CnetAddressSpace {
123-
log.Printf("Adding cnetAddressspace routes %v %v", ipRouteSubnet.IPAddress, ipRouteSubnet.PrefixLength)
127+
sb.WriteString(ipRouteSubnet.IPAddress + "/" + strconv.Itoa((int)(ipRouteSubnet.PrefixLength)) + ", ")
124128
routeIPnet := net.IPNet{IP: net.ParseIP(ipRouteSubnet.IPAddress), Mask: net.CIDRMask(int(ipRouteSubnet.PrefixLength), 32)}
125129
gwIP := net.ParseIP(ipconfig.GatewayIPAddress)
126130
result.Routes = append(result.Routes, &cniTypes.Route{Dst: routeIPnet, GW: gwIP})
127131
}
128132

133+
log.Printf(sb.String())
134+
129135
iface := &cniTypesCurr.Interface{Name: ifName}
130136
result.Interfaces = append(result.Interfaces, iface)
131137

cni/network/network.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
193193
nwDNSInfo network.DNSInfo
194194
)
195195

196-
log.Printf("[cni-net] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v}.",
197-
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path)
196+
log.Printf("[cni-net] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.",
197+
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData)
198198

199199
// Parse network configuration from stdin.
200200
nwCfg, err = cni.ParseNetworkConfig(args.StdinData)
@@ -298,7 +298,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
298298
*/
299299
epInfo, _ := plugin.nm.GetEndpointInfo(networkId, endpointId)
300300
if epInfo != nil {
301-
resultConsAdd, errConsAdd := handleConsecutiveAdd(args.ContainerID, endpointId, nwInfo, nwCfg)
301+
resultConsAdd, errConsAdd := handleConsecutiveAdd(args, endpointId, nwInfo, nwCfg)
302302
if errConsAdd != nil {
303303
log.Printf("handleConsecutiveAdd failed with error %v", errConsAdd)
304304
result = resultConsAdd
@@ -390,6 +390,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
390390
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
391391
DNS: nwDNSInfo,
392392
Policies: policies,
393+
NetNs: args.Netns,
393394
}
394395

395396
nwInfo.Options = make(map[string]interface{})
@@ -606,8 +607,8 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
606607
epInfo *network.EndpointInfo
607608
)
608609

609-
log.Printf("[cni-net] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v}.",
610-
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path)
610+
log.Printf("[cni-net] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v, StdinData:%s}.",
611+
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData)
611612

612613
defer func() { log.Printf("[cni-net] DEL command completed with err:%v.", err) }()
613614

cni/network/network_linux.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/Azure/azure-container-networking/log"
1010
"github.com/Azure/azure-container-networking/network"
1111
"github.com/Azure/azure-container-networking/network/policy"
12+
13+
cniSkel "github.com/containernetworking/cni/pkg/skel"
1214
cniTypes "github.com/containernetworking/cni/pkg/types"
1315
cniTypesCurr "github.com/containernetworking/cni/pkg/types/current"
1416
)
@@ -19,7 +21,7 @@ const (
1921
)
2022

2123
// handleConsecutiveAdd is a dummy function for Linux platform.
22-
func handleConsecutiveAdd(containerId, endpointId string, nwInfo *network.NetworkInfo, nwCfg *cni.NetworkConfig) (*cniTypesCurr.Result, error) {
24+
func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *network.NetworkInfo, nwCfg *cni.NetworkConfig) (*cniTypesCurr.Result, error) {
2325
return nil, nil
2426
}
2527

cni/network/network_windows.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/Azure/azure-container-networking/network/policy"
1515
"github.com/Microsoft/hcsshim"
1616

17+
cniSkel "github.com/containernetworking/cni/pkg/skel"
1718
cniTypes "github.com/containernetworking/cni/pkg/types"
1819
cniTypesCurr "github.com/containernetworking/cni/pkg/types/current"
1920
)
@@ -23,15 +24,20 @@ import (
2324
* We can delete this if statement once they fix it.
2425
* Issue link: https://github.com/kubernetes/kubernetes/issues/57253
2526
*/
26-
func handleConsecutiveAdd(containerId, endpointId string, nwInfo *network.NetworkInfo, nwCfg *cni.NetworkConfig) (*cniTypesCurr.Result, error) {
27+
func handleConsecutiveAdd(args *cniSkel.CmdArgs, endpointId string, nwInfo *network.NetworkInfo, nwCfg *cni.NetworkConfig) (*cniTypesCurr.Result, error) {
28+
// Return in case of HNSv2 as consecutive add call doesn't need to be handled
29+
if useHnsV2, err := network.UseHnsV2(args.Netns); useHnsV2 {
30+
return nil, err
31+
}
32+
2733
hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId)
2834
if hnsEndpoint != nil {
2935
log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint)
30-
log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, containerId)
36+
log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, args.ContainerID)
3137

32-
err := hcsshim.HotAttachEndpoint(containerId, hnsEndpoint.Id)
38+
err := hcsshim.HotAttachEndpoint(args.ContainerID, hnsEndpoint.Id)
3339
if err != nil {
34-
log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, containerId, err)
40+
log.Printf("[cni-net] Failed to hot attach shared endpoint[%v] to container [%v], err:%v.", hnsEndpoint.Id, args.ContainerID, err)
3541
return nil, err
3642
}
3743

@@ -184,11 +190,13 @@ func getEndpointDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Resul
184190
epDNS = network.DNSInfo{
185191
Servers: nwCfg.DNS.Nameservers,
186192
Suffix: namespace + "." + strings.Join(nwCfg.DNS.Search, ","),
193+
Options: nwCfg.DNS.Options,
187194
}
188195
} else {
189196
epDNS = network.DNSInfo{
190-
Suffix: result.DNS.Domain,
191197
Servers: result.DNS.Nameservers,
198+
Suffix: result.DNS.Domain,
199+
Options: nwCfg.DNS.Options,
192200
}
193201
}
194202

@@ -220,8 +228,6 @@ func getPoliciesFromRuntimeCfg(nwCfg *cni.NetworkConfig) []policy.Policy {
220228
}
221229

222230
func getCustomDNS(nwCfg *cni.NetworkConfig) network.DNSInfo {
223-
log.Printf("[net] RuntimeConfigs: %+v", nwCfg.RuntimeConfig)
224-
225231
var search string
226232
if len(nwCfg.RuntimeConfig.DNS.Searches) > 0 {
227233
search = strings.Join(nwCfg.RuntimeConfig.DNS.Searches, ",")
@@ -230,5 +236,6 @@ func getCustomDNS(nwCfg *cni.NetworkConfig) network.DNSInfo {
230236
return network.DNSInfo{
231237
Servers: nwCfg.RuntimeConfig.DNS.Servers,
232238
Suffix: search,
239+
Options: nwCfg.RuntimeConfig.DNS.Options,
233240
}
234241
}

network/endpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type endpoint struct {
4040
PODName string `json:",omitempty"`
4141
PODNameSpace string `json:",omitempty"`
4242
InfraVnetAddressSpace string `json:",omitempty"`
43+
NetNs string `json:",omitempty"`
4344
}
4445

4546
// EndpointInfo contains read-only information about an endpoint.
@@ -66,7 +67,7 @@ type EndpointInfo struct {
6667
PODNameSpace string
6768
Data map[string]interface{}
6869
InfraVnetAddressSpace string
69-
SkipHotAttachEp bool
70+
SkipHotAttachEp bool
7071
}
7172

7273
// RouteInfo contains information about an IP route.

0 commit comments

Comments
 (0)