Skip to content

Commit

Permalink
Reworking interface post-processing to be entirely generic, for all i…
Browse files Browse the repository at this point in the history
…nterfaces.

This enables us to:
- handle ALL activities, in one place, unconditionally
- cleaner code
- finally getting rid of all IPVLAN specific code
- being able to apply post processing even for the dummy interfaces
  • Loading branch information
Levovar committed Oct 7, 2019
1 parent e3d6618 commit ea7604f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 44 deletions.
6 changes: 3 additions & 3 deletions pkg/cnidel/cnidel.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ func DelegateInterfaceSetup(netConf *datastructs.NetConf, danmClient danmclients
//As netInfo is only copied to IPAM above, the IP allocation is not refreshed in the original copy.
//Without re-reading the network body we risk leaking IPs if error happens later on within the same thread!
netInfo,err = netcontrol.GetNetworkFromEp(danmClient, *ep)
if err != nil {log.Println("lofasz:" + err.Error())}
if err != nil {
return nil, err
}
ipamOptions = getCniIpamConfig(netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
}
rawConfig, err := getCniPluginConfig(netConf, netInfo, ipamOptions, ep)
if err != nil {
FreeDelegatedIps(danmClient, netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
return nil, err
}
cniType := netInfo.Spec.NetworkType
cniResult,err := execCniPlugin(cniType, CniAddOp, netInfo, rawConfig, ep)
if err != nil {
FreeDelegatedIps(danmClient, netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
return nil, errors.New("Error delegating ADD to CNI plugin:" + cniType + " because:" + err.Error())
}
if cniResult != nil {
Expand Down
38 changes: 8 additions & 30 deletions pkg/danmep/danmep.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ func DetermineHostDeviceName(dnet *danmtypes.DanmNet) string {
}

func PostProcessInterface(ep danmtypes.DanmEp, dnet *danmtypes.DanmNet) error {
if ep.Spec.Iface.DeviceID == "" &&
len(ep.Spec.Iface.Proutes) == 0 && len(ep.Spec.Iface.Proutes6) == 0 &&
len(dnet.Spec.Options.Routes) == 0 && len(dnet.Spec.Options.Routes6) == 0 {
return nil
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
origNs, err := ns.GetCurrentNS()
Expand All @@ -139,34 +134,18 @@ func PostProcessInterface(ep danmtypes.DanmEp, dnet *danmtypes.DanmNet) error {
if isVfAttachedToDpdkDriver {
err = createDummyInterface(ep)
if err != nil {
return err
return errors.New("failed to create dummy kernel interface for " + ep.Spec.Iface.Name + " because:" + err.Error())
}
}
err = setDanmEpSysctls(ep)
if err != nil {
return errors.New("failed to set kernel configs for interface" + ep.Spec.Iface.Name + " beause:" + err.Error())
}
return addIpRoutes(ep,dnet)
}

func SetDanmEpSysctls(ep danmtypes.DanmEp) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
// save the current namespace
origNs, err := ns.GetCurrentNS()
if err != nil {
return errors.New("failed to get current network namespace due to:" + err.Error())
}
// enter to the Pod's network namespace
podNs, err := ns.GetNS(ep.Spec.Netns)
if err != nil {
return errors.New("failed to get Pod's network namespace due to:" + err.Error())
}
err = podNs.Set()
if err != nil {
return errors.New("failed to switch to Pod's network namespace due to:" + err.Error())
}
defer func() {
podNs.Close()
origNs.Set()
}()
// set sysctls
func setDanmEpSysctls(ep danmtypes.DanmEp) error {
var err error
for _, s := range sysctls {
if s.sysctlFunc(ep) {
for _, ss := range s.sysctlData {
Expand All @@ -189,8 +168,7 @@ func isIPv6Needed(ep danmtypes.DanmEp) bool {
}

func isIPv6NotNeeded(ep danmtypes.DanmEp) bool {
isVfAttachedToDpdkDriver,_ := sriov_utils.HasDpdkDriver(ep.Spec.Iface.DeviceID)
if !isVfAttachedToDpdkDriver && ep.Spec.Iface.AddressIPv6 == "" {
if ep.Spec.Iface.AddressIPv6 == "" {
return true
}
return false
Expand Down
4 changes: 0 additions & 4 deletions pkg/danmep/ep.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ func createContainerIface(ep danmtypes.DanmEp, dnet *danmtypes.DanmNet, device s
log.Println("WARNING: sending gARP failed with error:" + err.Error(), ", but we will ignore that for now!")
}
}
err = addIpRoutes(ep, dnet)
if err != nil {
return errors.New("IP routes could not be provisioned, because:" + err.Error())
}
return nil
}

Expand Down
9 changes: 2 additions & 7 deletions pkg/metacni/metacni.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func createDelegatedInterface(syncher *syncher.Syncher, danmClient danmclientset
}
delegatedResult,err := cnidel.DelegateInterfaceSetup(DanmConfig, danmClient, netInfo, &ep)
if err != nil {
cnidel.FreeDelegatedIps(danmClient, netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
syncher.PushResult(netInfo.ObjectMeta.Name, errors.New("CNI delegation failed due to error:" + err.Error()), nil)
return
}
Expand All @@ -378,12 +379,6 @@ func createDelegatedInterface(syncher *syncher.Syncher, danmClient danmclientset
syncher.PushResult(netInfo.ObjectMeta.Name, errors.New("DanmEp object could not be PUT to K8s due to error:" + err.Error()), nil)
return
}
err = danmep.SetDanmEpSysctls(ep)
if err != nil {
cnidel.FreeDelegatedIps(danmClient, netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
syncher.PushResult(netInfo.ObjectMeta.Name, errors.New("Sysctls could not be set due to error:" + err.Error()), nil)
return
}
syncher.PushResult(netInfo.ObjectMeta.Name, nil, delegatedResult)
}

Expand Down Expand Up @@ -423,7 +418,7 @@ func createDanmInterface(syncher *syncher.Syncher, danmClient danmclientset.Inte
syncher.PushResult(netInfo.ObjectMeta.Name, errors.New("IPVLAN interface could not be created due to error:" + err.Error()), nil)
return
}
err = danmep.SetDanmEpSysctls(ep)
err = danmep.PostProcessInterface(ep, netInfo)
if err != nil {
ipam.GarbageCollectIps(danmClient, netInfo, ip4, ip6)
danmClient.DanmV1().DanmEps(ep.ObjectMeta.Namespace).Delete(ep.ObjectMeta.Name, &meta_v1.DeleteOptions{})
Expand Down

0 comments on commit ea7604f

Please sign in to comment.