Skip to content
Closed
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
15 changes: 13 additions & 2 deletions azure-ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions azure-ipam/ipconfig/ipconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ipconfig
import (
"encoding/json"
"fmt"
"net"
"net/netip"

"github.com/Azure/azure-container-networking/cns"
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading