Skip to content

Commit 1ee8aec

Browse files
Merge pull request #9396 from dovics/cniresult
fix: include new fields in cni Add success result
2 parents 791a7b6 + 63df9ee commit 1ee8aec

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

cni-plugin/pkg/k8s/k8s.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,11 @@ func CmdAddK8s(ctx context.Context, args *skel.CmdArgs, conf types.NetConf, epID
533533

534534
// Add the interface created above to the CNI result.
535535
result.Interfaces = append(result.Interfaces, &cniv1.Interface{
536-
Name: endpoint.Spec.InterfaceName},
537-
)
536+
Name: endpoint.Spec.InterfaceName,
537+
Mac: endpoint.Spec.MAC,
538+
Mtu: conf.MTU,
539+
Sandbox: args.Netns,
540+
})
538541

539542
// Conditionally wait for host-local Felix to program the policy for this WEP.
540543
// Error if negative, ignore if 0.

cni-plugin/pkg/plugin/plugin.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,11 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
509509

510510
// Add the interface created above to the CNI result.
511511
result.Interfaces = append(result.Interfaces, &cniv1.Interface{
512-
Name: endpoint.Spec.InterfaceName},
513-
)
512+
Name: endpoint.Spec.InterfaceName,
513+
Mac: endpoint.Spec.MAC,
514+
Mtu: conf.MTU,
515+
Sandbox: args.Netns,
516+
})
514517
}
515518

516519
// Handle profile creation - this is only done if there isn't a specific policy handler.

cni-plugin/tests/calico_cni_k8s_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,15 @@ var _ = Describe("Kubernetes CNI tests", func() {
25772577
// Otherwise, they should be the same.
25782578
resultSecondAdd.IPs = nil
25792579
result.IPs = nil
2580+
2581+
// The MAC address will be different, since we create a new veth.
2582+
Expect(len(resultSecondAdd.Interfaces)).Should(Equal(len(result.Interfaces)))
2583+
for i := range resultSecondAdd.Interfaces {
2584+
Expect(resultSecondAdd.Interfaces[i].Mac).ShouldNot(Equal(result.Interfaces[i].Mac))
2585+
resultSecondAdd.Interfaces[i].Mac = ""
2586+
result.Interfaces[i].Mac = ""
2587+
}
2588+
25802589
Expect(resultSecondAdd).Should(Equal(result))
25812590

25822591
// IPAM reservation should still be in place.

0 commit comments

Comments
 (0)