Skip to content

Commit 7ea6eb9

Browse files
committed
Fixing providing wrong interface name to be deleted during CNI_DEL operation in case Pod has multiple interfaces
CNI result is effectively ignored during CNI_DEL, an empty current.Result is returned to Kubelet
1 parent 5b150a4 commit 7ea6eb9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

build_danm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ error_handler()
3030
exit $1
3131
}
3232

33-
if [[ ( "$TRAVIS_PIPELINE" = "buildah" ) || ( -n "$TRAVIS_PIPELINE" && -x "$(command -v buildah)" ) ]]; then
33+
if [[ ( "$TRAVIS_PIPELINE" = "buildah" ) || ( "$TRAVIS_PIPELINE" = "" && -x "$(command -v buildah)" ) ]]; then
3434
source ./build_buildah.sh
35-
elif [[ ( "$TRAVIS_PIPELINE" = "docker" ) || ( -n "$TRAVIS_PIPELINE" && -x "$(command -v docker)" ) ]]; then
35+
elif [[ ( "$TRAVIS_PIPELINE" = "docker" ) || ( "$TRAVIS_PIPELINE" = "" && -x "$(command -v docker)" ) ]]; then
3636
source ./build_docker.sh
3737
else
3838
echo 'The build process requires docker or buildah/podman installed. Please install any of these and make sure these are executable'

pkg/cnidel/cnidel.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,23 @@ func getCniPluginConfig(netInfo *danmtypes.DanmNet, ipamOptions danmtypes.IpamCo
131131
func execCniPlugin(cniType string, netInfo *danmtypes.DanmNet, rawConfig []byte, ep *danmtypes.DanmEp) (types.Result,error) {
132132
cniPath, cniArgs, err := getExecCniParams(cniType, netInfo, ep)
133133
if err != nil {
134-
return nil, err
134+
return nil, errors.New("exec CNI params couldn't be gathered:" + err.Error())
135135
}
136136
exec := invoke.RawExec{Stderr: os.Stderr}
137137
rawResult, err := exec.ExecPlugin(cniPath, rawConfig, cniArgs)
138138
if err != nil {
139-
return nil, err
139+
return nil, errors.New("OS exec call failed:" + err.Error())
140140
}
141141
versionDecoder := &version.ConfigDecoder{}
142-
confVersion, err := versionDecoder.Decode(rawConfig)
143-
if err != nil {
144-
return nil, err
142+
confVersion, err := versionDecoder.Decode(rawConfig)
143+
if err != nil || rawResult == nil {
144+
return &current.Result{}, nil
145+
}
146+
convertedResult, err := version.NewResult(confVersion, rawResult)
147+
if err != nil || convertedResult == nil {
148+
return &current.Result{}, nil
145149
}
146-
return version.NewResult(confVersion, rawResult)
150+
return convertedResult, nil
147151
}
148152

149153
func getExecCniParams(cniType string, netInfo *danmtypes.DanmNet, ep *danmtypes.DanmEp) (string,[]string,error) {
@@ -183,7 +187,7 @@ func DelegateInterfaceDelete(danmClient danmclientset.Interface, netInfo *danmty
183187
return err
184188
}
185189
cniType := netInfo.Spec.NetworkType
186-
err = invoke.DelegateDel(cniType, rawConfig)
190+
_, err = execCniPlugin(cniType, netInfo, rawConfig, ep)
187191
if err != nil {
188192
freeDelegatedIps(danmClient, netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
189193
return errors.New("Error delegating DEL to CNI plugin:" + cniType + " because:" + err.Error())

0 commit comments

Comments
 (0)