Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L1VH CNI first version #2465

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a50182b
L1VH CNI
paulyufan2 Jan 3, 2024
0677f69
fix issues
paulyufan2 Jan 8, 2024
180715c
fix issues
paulyufan2 Jan 10, 2024
af02703
fix deletion
paulyufan2 Jan 10, 2024
1e7c325
current code
paulyufan2 Jan 14, 2024
2ea66a2
fix cni deletion call
paulyufan2 Jan 17, 2024
6692b24
fix issues
paulyufan2 Jan 17, 2024
bfb63c9
fix issues
paulyufan2 Jan 17, 2024
aae1984
fix issues
paulyufan2 Jan 17, 2024
c005303
fix hnsNetwork deletion issue
paulyufan2 Jan 19, 2024
f3c5b91
fix logs
paulyufan2 Jan 19, 2024
36932fd
fix logs
paulyufan2 Jan 19, 2024
a27ecc4
add windows UT
paulyufan2 Jan 19, 2024
d2e6624
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 19, 2024
62d0805
fix test issues
paulyufan2 Jan 22, 2024
851592b
add UTs
paulyufan2 Jan 22, 2024
7d11d01
add UTs
paulyufan2 Jan 22, 2024
fe01226
add UTs
paulyufan2 Jan 23, 2024
017fe33
add UT
paulyufan2 Jan 23, 2024
9e28b3b
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 23, 2024
12383d3
fix UTs
paulyufan2 Jan 23, 2024
405e04b
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 24, 2024
1730fd2
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 25, 2024
8c5ed2f
fix nat policy
paulyufan2 Jan 26, 2024
b3dbb51
fix comments
paulyufan2 Jan 26, 2024
83cd2a5
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 26, 2024
631f350
fix linter issue
paulyufan2 Jan 26, 2024
89e40bb
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 29, 2024
25d91d0
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Jan 31, 2024
234d36d
remove new conflist file
paulyufan2 Feb 5, 2024
369d976
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 5, 2024
1ed892b
fix issues
paulyufan2 Feb 5, 2024
e0d0da2
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 6, 2024
188ec28
add comments
paulyufan2 Feb 6, 2024
cf2707d
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 9, 2024
eb0f53c
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 12, 2024
bf20cb7
fix comments
paulyufan2 Feb 14, 2024
b328e06
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 15, 2024
8c1ab69
fix main comments
paulyufan2 Feb 15, 2024
4d8a0d8
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 16, 2024
c8ccc07
Merge branch 'master' into CNIL1VHBranch
paulyufan2 Feb 20, 2024
b078d8d
L1VH CNI
paulyufan2 Jan 3, 2024
49748c3
fix deletion
paulyufan2 Jan 10, 2024
34b688a
fix cni deletion call
paulyufan2 Jan 17, 2024
fcc3538
fix hnsNetwork deletion issue
paulyufan2 Jan 19, 2024
1bb97ef
add comments
paulyufan2 Feb 6, 2024
b3fe948
fix comments
paulyufan2 Feb 20, 2024
f90accd
fix TM's comments
paulyufan2 Feb 21, 2024
88157f2
fix the linter issue to assign a vairable
paulyufan2 Feb 21, 2024
fded358
fix issues'
paulyufan2 Feb 23, 2024
7ea8c68
fix the UT
paulyufan2 Feb 26, 2024
50826f7
fix the linter issue
paulyufan2 Feb 26, 2024
96b2363
fix an linter issue
paulyufan2 Feb 26, 2024
0da0f39
fix issues
paulyufan2 Feb 26, 2024
94c3800
fix a variable definition
paulyufan2 Feb 27, 2024
1fe4c7d
fix the cnsconfig changes
paulyufan2 Feb 27, 2024
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
1 change: 1 addition & 0 deletions cni/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type PodNetworkInterfaceInfo struct {
PodNamespace string
PodEndpointId string
ContainerID string
MacAddress string
paulyufan2 marked this conversation as resolved.
Show resolved Hide resolved
IPAddresses []net.IPNet
}

Expand Down
18 changes: 15 additions & 3 deletions cni/network/invoker_cns.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,17 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro

//nolint:exhaustive // ignore exhaustive types check
switch info.nicType {
case cns.DelegatedVMNIC:
// only handling single v4 PodIPInfo for DelegatedVMNICs at the moment, will have to update once v6 gets added
case cns.DelegatedVMNIC, cns.BackendNIC:
// only handling single v4 PodIPInfo for DelegatedVMNIC and BackendNIC at the moment, will have to update once v6 gets added
if !info.skipDefaultRoutes {
numInterfacesWithDefaultRoutes++
}

// Add secondary interface info from podIPInfo to ipamAddResult
info.hostSubnet = response.PodIPInfo[i].HostSecondaryIPInfo.Subnet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L168 - add other nic types too for same case

info.hostPrimaryIP = response.PodIPInfo[i].HostSecondaryIPInfo.PrimaryIP
info.hostGateway = response.PodIPInfo[i].HostSecondaryIPInfo.Gateway

Comment on lines +174 to +178
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont this affect AKS swift 2.0? it was using this before:


			hostSubnet:         response.PodIPInfo[i].HostPrimaryIPInfo.Subnet,
			hostPrimaryIP:      response.PodIPInfo[i].HostPrimaryIPInfo.PrimaryIP,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it gets secondary interface info from HostSecondaryIPInfo

if err := configureSecondaryAddResult(&info, &addResult, &response.PodIPInfo[i].PodIPConfig); err != nil {
return IPAMAddResult{}, err
}
Expand Down Expand Up @@ -450,6 +455,13 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
return errors.Wrap(err, "Invalid mac address")
}

