azure-container-networking/network/network_windows_test.go

599 строки
15 KiB
Go
Исходник Обычный вид История

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 19:39:01 +03:00
// Copyright 2017 Microsoft. All rights reserved.
// MIT License
//go:build windows
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 19:39:01 +03:00
// +build windows
package network
import (
"errors"
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 19:39:01 +03:00
"fmt"
"net"
"strings"
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 19:39:01 +03:00
"testing"
"time"
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 19:05:28 +03:00
"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/network/hnswrapper"
"github.com/Azure/azure-container-networking/platform"
"github.com/Microsoft/hcsshim/hcn"
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 19:39:01 +03:00
)
var (
errTestFailure = errors.New("test failure")
failedCaseReturn = "false"
succededCaseReturn = "true"
)
func TestNewAndDeleteNetworkImplHnsV2(t *testing.T) {
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 19:39:01 +03:00
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
// this hnsv2 variable overwrites the package level variable in network
// we do this to avoid passing around os specific objects in platform agnostic code
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
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 19:39:01 +03:00
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
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 19:39:01 +03:00
MasterIfName: "eth0",
Mode: "bridge",
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 19:39:01 +03:00
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
network, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
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 19:39:01 +03:00
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
if network.HnsId == "" {
t.Fatal("hns network id not populated in network struct")
}
if nwInfo.HNSNetworkID == "" {
t.Fatal("hns network id not populated")
}
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 19:39:01 +03:00
err = nm.deleteNetworkImplHnsV2(network)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
}
func TestSuccesfulNetworkCreationWhenAlreadyExists(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
// this hnsv2 variable overwrites the package level variable in network
// we do this to avoid passing around os specific objects in platform agnostic code
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
network := &hcn.HostComputeNetwork{
Name: "azure-vlan1-172-28-1-0_24",
}
_, err := Hnsv2.CreateNetwork(network)
// network name is derived from network info id
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "azure-vlan1-172-28-1-0_24",
MasterIfName: "eth0",
Mode: "bridge",
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
_, err = nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
}
func TestNewNetworkImplHnsV2WithTimeout(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
hnsFake := hnswrapper.NewHnsv2wrapperFake()
hnsFake.Delay = 15 * time.Second
Hnsv2 = hnswrapper.Hnsv2wrapperwithtimeout{
Hnsv2: hnsFake,
HnsCallTimeout: 10 * time.Second,
}
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
_, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err == nil {
t.Fatal("Failed to timeout HNS calls for creating network")
}
}
func TestDeleteNetworkImplHnsV2WithTimeout(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
network, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
hnsFake := hnswrapper.NewHnsv2wrapperFake()
hnsFake.Delay = 10 * time.Second
Hnsv2 = hnswrapper.Hnsv2wrapperwithtimeout{
Hnsv2: hnsFake,
HnsCallTimeout: 5 * time.Second,
}
err = nm.deleteNetworkImplHnsV2(network)
if err == nil {
t.Fatal("Failed to timeout HNS calls for deleting network")
}
}
func TestNewNetworkImplHnsV1WithTimeout(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
hnsFake := hnswrapper.NewHnsv1wrapperFake()
hnsFake.Delay = 10 * time.Second
Hnsv1 = hnswrapper.Hnsv1wrapperwithtimeout{
Hnsv1: hnsFake,
HnsCallTimeout: 5 * time.Second,
}
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
_, err := nm.newNetworkImplHnsV1(nwInfo, extInterface)
if err == nil {
t.Fatal("Failed to timeout HNS calls for creating network")
}
}
func TestDeleteNetworkImplHnsV1WithTimeout(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
Hnsv1 = hnswrapper.NewHnsv1wrapperFake()
network, err := nm.newNetworkImplHnsV1(nwInfo, extInterface)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
hnsFake := hnswrapper.NewHnsv1wrapperFake()
hnsFake.Delay = 10 * time.Second
Hnsv1 = hnswrapper.Hnsv1wrapperwithtimeout{
Hnsv1: hnsFake,
HnsCallTimeout: 5 * time.Second,
}
err = nm.deleteNetworkImplHnsV1(network)
if err == nil {
t.Fatal("Failed to timeout HNS calls for deleting network")
}
}
func TestAddIPv6DefaultRoute(t *testing.T) {
_, ipnetv4, _ := net.ParseCIDR("10.240.0.0/12")
_, ipnetv6, _ := net.ParseCIDR("fc00::/64")
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
plClient: platform.NewMockExecClient(false),
}
networkSubnetInfo := []SubnetInfo{
{
Family: platform.AfINET,
Gateway: net.ParseIP("10.240.0.1"),
Prefix: *ipnetv4,
},
{
Family: platform.AfINET6,
Gateway: net.ParseIP("fc00::1"),
Prefix: *ipnetv6,
},
}
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3f97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
Subnets: networkSubnetInfo,
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
// check if network can be successfully created
_, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err != nil {
t.Fatalf("Failed to create network due to error:%+v", err)
}
}
func TestFailToAddIPv6DefaultRoute(t *testing.T) {
_, ipnetv4, _ := net.ParseCIDR("10.240.0.0/12")
_, ipnetv6, _ := net.ParseCIDR("fc00::/64")
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
plClient: platform.NewMockExecClient(true), // return mock exec error
}
networkSubnetInfo := []SubnetInfo{
{
Family: platform.AfINET,
Gateway: net.ParseIP("10.240.0.1"),
Prefix: *ipnetv4,
},
{
Family: platform.AfINET6,
Gateway: net.ParseIP("fc00::1"),
Prefix: *ipnetv6,
},
}
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 0f004925cfb37a4594df63a4259242c37cf07785. * 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 04:36:32 +03:00
nwInfo := &EndpointInfo{
NetworkID: "d3f97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
Subnets: networkSubnetInfo,
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
// check if network is failed to create
_, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err == nil {
t.Fatal("Network should not be created")
}
}
func TestAddIPv6DefaultRouteHappyPath(t *testing.T) {
mockExecClient := platform.NewMockExecClient(false)
nm := &networkManager{
plClient: mockExecClient,
}
// happy path
mockExecClient.SetPowershellCommandResponder(func(cmd string) (string, error) {
if strings.Contains(cmd, "Get-NetIPInterface") || strings.Contains(cmd, "Remove-NetRoute") {
return succededCaseReturn, nil
}
// fail secondary command execution and successfully execute remove-netRoute command
if strings.Contains(cmd, "Get-NetRoute") {
return failedCaseReturn, errTestFailure
}
return "", nil
})
err := nm.addIPv6DefaultRoute()
if err != nil {
t.Fatal("Failed to test happy path")
}
}
func TestAddIPv6DefaultRouteUnhappyPathGetNetInterface(t *testing.T) {
mockExecClient := platform.NewMockExecClient(false)
nm := &networkManager{
plClient: mockExecClient,
}
// failed to execute Get-NetIPInterface command to find interface index
mockExecClient.SetPowershellCommandResponder(func(cmd string) (string, error) {
if strings.Contains(cmd, "Get-NetIPInterface") {
return failedCaseReturn, errTestFailure
}
return "", nil
})
err := nm.addIPv6DefaultRoute()
if err == nil {
t.Fatal("Failed to test unhappy path with failing to execute get-netIPInterface command")
}
}
func TestAddIPv6DefaultRouteUnhappyPathAddRoute(t *testing.T) {
mockExecClient := platform.NewMockExecClient(false)
nm := &networkManager{
plClient: mockExecClient,
}
mockExecClient.SetPowershellCommandResponder(func(cmd string) (string, error) {
if strings.Contains(cmd, "Get-NetIPInterface") {
return succededCaseReturn, nil
}
// fail secondary command execution and failed to execute remove-netRoute command
if strings.Contains(cmd, "Get-NetRoute") {
return failedCaseReturn, errTestFailure
}
if strings.Contains(cmd, "Remove-NetRoute") {
return failedCaseReturn, errTestFailure
}
return "", nil
})
err := nm.addIPv6DefaultRoute()
if err == nil {
t.Fatal("Failed to test unhappy path with failing to add default route command")
}
}
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 19:05:28 +03:00
func TestNewNetworkImplHnsV2ForBackendNIC(t *testing.T) {
pnpID := "PCI\\VEN_15B3&DEV_101C&SUBSYS_000715B3&REV_00\\5&8c5acce&0&0"
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
plClient: platform.NewMockExecClient(false),
}
nwInfo := &EndpointInfo{
NetworkID: "d3f97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "ib1",
Mode: "transparent",
NICType: cns.BackendNIC,
PnPID: pnpID,
}
extInterface := &externalInterface{
Name: "eth1",
}
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
// should return nil if nicType is BackendNIC when creating network
network, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if network != nil || err != nil {
t.Fatal("HNS network is created with BackendNIC interface")
}
}
// mock hns network creation and deletion for DelegatedNIC
func TestNewAndDeleteNetworkImplHnsV2ForDelegated(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
// this hnsv2 variable overwrites the package level variable in network
// we do this to avoid passing around os specific objects in platform agnostic code
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
NICType: cns.NodeNetworkInterfaceFrontendNIC,
MacAddress: net.HardwareAddr("12:34:56:78:9a:bc"),
}
extInterface := &externalInterface{
Name: "eth0",
Subnets: []string{"subnet1", "subnet2"},
}
network, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
err = nm.deleteNetworkImpl(network, cns.NodeNetworkInterfaceFrontendNIC)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
}
func TestSkipNetworkDeletion(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
// should return nil if nicType is Backend
err := nm.deleteNetworkImpl(nil, cns.BackendNIC)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
}
func TestTransparentNetworkCreationForDelegated(t *testing.T) {
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
// this hnsv2 variable overwrites the package level variable in network
// we do this to avoid passing around os specific objects in platform agnostic code
Hnsv2 = hnswrapper.NewHnsv2wrapperFake()
nwInfo := &EndpointInfo{
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
Mode: "bridge",
NICType: cns.NodeNetworkInterfaceFrontendNIC,
}
extInterface := &externalInterface{
Name: "eth1",
Subnets: []string{"subnet1", "subnet2"},
}
_, err := nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err != nil {
fmt.Printf("+%v", err)
t.Fatal(err)
}
// create a network again with same name and it should return error for transparent network
_, err = nm.newNetworkImplHnsV2(nwInfo, extInterface)
if err == nil {
t.Fatal("network creation does not return error")
}
}
// Test Configure HNC network for infraNIC ensuring the hcn network type is always l2 bridge
func TestConfigureHCNNetworkInfraNIC(t *testing.T) {
expectedHcnNetworkType := hcn.L2Bridge
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
extIf := externalInterface{
Name: "eth0",
}
nwInfo := &EndpointInfo{
AdapterName: "eth0",
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth0",
NICType: cns.InfraNIC,
IfIndex: 1,
EndpointID: "753d3fb6-e9b3-49e2-a109-2acc5dda61f1",
ContainerID: "545055c2-1462-42c8-b222-e75d0b291632",
NetNsPath: "fakeNameSpace",
IfName: "eth0",
Data: make(map[string]interface{}),
EndpointDNS: DNSInfo{
Suffix: "10.0.0.0",
Servers: []string{"10.0.0.1, 10.0.0.2"},
Options: nil,
},
HNSNetworkID: "853d3fb6-e9b3-49e2-a109-2acc5dda61f1",
}
hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf)
if err != nil {
t.Fatalf("Failed to configure hcn network for infraNIC interface due to: %v", err)
}
if hostComputeNetwork.Type != expectedHcnNetworkType {
t.Fatalf("Host network mode is not configured as %v mode when interface NIC type is infraNIC", expectedHcnNetworkType)
}
}
// Test Configure HCN Network for Swiftv2 DelegatedNIC HostComputeNetwork fields
func TestConfigureHCNNetworkSwiftv2DelegatedNIC(t *testing.T) {
expectedSwiftv2NetworkMode := hcn.Transparent
expectedSwifv2NetworkFlags := hcn.EnableNonPersistent | hcn.DisableHostPort | hcn.EnableIov
nm := &networkManager{
ExternalInterfaces: map[string]*externalInterface{},
}
extIf := externalInterface{
Name: "eth1",
}
nwInfo := &EndpointInfo{
AdapterName: "eth1",
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
MasterIfName: "eth1",
Mode: "bridge",
NICType: cns.NodeNetworkInterfaceFrontendNIC,
}
hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf)
if err != nil {
t.Fatalf("Failed to configure hcn network for delegatedVMNIC interface due to: %v", err)
}
if hostComputeNetwork.Type != expectedSwiftv2NetworkMode {
t.Fatalf("host network mode is not configured as %v mode when interface NIC type is delegatedVMNIC", expectedSwiftv2NetworkMode)
}
// make sure network type is transparent and flags is 9224
// TODO: check if this is expected for both delegated&accelnet
if hostComputeNetwork.Flags != expectedSwifv2NetworkFlags {
t.Fatalf("host network flags is not configured as %v when interface NIC type is delegatedVMNIC", expectedSwifv2NetworkFlags)
}
}