Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle pod deletion when PrevResult has VLAN 0 #2323

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions cmd/routed-eni-cni-plugin/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ import (
pb "github.com/aws/amazon-vpc-cni-k8s/rpc"
)

const ipamdAddress = "127.0.0.1:50051"

const dummyVlanInterfacePrefix = "dummy"
const (
ipamdAddress = "127.0.0.1:50051"
dummyVlanInterfacePrefix = "dummy"
reservedVlanID = 0
)

var version string

Expand Down Expand Up @@ -214,7 +216,7 @@ func add(args *skel.CmdArgs, cniTypes typeswrapper.CNITYPES, grpcClient grpcwrap
var dummyVlanInterface *current.Interface

// Non-zero value means pods are using branch ENI
if r.PodVlanId != 0 {
if r.PodVlanId != reservedVlanID {
hostVethNamePrefix := sgpp.BuildHostVethNamePrefix(conf.VethPrefix, conf.PodSGEnforcingMode)
hostVethName = generateHostVethName(hostVethNamePrefix, string(k8sArgs.K8S_POD_NAMESPACE), string(k8sArgs.K8S_POD_NAME))
err = driverClient.SetupBranchENIPodNetwork(hostVethName, args.IfName, args.Netns, v4Addr, v6Addr, int(r.PodVlanId), r.PodENIMAC,
Expand Down Expand Up @@ -395,7 +397,7 @@ func del(args *skel.CmdArgs, cniTypes typeswrapper.CNITYPES, grpcClient grpcwrap
}

// vlanID != 0 means pod using security group
if r.PodVlanId != 0 {
if r.PodVlanId != reservedVlanID {
if isNetnsEmpty(args.Netns) {
log.Infof("Ignoring TeardownPodENI as Netns is empty for SG pod:%s namespace: %s containerID:%s", k8sArgs.K8S_POD_NAME, k8sArgs.K8S_POD_NAMESPACE, k8sArgs.K8S_POD_INFRA_CONTAINER_ID)
return nil
Expand Down Expand Up @@ -431,9 +433,13 @@ func tryDelWithPrevResult(driverClient driver.NetworkAPIs, conf *NetConf, k8sArg
return false, nil
}
podVlanID, err := strconv.Atoi(dummyIface.Mac)
if err != nil || podVlanID == 0 {
if err != nil {
return true, errors.Errorf("malformed vlanID in prevResult: %s", dummyIface.Mac)
}
// If VLAN value is 0, return without handling so that normal delete logic can occur.
jdn5126 marked this conversation as resolved.
Show resolved Hide resolved
if podVlanID == reservedVlanID {
return false, nil
}
if isNetnsEmpty(netNS) {
log.Infof("Ignoring TeardownPodENI as Netns is empty for SG pod:%s namespace: %s containerID:%s", k8sArgs.K8S_POD_NAME, k8sArgs.K8S_POD_NAMESPACE, k8sArgs.K8S_POD_INFRA_CONTAINER_ID)
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/routed-eni-cni-plugin/cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func Test_tryDelWithPrevResult(t *testing.T) {
wantErr: errors.New("malformed vlanID in prevResult: xxx"),
},
{
name: "malformed vlanID in prevResult - 0",
name: "vlanID in prevResult - 0",
fields: fields{},
args: args{
conf: &NetConf{
Expand Down Expand Up @@ -643,7 +643,7 @@ func Test_tryDelWithPrevResult(t *testing.T) {
},
contVethName: "eth0",
},
wantErr: errors.New("malformed vlanID in prevResult: 0"),
want: false,
},
{
name: "confVeth don't exists",
Expand Down