_, hostIPNet, err := net.ParseCIDR(info.hostSubnet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we do need "hostSubnetPrefix" to find master interface if you check findMasterInterface()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check based on macAddress instead?

if err != nil {
return fmt.Errorf("unable to parse hostSubnet: %w", err)
}

addResult.hostSubnetPrefix = *hostIPNet

routes, err := getRoutes(info.routes, info.skipDefaultRoutes)
if err != nil {
return err
Expand All @@ -462,6 +474,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
IP: ip,
Mask: ipnet.Mask,
},
Gateway: net.ParseIP(info.ncGatewayIPAddress),
},
},
Routes: routes,
Expand All @@ -471,6 +484,5 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
}

addResult.secondaryInterfacesInfo = append(addResult.secondaryInterfacesInfo, result)

return nil
}
110 changes: 110 additions & 0 deletions cni/network/invoker_cns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,3 +1337,113 @@ func Test_setHostOptions(t *testing.T) {
})
}
}

func TestCNSIPAMInvoker_Add_SwiftV2(t *testing.T) {
require := require.New(t) //nolint further usage of require without passing t

macAddress := "12:34:56:78:9a:bc"
parsedMacAddress, _ := net.ParseMAC(macAddress)

type fields struct {
podName string
podNamespace string
cnsClient cnsclient
}

type args struct {
nwCfg *cni.NetworkConfig
args *cniSkel.CmdArgs
hostSubnetPrefix *net.IPNet
options map[string]interface{}
}

tests := []struct {
name string
fields fields
args args
wantSecondaryInterfacesInfo network.InterfaceInfo
wantErr bool
}{
{
name: "Test happy CNI add with swiftv2 L1VH multitenant result",
fields: fields{
podName: testPodInfo.PodName,
podNamespace: testPodInfo.PodNamespace,
cnsClient: &MockCNSClient{
require: require,
requestIPs: requestIPsHandler{
ipconfigArgument: cns.IPConfigsRequest{
PodInterfaceID: "testcont-testifname1",
InfraContainerID: "testcontainerid1",
OrchestratorContext: marshallPodInfo(testPodInfo),
},
result: &cns.IPConfigsResponse{
PodIPInfo: []cns.PodIpInfo{
{
PodIPConfig: cns.IPSubnet{
IPAddress: "10.1.1.10",
PrefixLength: 24,
},
HostSecondaryIPInfo: cns.HostIPInfo{
Gateway: "10.0.0.1",
PrimaryIP: "10.0.0.2",
Subnet: "10.0.0.1/24",
},
NICType: cns.DelegatedVMNIC,
MacAddress: macAddress,
},
},
Response: cns.Response{
ReturnCode: 0,
Message: "",
},
},
err: nil,
},
},
},
args: args{
nwCfg: &cni.NetworkConfig{},
args: &cniSkel.CmdArgs{
ContainerID: "testcontainerid1",
Netns: "testnetns1",
IfName: "testifname1",
},
hostSubnetPrefix: getCIDRNotationForAddress("10.0.0.1/24"),
options: map[string]interface{}{},
},
wantSecondaryInterfacesInfo: network.InterfaceInfo{
IPConfigs: []*network.IPConfig{
{
Address: *getCIDRNotationForAddress("10.1.1.10/24"),
},
},
Routes: []network.RouteInfo{},
NICType: cns.DelegatedVMNIC,
MacAddress: parsedMacAddress,
},
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
invoker := &CNSIPAMInvoker{
podName: tt.fields.podName,
podNamespace: tt.fields.podNamespace,
cnsClient: tt.fields.cnsClient,
}
ipamAddResult, err := invoker.Add(IPAMAddConfig{nwCfg: tt.args.nwCfg, args: tt.args.args, options: tt.args.options})
if tt.wantErr {
require.Error(err)
} else {
require.NoError(err)
}

fmt.Printf("want:%+v\nrest:%+v\n", tt.wantSecondaryInterfacesInfo, ipamAddResult.secondaryInterfacesInfo)
if len(tt.wantSecondaryInterfacesInfo.IPConfigs) > 0 {
require.EqualValues(tt.wantSecondaryInterfacesInfo, ipamAddResult.secondaryInterfacesInfo[0], "incorrect multitenant response")
}
})
}
}
Loading
Loading