diff --git a/azure-ipam/ipam.go b/azure-ipam/ipam.go index e71782ebd8..defb15e078 100644 --- a/azure-ipam/ipam.go +++ b/azure-ipam/ipam.go @@ -81,7 +81,7 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error { p.logger.Debug("Making request to CNS") // if this fails, the caller plugin should execute again with cmdDel before returning error. // https://www.cni.dev/docs/spec/#delegated-plugin-execution-procedure - resp, err := p.cnsClient.RequestIPs(context.TODO(), req) + resp, err := p.cnsClient.RequestIPs(context.TODO(), req) // need to add interfaces to this response if err != nil { if cnscli.IsUnsupportedAPI(err) { p.logger.Error("Failed to request IPs using RequestIPs from CNS, going to try RequestIPAddress", zap.Error(err), zap.Any("request", req)) @@ -113,9 +113,10 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error { } } p.logger.Debug("Received CNS IP config response", zap.Any("response", resp)) + // resp.PodIPInfo // Get Pod IP and gateway IP from ip config response - podIPNet, err := ipconfig.ProcessIPConfigsResp(resp) + podIPNet, gatewayIP, err := ipconfig.ProcessIPConfigsResp(resp) // need to get interfaces out of the response and add it here if err != nil { p.logger.Error("Failed to interpret CNS IPConfigResponse", zap.Error(err), zap.Any("response", resp)) return cniTypes.NewError(ErrProcessIPConfigResponse, err.Error(), "failed to interpret CNS IPConfigResponse") @@ -130,14 +131,24 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error { IP: net.ParseIP(ipNet.Addr().String()), Mask: net.CIDRMask(ipNet.Bits(), 32), // nolint } + ipConfig.Gateway = (*gatewayIP)[i] } else { ipConfig.Address = net.IPNet{ IP: net.ParseIP(ipNet.Addr().String()), Mask: net.CIDRMask(ipNet.Bits(), 128), // nolint } + ipConfig.Gateway = net.ParseIP("fd00:aec6:6946:1::") } cniResult.IPs[i] = ipConfig } + cniResult.Interfaces = make([]*types100.Interface, 1) + interface_test := &types100.Interface{ + Name: "eth1", + Mac: "00:0D:3A:FE:1E:B2", + } + cniResult.Interfaces[0] = interface_test + + p.logger.Info("Created CNIResult:", zap.Any("result", cniResult)) // Get versioned result versionedCniResult, err := cniResult.GetAsVersion(nwCfg.CNIVersion) diff --git a/azure-ipam/ipconfig/ipconfig.go b/azure-ipam/ipconfig/ipconfig.go index 9b2ecc97f4..53ad3a3d8a 100644 --- a/azure-ipam/ipconfig/ipconfig.go +++ b/azure-ipam/ipconfig/ipconfig.go @@ -3,6 +3,7 @@ package ipconfig import ( "encoding/json" "fmt" + "net" "net/netip" "github.com/Azure/azure-container-networking/cns" @@ -63,8 +64,9 @@ func CreateIPConfigsReq(args *cniSkel.CmdArgs) (cns.IPConfigsRequest, error) { return req, nil } -func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, error) { +func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, *[]net.IP, error) { podIPNets := make([]netip.Prefix, len(resp.PodIPInfo)) + gatewaysIPs := make([]net.IP, len(resp.PodIPInfo)) for i := range resp.PodIPInfo { podCIDR := fmt.Sprintf( @@ -74,12 +76,14 @@ func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, error) ) podIPNet, err := netip.ParsePrefix(podCIDR) if err != nil { - return nil, errors.Wrapf(err, "cns returned invalid pod CIDR %q", podCIDR) + return nil, nil, errors.Wrapf(err, "cns returned invalid pod CIDR %q", podCIDR) } podIPNets[i] = podIPNet + gatewayIP := net.ParseIP(resp.PodIPInfo[i].NetworkContainerPrimaryIPConfig.GatewayIPAddress) + gatewaysIPs[i] = gatewayIP } - return &podIPNets, nil + return &podIPNets, &gatewaysIPs, nil } type k8sPodEnvArgs struct { diff --git a/cns/restserver/util.go b/cns/restserver/util.go index 43d1e1aef9..e485c5908f 100644 --- a/cns/restserver/util.go +++ b/cns/restserver/util.go @@ -846,7 +846,7 @@ func (service *HTTPRestService) populateIPConfigInfoUntransacted(ipConfigStatus podIPInfo.HostPrimaryIPInfo.Subnet = primaryHostInterface.Subnet podIPInfo.HostPrimaryIPInfo.Gateway = primaryHostInterface.Gateway podIPInfo.NICType = cns.InfraNIC - + fmt.Printf("podIPInfo after adding interface: %+v", podIPInfo) return nil }