Skip to content

Commit 699c452

Browse files
committed
initial changes for azure-ipam V6 routing
1 parent 88959a1 commit 699c452

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

azure-ipam/ipam.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error {
8181
p.logger.Debug("Making request to CNS")
8282
// if this fails, the caller plugin should execute again with cmdDel before returning error.
8383
// https://www.cni.dev/docs/spec/#delegated-plugin-execution-procedure
84-
resp, err := p.cnsClient.RequestIPs(context.TODO(), req)
84+
resp, err := p.cnsClient.RequestIPs(context.TODO(), req) // need to add interfaces to this response
8585
if err != nil {
8686
if cnscli.IsUnsupportedAPI(err) {
8787
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 {
113113
}
114114
}
115115
p.logger.Debug("Received CNS IP config response", zap.Any("response", resp))
116+
// resp.PodIPInfo
116117

117118
// Get Pod IP and gateway IP from ip config response
118-
podIPNet, err := ipconfig.ProcessIPConfigsResp(resp)
119+
podIPNet, gatewayIP, err := ipconfig.ProcessIPConfigsResp(resp) // need to get interfaces out of the response and add it here
119120
if err != nil {
120121
p.logger.Error("Failed to interpret CNS IPConfigResponse", zap.Error(err), zap.Any("response", resp))
121122
return cniTypes.NewError(ErrProcessIPConfigResponse, err.Error(), "failed to interpret CNS IPConfigResponse")
@@ -130,14 +131,24 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error {
130131
IP: net.ParseIP(ipNet.Addr().String()),
131132
Mask: net.CIDRMask(ipNet.Bits(), 32), // nolint
132133
}
134+
ipConfig.Gateway = (*gatewayIP)[i]
133135
} else {
134136
ipConfig.Address = net.IPNet{
135137
IP: net.ParseIP(ipNet.Addr().String()),
136138
Mask: net.CIDRMask(ipNet.Bits(), 128), // nolint
137139
}
140+
ipConfig.Gateway = net.ParseIP("fd00:aec6:6946:1::")
138141
}
139142
cniResult.IPs[i] = ipConfig
140143
}
144+
cniResult.Interfaces = make([]*types100.Interface, 1)
145+
interface_test := &types100.Interface{
146+
Name: "eth1",
147+
Mac: "00:0D:3A:FE:1E:B2",
148+
}
149+
cniResult.Interfaces[0] = interface_test
150+
151+
p.logger.Info("Created CNIResult:", zap.Any("result", cniResult))
141152

142153
// Get versioned result
143154
versionedCniResult, err := cniResult.GetAsVersion(nwCfg.CNIVersion)

azure-ipam/ipconfig/ipconfig.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ipconfig
33
import (
44
"encoding/json"
55
"fmt"
6+
"net"
67
"net/netip"
78

89
"github.com/Azure/azure-container-networking/cns"
@@ -63,8 +64,9 @@ func CreateIPConfigsReq(args *cniSkel.CmdArgs) (cns.IPConfigsRequest, error) {
6364
return req, nil
6465
}
6566

66-
func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, error) {
67+
func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, *[]net.IP, error) {
6768
podIPNets := make([]netip.Prefix, len(resp.PodIPInfo))
69+
gatewaysIPs := make([]net.IP, len(resp.PodIPInfo))
6870

6971
for i := range resp.PodIPInfo {
7072
podCIDR := fmt.Sprintf(
@@ -74,12 +76,14 @@ func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, error)
7476
)
7577
podIPNet, err := netip.ParsePrefix(podCIDR)
7678
if err != nil {
77-
return nil, errors.Wrapf(err, "cns returned invalid pod CIDR %q", podCIDR)
79+
return nil, nil, errors.Wrapf(err, "cns returned invalid pod CIDR %q", podCIDR)
7880
}
7981
podIPNets[i] = podIPNet
82+
gatewayIP := net.ParseIP(resp.PodIPInfo[i].NetworkContainerPrimaryIPConfig.GatewayIPAddress)
83+
gatewaysIPs[i] = gatewayIP
8084
}
8185

82-
return &podIPNets, nil
86+
return &podIPNets, &gatewaysIPs, nil
8387
}
8488

8589
type k8sPodEnvArgs struct {

cns/restserver/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ func (service *HTTPRestService) populateIPConfigInfoUntransacted(ipConfigStatus
846846
podIPInfo.HostPrimaryIPInfo.Subnet = primaryHostInterface.Subnet
847847
podIPInfo.HostPrimaryIPInfo.Gateway = primaryHostInterface.Gateway
848848
podIPInfo.NICType = cns.InfraNIC
849-
849+
fmt.Printf("podIPInfo after adding interface: %+v", podIPInfo)
850850
return nil
851851
}
852852

0 commit comments

Comments
 (0)