Skip to content
Merged
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
14 changes: 2 additions & 12 deletions azure-ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error {
p.logger.Debug("Received CNS IP config response", zap.Any("response", resp))

// Get Pod IP and gateway IP from ip config response
podIPNet, gwIP, err := ipconfig.ProcessIPConfigResp(resp)
podIPNet, err := ipconfig.ProcessIPConfigResp(resp)
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")
}
p.logger.Debug("Parsed pod IP and gateway IP", zap.String("podIPNet", podIPNet.String()), zap.String("gwIP", gwIP.String()))
p.logger.Debug("Parsed pod IP", zap.String("podIPNet", podIPNet.String()))

cniResult := &types100.Result{
IPs: []*types100.IPConfig{
Expand All @@ -94,16 +94,6 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error {
IP: net.ParseIP(podIPNet.Addr().String()),
Mask: net.CIDRMask(podIPNet.Bits(), 32), // nolint
},
Gateway: net.ParseIP(gwIP.String()),
},
},
Routes: []*cniTypes.Route{
{
Dst: net.IPNet{
IP: net.IPv4zero,
Mask: net.IPv4Mask(0, 0, 0, 0),
},
GW: net.ParseIP(gwIP.String()),
},
},
}
Expand Down
12 changes: 3 additions & 9 deletions azure-ipam/ipconfig/ipconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,18 @@ func CreateIPConfigReq(args *cniSkel.CmdArgs) (cns.IPConfigRequest, error) {
}

// ProcessIPConfigResp processes the IPConfigResponse from the CNS.
func ProcessIPConfigResp(resp *cns.IPConfigResponse) (*netip.Prefix, *netip.Addr, error) {
func ProcessIPConfigResp(resp *cns.IPConfigResponse) (*netip.Prefix, error) {
podCIDR := fmt.Sprintf(
"%s/%d",
resp.PodIpInfo.PodIPConfig.IPAddress,
resp.PodIpInfo.NetworkContainerPrimaryIPConfig.IPSubnet.PrefixLength,
)
podIPNet, err := netip.ParsePrefix(podCIDR)
if err != nil {
return nil, nil, errors.Wrapf(err, "cns returned invalid pod CIDR %q", podCIDR)
return nil, errors.Wrapf(err, "cns returned invalid pod CIDR %q", podCIDR)
}

ncGatewayIPAddress := resp.PodIpInfo.NetworkContainerPrimaryIPConfig.GatewayIPAddress
gwIP, err := netip.ParseAddr(ncGatewayIPAddress)
if err != nil {
return nil, nil, errors.Wrapf(err, "cns returned an invalid gateway address %q", ncGatewayIPAddress)
}

return &podIPNet, &gwIP, nil
return &podIPNet, nil
}

type k8sPodEnvArgs struct {
Expand Down