Граф коммитов

52 Коммитов

Автор SHA1 Сообщение Дата
Kshitija Murudi bee72ee95f
Default to accelnet behavior in CNI for SwiftV2 windows (#3020)
* modify accelnet path in cni

* remove all occurences of accelnetnic type since not sent by cns middleware

* remove all accelnet specific UTs

* remove additional UTs referring to accelnet in invoker_cns & network_test

* fix: additional UTs in endpoint_windows
invoker_mock - removed accelnet flags
2024-09-24 16:36:36 +00:00
Alexander 47b4329b06
fix: add dhcp discover packet to linux swiftv2 to ensure mappings exist for dns (#2989)
* add dhcp client

* address linter issues

* issue dhcp discover request without libraries

* remove library references

* add build tag and remove rand dependency

* address linter issues

* update logging

* fix logging

* move unix sockets to interface to address feedback

* address linter issues

* prevent leaking sockets on error

* remove reuse address option

* add comments

* make dhcp client
2024-09-10 16:46:05 +00:00
Paul Yu 4c66f48fdd
Add UTs to configure secondary interfaces add Result for windows swiftv2 (#2923)
* add UTs for adding interface NICs to cni Result

* add UTs to add interface nics to cniResult

* add an unhappy path ut

* fix linter issues

* fix linter issues

* add a new UT

* fix comments

* remove configurhcnEndpoint UT

* fix linter issue

* fix comments

* fix UT

---------

Signed-off-by: Paul Yu <129891899+paulyufan2@users.noreply.github.com>
2024-08-22 23:19:18 +00:00
Paul Yu ae690d2a70
add accelnet support on CNI (#2853)
* add accelnet support for CNI

* add uts for AccelnetNIC on CNI

* add more uts

* fix an ut

* fix uts

* add ut to endpoint_test

* add endpoint impl test cases for accelnet

* gofummpt windows test

* fix logic of accelnet

* fix logic of accelnet

* modify uts

* remove  an ut

* fix one ut issue

* accelnet interface should set default route

* fix some uts

* remove an ib ut

* fix comments

* fix comments and add uts

* add more uts

* fix an linter issue

* fix comments

* add comment for iov flag

* fix comments

* add endpoint deletion

* add HNSV2 check

* add UT to make sure endpoint and networ deletion called

* add a new test to make infraNIC network is not deleted

* add errMsg

* fix error msg

* add windows test cases for endpoint state deletion

* fix linter issue

* fix a linter issue

* remove hardcode hcniov flag

* comments fix

* add uts for transparent network deletion

* fix comment when hns id is empty

* fix the UT when hns id is empty

* skip linter issue

* change the delegatedVMNIC to NodeNetworkInterfaceFrontendNIC

* fix an ut

* fix add accelnet policy setting ut
2024-08-07 19:08:00 +00:00
Paul Yu 03e0447f32
add L1VH IB support on CNI (#2762)
* add L1VH IB support on CNI

* fix IB issues

* fix UT errors

* fix linter issues

* add win 2025 support for cni image build

* add and comments

* fix a logic bug

* disable endpoint creation and deletion if it's IB NIC

* fix a linter issue

* add UTs

* add UTs for powershell

* enhance Test_getInterfaceInfoKey test case

* remove windows 2025 build from pipeline

* fix some issues

* add an UT to test pnpID

* fix an issue

* fix an ut

* add double quotes

* unblock a brunch of issues

* remove unnecessary codes

* upgradelatest upstream cnii build

* fix a log

* add windows build on pipeline temporarily

* remove backendNIC check for findMasterInterface

* add ut to confirm IB does not create endpoint

* fix linter issue that use %q

* format network.go

* add more uts to cover powershell commands

* remove windows2025 pipeline build

* enhance logs

* fix cniResult format

* add getPnpidstate func

* fix the issue for infraNIC routes

* fix the issue for infraNIC routes

* fix gateway ip address

* add get-pnpdevice UT

* add accelnetNIC support for L1VH

* enhance logic for accelnet nic netowrk flag

* enhance network windows uts

* fix bitmask operator

* use another PR for accelnet PR

* gofumpt files

* fix comments for functional codes

* add uts

* add more uts

* fix uts

* fix functional codes comments

* Update cni/network/network.go

Co-authored-by: tamilmani1989 <tamanoha@microsoft.com>
Signed-off-by: Paul Yu <129891899+paulyufan2@users.noreply.github.com>

* fix latest comments

* fix an UT

* fix invoker_cns_test.go

* fix ut bugs

* fix ut with SkipDefaultRoutes

* add combination ut

* add combination ut

* add ncGateway address to ut

* fix an ut bug

* fix ut bug

* add unhappy test cases

* add endpoint add and deletion cases

* push mock network creation hns api test cases

* remove network creation hns call

* add uts to mock hns network and endpoint calls

* fix ut linter issues

* add infraNIC only invoker test case

* add unhappy path test case

* remove infraNIC only case

* remove unhappy test case

* re-archetect cni ib codes and test

* remove unnecessary logs

* save endpoint state

* save endpoint object for IB

* fix linter issue

* fix a brunch of linter issues

* fix linter issues

* fix linter issue

* fix ut for returned error msg

* temporary add manifest build for CNS/CNI to pipeline

* feedback fix

* fix linter issue

* add ut to get networkName and networkID

* remove Ankit's PR to build cns image

* revert Ankit's changes back

* remove win2025 build from pipeline

* log error for invalid mac address

* revert convertInterfaceInfoToCniResult impl

* fix feedback

* add crd changes to test

* add win2025 yaml to build image

* pass containerID to cns

* revert changes back for review

* revert changes back for review

* gofumpt endpoint.go

* remove comment

* add latest comments

* Update network/endpoint_windows.go

Co-authored-by: tamilmani1989 <tamanoha@microsoft.com>
Signed-off-by: Paul Yu <129891899+paulyufan2@users.noreply.github.com>

* fix a linter issue

* add error check

* add error check

* gofumpt endpoint windows test file

---------

Signed-off-by: Paul Yu <129891899+paulyufan2@users.noreply.github.com>
Co-authored-by: tamilmani1989 <tamanoha@microsoft.com>
2024-07-11 16:05:28 +00:00
QxBytes 6aaa151c8f
fix: add hns network id to endpoint struct for pushing to cns in stateless (#2822)
fix not adding hns network id to endpoint struct for pushing to cns
2024-07-02 02:46:13 +00:00
QxBytes 2ab9cfe823
refactor: code changes for stateless cni and swift v2 (#2688)
* ci: changes up to endpointInternal

* ci: remove defaultInterface from invoker

* ci: change up to CreateEndpoint

* ci: changes up to CreateEndpoint()

* ci: invoker cns and UT fixes

* ci: add fixes to UT(s), capture non populated defaultInterface failures

* ci: multitenancy changes

* ci: invoker azure changes & remove all defaultInterfaceInfo possible

* ci add NICType to baremetal flow

* chore: address comments

* merge nw info fields to ep info and draft new createEndpoint function

* restruct ipamAddResult struct

* reorder code to create epinfo first, and then create network and ep based on epinfo

* add getNwInfo and generate ipamAddResult

* fix network windows.go

* create nw info first and create nw and ep dns info

* fix testIpamAddFail ut referencing wrong redeclared err variable, fix error message

* UT fix part one

* fix the getNetworkID and getNetworkInfo

* move create endpoint to network package, remove ifIndex as needed

* use function to get network id

* unify creation of nw and endpoint info by removing switch

* change functions to consume ep info instead of nw info

* remove unused variable accidentally added earlier

* update old azure ipam invoker to use ep info and change ids to network ids when appropriate

previously we renamed the NetworkInfo symbol to EndpointInfo in lots of places, but the Id in Network Info is NOT the same as Endpoint Info, so while the code compiles, code that previously used the id field of the network info struct would now be using the id field of the endpoint info struct. It should use the NetworkId field of the endpoint info struct instead.

* rename endpoint info id field to EndpointID to remove ambiguity

* change nw info to ep info in windows

* adjust comments

* move all methods in create ep info dependent on nw info to use ep info instead (windows and linux)

addSubnetToNetworkInfo, setNetworkOptions, and getEndpointPolicies. getEndpointPolicies will now take just the subnets needed as a parameter rather than the whole nw or ep info.

* make cnm compile (not necessarily correct)

* make all tests compile except endpoint test secondary client (windows and linux) (not necessarily correct)

* comment out endpoint test secondary endpoint client case to make tests compile

* address todos and comments from meeting

* remove duplicated code for populating address in ep info generation

* update EndpointCreate to support multiple infra nic

* save all endpoints to state, regardless of type, use either stateless or cni statefile

undos some changes in "move create endpoint to network package, remove ifIndex as needed"
deletion flow needs to figure out how to tell if the nic type is delegated
1 interface info : 1 endpoint info : 1 endpoint struct mapping

* fix dual nic support conditional and finding master interface ip

the master interface ip must be in a particular form where the last few bits are zeroed out based on the mask or we won't find the ip
for example, while the host subnet perfix is 10.224.0.113/16, the ip that should be passed into find master interface (subnet) should be 10.224.0.0/16 which matches one of the interfaces' ipnet (10.224.0.0/16)

* fix empty network name
when we need to create a network, we collect the network information, but if we do not find the network, we return an empty nw info and an error
when we create the endpoint we need to use endpoint info's network id, not the (possibly) empty network info struct's network id

* make network_test.go compile (linux and windows compile)

unit tests are not necessarily correct at this point

* add NICType to endpoint struct and populate it

important: when getting the endpoint state, the NIC Type field is not populated, leading to deletes not having a NIC Type; this should be changed so that getting the state populates that field
including the nic type allows us to simplify the secondary endpoints delete flow (just check if the nic type is delegated instead of checking if the secondary interfaces map is populated)

smoke tested:
linux aks podsubnet (same vm, multi vm, internet, cni statefile consistent)
linux standalone transparent vlan multitenancy (same vm, multi vm, internet, multi vnet, no connection between coke pepsi, cni statefile consistent)
windows standalone bridge multitenancy single customer (same vm connections, internet, dns only, cni statefile consistent, 2 pods deleting and recreating)

* ci: InterfaceInfo Map

* fix multitenancy_test ut by changing key

* add endpoint id to secondary ep info test since we populate the id in the actual flow

* fix cni network_test linux and ensure secondary create ep info does not break

in network_test we pass in sample delegated (secondary) data to Add which we then create endpoint info from
even with most fields empty, in linux, the ep info is created without erroring

* make invoker_cns_test linux pass

running all linux package tests for network and cni package pass (or also fail on master, like createBridge)
windows unit tests mostly all fail for the same ones on master and this branch
summary:
	- network_windows_test.go
		○ TestFailToAddIPv6DefaultRoute already fails on master
	- network_test.go
		○ 9 tests fail on master, 9 tests fail on my branch
	- manager_test.go
		○ 9 tests fail on master, 9 tests fail on my branch
	- endpoint_windows_test.go
		○ TestNewAndDeleteEndpointImplHnsV2 already timeouts on master
	- endpoint_test.go
		○ 9 tests fail on  master, 9 tests fail on my branch
	- network_windows_test.go
		○ FAIL: TestPluginSecondAddSamePodWindows/CNI_consecutive_add_already_hot_attached
		○ FAIL: TestPluginSecondAddSamePodWindows/CNI_consecutive_add_not_hot_attached
		○ We don't handle consecutive add anymore
	- network_test.go
		○ TestPluginMultitenancyAdd/Add_Happy_path fails on master and my branch (received multiple NC results [] from CNS while dualnic feature is not supported)-- we still get two items on our list/map though which is expected
	- invoker_cns_test passes
	- invoker_azure_test passes
        - multitenancy_test passes
The consecutive add tests fail but that is expected since we no longer support it.

* modify delete flow to handle multiple epinfos to delete

delete ALL endpoints related to the endpoint infos list in the event cni fails half-way through an add (one failed endpoint create and we delete all would-be-create endpoints and the state)
replace looping over deletion code "n" number of times with getting a slice of endpoint infos to delete
modify stateless cni code to retrieve a slice of network endpoint infos from a single response based on the container id (container id can be used in stateless cni for retrieval)
incorporate stateless cni changes from other branch (cns client/ipam/restserver changes)
modify get endpoint state to return slice of endpoint infos, and getting an endpoint will return an endpoint from that slice with nic type infra
move edge case where endpoint is not created in the state but ips are already allocated to immediately after retrieving all ep infos
fix mock behavior for getting all endpoints by container id
move getting network id and network info out of the loop because their values do not seem to change between iterations
move deletion of endpoint logic into a dedicated loop, and then create a dedicate loop for calling ipam delete to prevent inconsistent state

all expected unit tests on linux pass

* address feedback

* Make change to UpdateEndpointState API to support SwiftV2 for Stateless CNI

* change save state to only call update endpoint state once with a slice of endpoints, uts pass

* fix using nonexistent key by passing in current interface info directly

* fix azure ipam invoker not getting a populated network info for legacy cni

* add L1VH windows support

* add nic type to windows endpoints

* move adding an external interface code to run only when creating a new network

this change reflects prior behavior, where we would only add an external interface to the statefile if the network (after searching through all external interfaces) was not found
currently, if there are multiple interfaces that could be selected as the master, we would add each external interface to the statefile, even if the *network* is associated with one of the existing interfaces
while we would still always find the same network (thanks to having a constant NetworkId, regardless of the external interface), you could get an extra empty external interface in your statefile
this commit should remove that possibility (the extra external interface shouldn't really matter in the first place though because we always select the external interface that has a matching network created on it)
this should be os agnostic

* update comments, first todo check pass

* address some linter issues

* rename networkId to networkID in endpoint info

ran package tests in windows and linux for cni and network packages
ran package tests in linux for cns restserver
all have expected outputs (either pass, or also fails on master branch)

* address linter issues

* preserve more logs and reduce timeout for restart for debugging

* clean comments and rename for clarity

if we use the endpoint info for the network info fields, we name it nwInfo as a hint

* address more linter issues

linux network, restserver, and cni package tests pass

* Revert "preserve more logs and reduce timeout for restart for debugging"

This reverts commit 0f004925cf.

* ignore error on delete flow network query

if we are in stateful cni and do not find the network, we will not error, but when we search for the endpoint it will not be found, leading to us calling ipam invoker delete which is assumed idempotent before returning
previously we would error in stateful cni and return before calling ipam invoker delete

* delete network on endpoint delete if stateless and delegated vmnic (win + linux)

* add nic name, set nicname in linux to master interface name

stateless will key into interface map with the nicname field
in windows, the nicname field is based on the args ifname (usually eth0)
in linux, the nicname field is based on the master interface found (usually eth0)

note:
hostifname/hostvethname = linux veth pair peer in the host ns
ifname/contifname = linux veth pair peer in the container ns, in windows it's just the args ifname
nicname is something else
ifname isn't used during deletion in linux, hns id is used for deletion in windows

* return secondary interface as cni result if no infra nic found, include mac address in cni result

* address linter issue

* fix critical error where failing to add in windows stateless would lead to hns components not being deleted and add netns for hnsv2

tested by triggering a failure to save the stateless state and seeing that the hns endpoint and network are cleaned up
we use the endpoint info to clean up on "add" error, but previously, we didn't populate it with the hns ids to do so

adds netns to stateless as the presence of a valid guid in netns determines if hnsv2 is used

* set nicname used in stateless cni according to feedback

* add dummy guid to stateless delete since we assume stateless is always hnsv2

we assume that the netns value isn't used in stateless deletion

* clean up createEpInfo, declare endpoint info once

* address feedback from vipul

* change comments only

* revert change to cns package

* fix stateless cni migration flow not having nictype on migrate

* keep nwInfo variables named the same as before pr (noop)

* separate endpoint and network policies in endpoint info

behavior should not change except in hnsv1, where network policies passed into network create call will NOT include endpoint policies
endpoint policies always include network policies

* address feedback from reviewers

* address feedback and account for case where cns provides info without nic type

if nic type is empty from cns in invoker cns, we assume it is infra nic type and populate it with infra nic type

* address feedback to declare endpoint info once and populate all fields at once

moved add subnets to after endpoint info created
moved retrieval of all endpoint policies (from getEndpointPolicies and getPoliciesFromRuntimeCfg)until after endpoint info created
network policies are just passed in from the args unaltered

* use ifname instead of nicname field in endpoint struct as key in stateless

* convert macaddress only nictype is delegatedvmnic

* address feedback by removing network dns settings

* address linter issues (noop)

* address feedback and linter (noop)

* remove unused consecutive add funcs (noop)

* fix release ips when create a container without nictype using older cni and then upgrade cni and delete

if we create a pod with an older cni version, it won't have a nictype
if we upgrade cni and then delete, we should treat an empty nictype as an infra nictype and
call the invoker delete

* prevent eps with delegated nic type present on ep from also calling transparent endpoint client on delete

tested on swift v2 linux single pod add, change cni to this version, delete (ok)
then add using this cni version and delete, no extraneous transparent endpoint client calls logged

* mock get interface method for ut

searched for "NetPlugin" in all files and determined all prod use of NetPlugin goes through NewNetPlugin where we set the get interface method to the real interface get method
adds ut where the master interface (by mac) is not found

* address feedback (noop)

* add ut for handling empty nictype on cns add (noop)

* add multitenancy delete net not found ut (noop)

* add uts for multi interface infos single add call, verify endpoint id, cns to cni data conversion and vice versa, get endpoint info from container id (noop)

verifies partial success will delete all endpoints, even successfully created ones in the same cni add call

* add ut for all pods associated with container id delete in one del call, new secondary delete flow (noop)

* add two UTs

* fix a linter issue

* add ut to check endpoint ifname on new endpoint creation based on nictype (noop)

* add ut for fail to find interface by subnet (noop)

* Adding support for Stateless CNI Delete Edge case when there in no HNS ID

* fix uts

* fix linter issues

* fix ut

---------

Co-authored-by: jpayne3506 <payne.3506@gmail.com>
Co-authored-by: paulyufan2 <paulyu01@outlook.com>
Co-authored-by: AzureAhai <behzadm@microsoft.com>
2024-06-01 01:36:32 +00:00
Behzad Mirkhanzadeh 4370e6e93c
feat: Adding MACAddress to CNS endpoint State and refactoring stateless CNI code (#2722)
* Adding MACAddress to CNS endpointState and also refactoring statelss cni code

* Addressing the comments.

* Addressing the comments
2024-05-08 00:07:03 +00:00
Behzad Mirkhanzadeh b22ac38f3e
feat: Migration stateless cni (#2470)
* 🌈 feat: adding flags for stateless cni (#2103)

feat: stateless cni

* feat: create stateless cni binary for swift (#2275)

* enabling CNS telemetry

* CNI Telemetry enabled on CNS

* Code changes for Statefull CNI Migration

* Making changes to the CNI state migration code.

* Make code changes for Stateless CNI migrations.

* Make changes to statless CNI migration branch.

* Stateless CNI migration code changes

* resolving migration issue

* remove cni changes

* Applying changes to CNIReonciler

* Addressing the comments.

* Addressing the comments

* addressing the latest comments

* Addressing Evan's comments

* Adding a MigrateSate() function to the cnireconciler

---------

Co-authored-by: Vipul Singh <vipul21sept@gmail.com>
2024-02-08 23:47:56 +00:00
QxBytes 0c8f78a2f0
refactor: add receiver to iptables and create interface (#2421)
* Move network utils functions with iptables to new file

* Add receiver to iptables and create interface

* Resolve conflicts from rebasing

* Add changes for building on windows

* Address linter issues

* Address windows linter issues

* Invert if condition for linter nesting

* Scope iptables interfaces to package

* Rename iptables client to avoid stuttering

* Move EnableIPForwarding to snat linux

* Rename ipTablesClientInterface to ipTablesClient

* Address linter issues from moving enable ip forwarding function

* Rename after rebase
2023-12-14 09:27:17 -08:00
Jaeryn 4168c62faa
test: validate secondary endpoint client failure (#2345)
test: validate secondary endpoint client failure will prevent endpoint creation

Co-authored-by: Jaeryn <tsch@microsoft.com>
2023-11-03 23:32:40 +00:00
Jaeryn 83fca75334
feat: cni refactor for swift v2 (#2330)
* feat: update contracts to support swift 2

* add comments

* rename AddressType to NICType

* update contract names and comments

* address comments

* feat: update invokers to support swift 2

* address comments

* address comments

* refactor cns invoker per comments

* update invokers based on contract change

* update test

* update with contract changes

* fix linter errs

* fix naming

* fix linter

* fix linter

* address comments

* update tests

* add tests

* address nit comments

* add comments

* address comments

* fix casing

* address comments

* feat: update invokers to support swift 2

* address comments

* feat: update invokers to support swift 2

* feat: update invokers to support swift 2

* feat: update endpoint clients for swift 2

* address comments

* fix lint errs

* update endpoint clients based on contract changes

* update tests

* only skip adding default route

* modify AddEndpoints per comments

* address comments

* update deleteendpoint

* enter ns before moving interface back to vm ns

* update delete endpoint test

* add namespace interface for testing

* fix lint

* fix lint

* add comment

* add extra delete endpoint test

* update test

* feat: update invokers to support swift 2

* address comments

* address comments

* feat: refactor endpoint create/delete flow for swift 2

* address comments

* address comments

* address linter

* update based on contract changes

* update with contract changes

* add more tests and address comments

* modify AddEndpoints per comments

* update test for invoker add and endpoint client add failure

* address comments

* fix lint

* update windows tests

* update refactor with namespace interface

* fix lint

* rebasing fixes

* address comments

---------

Co-authored-by: Jaeryn <tsch@microsoft.com>
2023-11-01 19:50:35 +00:00
Paul Yu ae37d40982
[CNI] zap logger for platform package (#2233)
* zap logger for platform package
2023-10-13 12:08:58 -07:00
Paul Yu 44dc74e5ec
[CNI] Migrate network and platform package logging to zap (#2209)
* network package zap logger

* add zaplogger for platform
2023-09-16 00:14:44 +00:00
Steven Nguyen 672cce9460
update: add pod info to windows endpoint (#2040) 2023-07-05 11:51:48 -07:00
tamilmani1989 a82b312995
Set constant mac for host veth interface in transparent vlan mode (#1906)
* set constant mac for host veth interface

* fixed a race issue in transparent-vlan where delete can happen after add and removes route add by ADD call

* moved log to place where its executed

* enable proxy arp on bridge to allow public connectivity from apipa interface

* validate newly created namespace is not same as host namespace

* addressed comments and added UTs

* fixed cni delete call for linux multitenancy

* lint fixes

* windows lint fixes

* lint fixes

* fix issues with network namespace creation and vlan interface creation

* Removed deletehostveth flag and delete host veth on delete endpoint trigger

* lint fix

* address comment
2023-04-17 14:26:00 -07:00
tamilmani1989 1ec3abdaf9
Delete host veth interface on endpoint creation error in transparent-vlan mode (#1892)
* deletion of host veth interface on error in transparent_vlan mode

* fixed a typo character

* Fix lint issues

* Windows lint fix

* Windows lint fix

* add netio import

* Fixed newly added ut

* reverting pre-push change

* fix a typo
2023-04-13 08:43:44 +00:00
QxBytes ce14b0b6f5
style: Go fumpt entire network package (#1507)
no code changes..so bypassing e2e
2022-08-03 15:09:00 -07:00
tamilmani1989 ba3bbe0f26
Remove azure-vnet-telemetry for windows multitenancy (#1430)
* Remove azure-vne-telemetry for windows multitenancy and telemetry service for windows multitenancy will be started from cns.

* start telemetry service from cns

* lint and log fix

* minor change

* addressed comment
2022-07-01 15:09:39 -07:00
aegal 251edbfd04
Alegal/add timeout to hns calls (#1369)
* initial implemenation with timeout

* initial implemenation with timeout hns

* modify test

* modify code slightly

* updating to read in timeout flag and settings

* updating to read in timeout settings

* remove extra space

* correct a typo

* timeout value greater than zero for detection

* add couple ut's and remove needless code

* including timeout in hnsv1

* wip

* address comments

* address comments

* supress linter errors and update conflist

* fix linter and ensure we don't regress our tests

* updating with p.r feedback

* addressing comments

* updating linter warning

* update to address TM's comments

* fix lint error

* correct a linter spacing complaint

* remove fmt.sprintf
2022-05-25 14:18:46 -07:00
tamilmani1989 6ec42039d7
ignore removenamespace endpoint error (#1272) 2022-03-10 09:58:30 -08:00
Matthew Long 580c3e4072
feat: don't use CNS for CNI DEL command in windows multitenancy (#1216)
* feat: don't use CNS for CNI DEL command in windows multitenancy

* go fmt

* go fmt take 2

* fix: don't fallback to CNS for getNetwork or deleteHostNCApipaEndpoint, handle errNetworkNotFound

* test: add test for FindNetworkIDFromNetNs

* fix: getNetworkName needs to fallback to CNS when not found in state file for ADD

* fix: simplify the deleteHostNCApipaEndpoint function

* fix: linter

* fix: cnm should compile

* fix: always return retriable error for endpoint deletion failure

* fix: handle npe in cns/hnsclient by not using that package

* fix: logging

* fix: don't try cns if there is no multitenancy client

* fix: don't call CNS twice during ADD cmd

* fix: use hns wrapper, add some logging, don't return error when endpoint is already deleted
2022-02-03 19:14:31 -08:00
Jaeryn 01085728bb
fix: Add NAT Policies for Windows AKS-Swift Scenario (#1036)
* Add DNS NAT policy for windows AKS-Swift scenario

* Addressing comments

Co-authored-by: Jaeryn <tsun.chu@microsoft.com>
2021-10-20 13:58:10 -07:00
tamilmani1989 279911c94a
Support for Dualstack transparent (#1046)
* ipv6 dualstack support transparent mode

* golint fixes

* fixed linter errors

* enable ipv6 setting

* dualstack transparent changes

* abstracted platform execute command

* lint fixes
fix compilation issues

* addressed comments

* fixed a bug
2021-10-15 14:28:37 -07:00
tamilmani1989 f9c4b8549a
Set MTU for veths based on VM interface (#1031)
* Set MTU for veths based on VM interface

* ignore setmtu error
2021-09-22 17:28:50 -07:00
aegal 62172a4387
wrap hnsv2 calls and add a test with mocks (#1012)
* feat: update cns client (#992)

* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* Remove dead codes from telemetry package (#1004)

* Netlink package interfacing and adding a fake (#996)

* Initial pass at Netlink interface

* changing some netlink and epc

* Resolcing all dependencies on netlink package

* first pass at adding a netlinkinterface

* windows working now

* feat: update cns client (#992)

* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* windows working now

* Some golints checks

* commenting a flaky NPM UT and adding some golint checks

* renaming fakenetlink to mocknetlink

* removing a mock netlink usage

* fixing more golints and a test fix

* fixing more go lints

* Adding in netlink from higher level as input

* adding netlinkinterface to windows endpoint impl

* removing netlink name confusion

Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>

* wrap hns calls

* correct delete endpoint test

* tag with windows

* change uuid for fake

* change parameter name to be relevant

* update to add comment and fix build tag

* include build tag on wrapper

* correct merge conflict error

Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>
Co-authored-by: JungukCho <jungukcho@microsoft.com>
Co-authored-by: Vamsi Kalapala <vakr@microsoft.com>
2021-09-21 10:39:01 -06:00
tamilmani1989 99a856982c
cni/network unit test coverage (#1020)
* adding uts

* feat: update cns client (#992)

* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* Remove dead codes from telemetry package (#1004)

* Netlink package interfacing and adding a fake (#996)

* Initial pass at Netlink interface

* changing some netlink and epc

* Resolcing all dependencies on netlink package

* first pass at adding a netlinkinterface

* windows working now

* feat: update cns client (#992)

* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* windows working now

* Some golints checks

* commenting a flaky NPM UT and adding some golint checks

* renaming fakenetlink to mocknetlink

* removing a mock netlink usage

* fixing more golints and a test fix

* fixing more go lints

* Adding in netlink from higher level as input

* adding netlinkinterface to windows endpoint impl

* removing netlink name confusion

Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>

* test: add tests for CNI Azure invoker (#1010)

* include add tests

* test delete

* gci

* chore: Refactor UTs in telemetry packages (#1011)

* Refactor UTs to cleanup UTs and increase UT coverages

* User assert for consistency

* Applied comments and resolve lint error

* Delete unnecessary license header

* Add UT coverage ovs_network_client (#1008)

* Added ovsctl mock
* Changed iptables and ovsctl to use interface instead of concrete
  classes
* Added tests for ovs_networkclient_linux.go
* Fix linter issues

Co-authored-by: Shriroop <shrjo@microsoft.com>

* unitest for add, delete, get
added test for handling second add call in windows
added linux and windows specific tests
added multitenancy, baremetal tests
fixed linter errors

* fix linter issue

* fix nns test
added comment
linter fixes and dependency injection from top

* adding back removed file
fixed merge issues

* linter fixes

Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>
Co-authored-by: JungukCho <jungukcho@microsoft.com>
Co-authored-by: Vamsi Kalapala <vakr@microsoft.com>
Co-authored-by: Mathew Merrick <matmerr@users.noreply.github.com>
Co-authored-by: Shriroop Joshi <shriroopjoshi@users.noreply.github.com>
Co-authored-by: Shriroop <shrjo@microsoft.com>
2021-09-20 16:58:18 -07:00
tamilmani1989 2bd3c74811
Netlink package interfacing and adding a fake (#996) (#1025)
* Initial pass at Netlink interface

* changing some netlink and epc

* Resolcing all dependencies on netlink package

* first pass at adding a netlinkinterface

* windows working now

* feat: update cns client (#992)

* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* windows working now

* Some golints checks

* commenting a flaky NPM UT and adding some golint checks

* renaming fakenetlink to mocknetlink

* removing a mock netlink usage

* fixing more golints and a test fix

* fixing more go lints

* Adding in netlink from higher level as input

* adding netlinkinterface to windows endpoint impl

* removing netlink name confusion

Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>

Co-authored-by: Vamsi Kalapala <vakr@microsoft.com>
Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>
2021-09-20 13:57:12 -05:00
Evan Baker 69abf11d4c
feat: update cns client (#992)
* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
2021-09-14 12:56:32 -05:00
Mathew Merrick 1fa243e5f5
CI: Add golint-ci (#888)
* add golint-ci

* add gofmt

* enable linters

* uncap count

* fix linting/fmt issues
2021-06-01 16:58:56 -07:00
Ramiro 33a1dd5070 handling endpoint not found in hns delete 2020-11-12 06:14:06 -08:00
tamilmani1989 aed0d716b9
Azure CNI Windows dualstack support (#557)
* windows ipv6 changes

* addressed compilation issues

* return fix

* type error

* updated pipeline.yaml

* removed -mod=vendor

* updated pipeline yaml

* fixed pipeline.yaml

* fixed pipeline.yaml

* updated function name as per comment
2020-05-07 11:40:46 -07:00
jaer-tsun 43d2c684d1
Setup SNAT Configuration Based on Azure Host Support (#401)
* Save enable snat on host settings after querying NMagent version

* Adding changes to exclude outbound snat for win cni if new NMAgent is running

* try to acquire lock file when writing to disableSnatOnHost.json

* addressed some of Tamilmani's comments

* Adding snat for DNS if current NMAgent does not support it yet

* Adding DNS NAT changes for Windows CNI

* vendoring HCSShim changes that support destination based SNATing

* Reverting k8s.io/api dependencies from master branch to last working version

* Addressing Tamilmani's comments

* syncing with an older version of k8s.io dependencies

* verify valid windows version before Dns NAT.

* only remove snat on windows when host has full support

* addressing Tamilmani's comments

* addressing Tamilmani's comments

* rebased and re-depped
2019-11-14 12:01:04 -08:00
Ashvin Deodhar 84fb35b545
Add Host NC communication support in Windows with HnsV2 (#424)
This PR adds support for host NC bidirectional communication with windows HnsV2. This is supported in multitenant scenario only. AllowHostToNCCommunication and AllowNCToHostCommunication flags are used to enable Host to NC and NC to host communication respectively.
2019-10-18 13:12:03 -07:00
Ashvin Deodhar edd2ae7c8b
Support hyper-v and process based containers with cricontainerd (*COW) (#417)
Support hyper-v and process based containers with cricontainerd (*COW)
2019-10-18 06:58:27 -07:00
Ashvin Deodhar e28f5836d0
Skip HotAttachEp from CNM createEndpoint (#332)
* Skip HotAttachEp from CNM create endpoint

* Address review comments
2019-04-12 16:17:45 -07:00
Ashvin Deodhar 3f1216ef26 Fix Endpoint policy regression (#268)
Fix endpoint policy regression
2018-11-20 10:51:18 -08:00
Ashvin Deodhar bfb3eaafa7 Implement multitenancy for windows (#259)
* Implement multitenancy for windows
2018-10-31 14:34:04 -07:00
Sushant Sharma 6e6260afe5 Implement CNI update for Azure CNI (#265)
* Implement CNI Update for Azure CNI (#21)
2018-10-29 11:10:27 -07:00
John Howard a386846345 Store fixes; Windows compile
Signed-off-by: John Howard <jhoward@microsoft.com>

- First, the store timeout is woefully low. Bumped to 20 seconds from 2 seconds.
  This may fix https://github.com/Azure/azure-container-networking/issues/242#issuecomment-422701838
  IMO, as only test code calls it non-blocked, why even have a block parameter to Lock()?
  IMO also, why a timeout at all? They're always fraught with error and machine timing.

- Presence of a key should be checked using `raw, ok := hvs.data[key]`, not the current nil checked

- ErrKeyNotFound should be returned if the store file does not exist. It shouldn't ignore that error.

- Actually now reports if a timeout occurred correctly, along with non-block lock attempt when already locked.

- Serial pattern abuse in not always closing the lock file.

- Some golang correctness (errors should be lower case)

- go build ./... actually passes on Windows now - various compile errors previously.

- golang pattern conformance `if err:=<test>; err!=nil {....`

- Simplified timeout duration (no need for time.Duration(...))
2018-09-19 15:30:36 -07:00
tamilmani1989 3ea96edae3 Update Windows CNI implementation to free resources in case of HNS failures (#223)
Update Windows CNI implementation to free resources in case of HNS failures
2018-08-09 16:54:10 -07:00
Yongli Chen 27e10e8ff8 handle empty string (#213) 2018-08-01 16:08:50 -07:00
tamilmani1989 59ae2cd9c4 Fixed constructing endpointID (#210) 2018-07-24 17:46:46 -07:00
ashvindeodhar 54be5fed60 azure-vnet: Implement GET command as per CNI 0.4.0 spec (#161)
* azure-vnet: Implement GET command
2018-06-01 17:48:19 -07:00
Yongli Chen f1f65e73e9 moves cni related code from network package to cni. (#129)
* configure dnssuffix & dnsServerList

* add dns info to conflist

* change case for dns info

* remove hardcoding

* remove hardcoding

* parse k8s pod info

* add AdditionalArgs and Dns info to conflist

* serialize policies

* program route info

* start addressign ipam ip leak

* fix 1) ip inconsistency in k8s & pod. 2) IP leak in IPAM.

* remove comments

* separate windows & linux

* remove dnsServers

* remove comments

* address comments

* add dns verification

* abstract linux policy struct

* remove setPolicies

* separte Windows & Linux code
2018-05-03 15:48:30 -07:00
Yongli Chen 0bbce8daa9 Support k8s DNS & endpoint policy (#127)
* configure dnssuffix & dnsServerList

* add dns info to conflist

* change case for dns info

* remove hardcoding

* remove hardcoding

* parse k8s pod info

* add AdditionalArgs and Dns info to conflist

* serialize policies

* program route info

* start addressign ipam ip leak

* fix 1) ip inconsistency in k8s & pod. 2) IP leak in IPAM.

* remove comments

* separate windows & linux

* remove dnsServers

* remove comments

* address comments

* add dns verification

* abstract linux policy struct

* remove setPolicies
2018-05-03 14:57:31 -07:00
Yongli Chen 4bc51cc22c Update endpoint creation in CNI for Windows containers. (#86)
Enable outboundNAT for Windows containers.
Handle consecutive ADD calls for the same container.
Handle attach endpoint for workload containers.
2017-12-28 11:47:46 -08:00
Onur Filiz 672ddf2ef2 Implement CNM GetEndpointInfo on Windows 2017-05-17 13:36:57 -07:00
Onur Filiz 2738f04ae6 Store the gateway address from HNS response in endpoints on Windows 2017-05-05 14:07:35 -07:00
Onur Filiz 3bbcd0fd26 Add support for multiple subnets and gateways per network 2017-03-10 13:53:37 -08:00