Skip to content

Commit cace8b8

Browse files
Merge pull request #229 from sharmasushant/fork-master
Use CNI spec to create interface name for container interfaces
2 parents 677d471 + 6c826a7 commit cace8b8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cni/network/network.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
200200
return plugin.Errorf(errMsg)
201201
}
202202

203+
k8sContainerID := args.ContainerID
204+
if len(k8sContainerID) == 0 {
205+
errMsg := "Container ID not specified in CNI Args"
206+
log.Printf(errMsg)
207+
return plugin.Errorf(errMsg)
208+
}
209+
210+
k8sIfName := args.IfName
211+
if len(k8sIfName) == 0 {
212+
errMsg := "Interfacename not specified in CNI Args"
213+
log.Printf(errMsg)
214+
return plugin.Errorf(errMsg)
215+
}
216+
203217
// Parse network configuration from stdin.
204218
nwCfg, err = cni.ParseNetworkConfig(args.StdinData)
205219
if err != nil {
@@ -359,7 +373,9 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
359373
}
360374
epInfo.Data = make(map[string]interface{})
361375

362-
vethName := fmt.Sprintf("%s.%s", k8sNamespace, k8sPodName)
376+
// A runtime must not call ADD twice (without a corresponding DEL) for the same
377+
// (network name, container id, name of the interface inside the container)
378+
vethName := fmt.Sprintf("%s%s%s", networkId, k8sContainerID, k8sIfName)
363379
setEndpointOptions(cnsNetworkConfig, epInfo, vethName)
364380

365381
var dns network.DNSInfo

0 commit comments

Comments
 (0)