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

fix: include new fields in cni Add success result #9396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions cni-plugin/pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,11 @@ func CmdAddK8s(ctx context.Context, args *skel.CmdArgs, conf types.NetConf, epID

// Add the interface created above to the CNI result.
result.Interfaces = append(result.Interfaces, &cniv1.Interface{
Name: endpoint.Spec.InterfaceName},
)
Name: endpoint.Spec.InterfaceName,
Mac: endpoint.Spec.MAC,
Mtu: conf.MTU,
Sandbox: args.Netns,
})

// Conditionally wait for host-local Felix to program the policy for this WEP.
// Error if negative, ignore if 0.
Expand Down
7 changes: 5 additions & 2 deletions cni-plugin/pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,11 @@ func cmdAdd(args *skel.CmdArgs) (err error) {

// Add the interface created above to the CNI result.
result.Interfaces = append(result.Interfaces, &cniv1.Interface{
Name: endpoint.Spec.InterfaceName},
)
Name: endpoint.Spec.InterfaceName,
Mac: endpoint.Spec.MAC,
Mtu: conf.MTU,
Sandbox: args.Netns,
})
}

// Handle profile creation - this is only done if there isn't a specific policy handler.
Expand Down
9 changes: 9 additions & 0 deletions cni-plugin/tests/calico_cni_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,15 @@ var _ = Describe("Kubernetes CNI tests", func() {
// Otherwise, they should be the same.
resultSecondAdd.IPs = nil
result.IPs = nil

// The MAC address will be different, since we create a new veth.
Expect(len(resultSecondAdd.Interfaces)).Should(Equal(len(result.Interfaces)))
for i := range resultSecondAdd.Interfaces {
Expect(resultSecondAdd.Interfaces[i].Mac).ShouldNot(Equal(result.Interfaces[i].Mac))
resultSecondAdd.Interfaces[i].Mac = ""
result.Interfaces[i].Mac = ""
}

Expect(resultSecondAdd).Should(Equal(result))

// IPAM reservation should still be in place.
Expand Down