@@ -210,15 +210,31 @@ func allocateIPsWithDelegatedPlugin(
210210 // Safe to assume at most one IP per family. The K8s API docs say:
211211 // "Pods may be allocated at most 1 value for each of IPv4 and IPv6"
212212 // https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/
213+ // Interface returned by IPAM should be treated as the uplink for the Pod.
214+ masterMac := ""
215+ for _ , iface := range ipamResult .Interfaces {
216+ if iface .Sandbox == "" && iface .Mac != "" {
217+ masterMac = iface .Mac
218+ }
219+ }
213220 for _ , ipConfig := range ipamResult .IPs {
214221 ipNet := ipConfig .Address
215222 if ipv4 := ipNet .IP .To4 (); ipv4 != nil {
216223 ipam .Address .IPV4 = ipNet .String ()
217- ipam .IPV4 = & models.IPAMAddressResponse {IP : ipv4 .String ()}
224+ ipam .IPV4 = & models.IPAMAddressResponse {
225+ IP : ipv4 .String (),
226+ Gateway : ipConfig .Gateway .String (),
227+ MasterMac : masterMac ,
228+ InterfaceNumber : "0" ,
229+ }
218230 } else if conf .Addressing .IPV6 != nil {
219231 // assign ipam ipv6 address only if agent ipv6 config is enabled
220232 ipam .Address .IPV6 = ipNet .String ()
221- ipam .IPV6 = & models.IPAMAddressResponse {IP : ipNet .IP .String ()}
233+ ipam .IPV6 = & models.IPAMAddressResponse {
234+ IP : ipNet .IP .String (),
235+ MasterMac : masterMac ,
236+ InterfaceNumber : "0" ,
237+ }
222238 }
223239 }
224240
@@ -665,6 +681,13 @@ func (cmd *Cmd) Add(args *skel.CmdArgs) (err error) {
665681 if err != nil {
666682 return fmt .Errorf ("unable to setup interface datapath: %w" , err )
667683 }
684+ case ipamOption .IPAMDelegatedPlugin :
685+ if ipam .IPV4 .MasterMac != "" || ipam .IPV6 .MasterMac != "" {
686+ err = interfaceAdd (ipConfig , ipam .IPV4 , conf )
687+ if err != nil {
688+ return fmt .Errorf ("unable to setup interface datapath: %w" , err )
689+ }
690+ }
668691 }
669692
670693 var macAddrStr string
0 commit comments