diff --git a/Golang_Ubuntu_Dockerfile b/Golang_Ubuntu_Dockerfile index a4d9109..0872dc4 100644 --- a/Golang_Ubuntu_Dockerfile +++ b/Golang_Ubuntu_Dockerfile @@ -80,6 +80,8 @@ ARG D_OFED_URL_PATH="${D_OFED_BASE_URL}/${D_OFED_SRC_ARCHIVE}" # although argum ENV NVIDIA_NIC_DRIVER_PATH="${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSION}" WORKDIR /root +RUN set -x && \ + apt-get update RUN set -x && \ echo $D_OS | grep "ubuntu20.04" || GCC_VER="-12" && \ # Install prerequirements \ diff --git a/entrypoint/go.mod b/entrypoint/go.mod index e9045ea..f27b3a7 100644 --- a/entrypoint/go.mod +++ b/entrypoint/go.mod @@ -5,7 +5,9 @@ go 1.24.0 require ( github.com/go-logr/logr v1.4.3 github.com/gofrs/flock v0.12.1 + github.com/k8snetworkplumbingwg/sriovnet v1.2.0 github.com/stretchr/testify v1.11.1 + github.com/vishvananda/netlink v1.2.1-beta.2 go.uber.org/zap v1.27.0 ) @@ -15,9 +17,12 @@ require ( github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect + github.com/google/uuid v1.1.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect + github.com/spf13/afero v1.9.4 // indirect github.com/stretchr/objx v0.5.2 // indirect + github.com/vishvananda/netns v0.0.4 // indirect go.uber.org/automaxprocs v1.6.0 // indirect go.uber.org/multierr v1.10.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect diff --git a/entrypoint/go.sum b/entrypoint/go.sum index 89b5acb..0c5d986 100644 --- a/entrypoint/go.sum +++ b/entrypoint/go.sum @@ -1,9 +1,67 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA= github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= @@ -12,28 +70,121 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/k8snetworkplumbingwg/sriovnet v1.2.0 h1:6ELfAxCB1dvosGUy3DVRmfH+HWTzmPD3W67HKQvMR1M= +github.com/k8snetworkplumbingwg/sriovnet v1.2.0/go.mod h1:jyWzGe6ZtYiPq6ih6aXCOy6mZ49Y9mNyBOLBBXnli+k= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/onsi/ginkgo/v2 v2.25.3 h1:Ty8+Yi/ayDAGtk4XxmmfUy4GabvM+MegeB4cDLRi6nw= github.com/onsi/ginkgo/v2 v2.25.3/go.mod h1:43uiyQC4Ed2tkOzLsEYm7hnrb7UJTWHYNsuy3bG/snE= github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A= github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/spf13/afero v1.9.4 h1:Sd43wM1IWz/s1aVXdOBkjJvuP8UdyqioeE4AmM0QsBs= +github.com/spf13/afero v1.9.4/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs= +github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= +github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= +github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -44,18 +195,307 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A= google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/entrypoint/internal/entrypoint/entrypoint.go b/entrypoint/internal/entrypoint/entrypoint.go index 4de87f6..c7f5070 100644 --- a/entrypoint/internal/entrypoint/entrypoint.go +++ b/entrypoint/internal/entrypoint/entrypoint.go @@ -29,6 +29,8 @@ import ( "github.com/Mellanox/doca-driver-build/entrypoint/internal/constants" "github.com/Mellanox/doca-driver-build/entrypoint/internal/driver" "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/netlink" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/sriovnet" "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/cmd" "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/host" "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/ready" @@ -56,7 +58,7 @@ func Run(signalCh chan os.Signal, log logr.Logger, containerMode string, cfg con host: hostHelper, cmd: cmdHelper, os: osWrapper, - netconfig: netconfig.New(), + netconfig: netconfig.New(cmdHelper, osWrapper, hostHelper, sriovnet.New(), netlink.New()), drivermgr: driver.New(containerMode, cfg, cmdHelper, hostHelper, osWrapper), } return m.run(signalCh) diff --git a/entrypoint/internal/netconfig/netconfig.go b/entrypoint/internal/netconfig/netconfig.go index 40c9780..6192c0d 100644 --- a/entrypoint/internal/netconfig/netconfig.go +++ b/entrypoint/internal/netconfig/netconfig.go @@ -16,11 +16,62 @@ package netconfig -import "context" +import ( + "context" + "encoding/json" + "fmt" + "net" + "regexp" + "strconv" + "strings" + "time" + + "github.com/go-logr/logr" + + "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/netlink" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/sriovnet" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/cmd" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/host" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/wrappers" +) + +// Constants for device types and states +const ( + devTypeIB = "ib" + devTypeEth = "eth" + adminStateUp = "up" + adminStateDown = "down" + eswitchModeLegacy = "legacy" + eswitchModeSwitchdev = "switchdev" + defaultDriverPath = "/sys/bus/pci/drivers/mlx5_core" +) + +// JSON structures for parsing ip command output +type VFInfo struct { + Address string `json:"address"` + PortGUID string `json:"port guid"` +} + +type LinkInfo struct { + VFinfoList []VFInfo `json:"vfinfo_list"` +} // New initialize default implementation of the netconfig.Interface. -func New() Interface { - return &netconfig{} +func New( + cmdHelper cmd.Interface, + osWrapper wrappers.OSWrapper, + hostHelper host.Interface, + sriovnetLib sriovnet.Lib, + netlinkLib netlink.Lib, +) Interface { + return &netconfig{ + cmd: cmdHelper, + os: osWrapper, + host: hostHelper, + sriovnetLib: sriovnetLib, + netlinkLib: netlinkLib, + mellanoxDevices: make(map[string]*MellanoxDevice), + } } // Interface is the interface exposed by the netconfig package. @@ -33,14 +84,1473 @@ type Interface interface { Restore(ctx context.Context) error } -type netconfig struct{} +// VF represents a Virtual Function with all its attributes +type VF struct { + // VF identification + VFIndex int // VF index (0-based) + VFPCIAddr string // VF PCI address (e.g., "0000:08:00.2") + VFName string // VF netdev name (e.g., "eth6") + + // VF configuration + AdminState string // VF admin state: "up" or "down" + MACAddress string // VF hardware MAC address + AdminMAC string // VF administrative MAC address + MTU int // VF MTU value + GUID string // VF GUID (for IB) or "-" for Ethernet +} -// Save is the default implementation of the netconfig.Interface. +// Representor represents a switchdev representor device +type Representor struct { + // Representor identification + PhysSwitchID string // Physical switch ID + PhysPortNum string // Physical port number + VFID string // VF ID + Name string // Representor netdev name + + // Representor configuration + AdminState string // Representor admin state: "up" or "down" + MTU int // Representor MTU value +} + +// MellanoxDevice represents a Mellanox network device with all its attributes +type MellanoxDevice struct { + // Basic device information + PCIAddr string // PCI address (e.g., "0000:08:00.0") + DevType string // Device type: "eth" or "ib" + AdminState string // Admin state: "up" or "down" + MTU int // MTU value + GUID string // Device GUID (for IB) or "-" for Ethernet + EswitchMode string // Eswitch mode: "legacy" or "switchdev" + + // SRIOV information + PfNumVfs int // Number of VFs configured (from sriov_numvfs) + VFs []VF // Array of VF information + Representors []Representor // Array of representor information (for switchdev mode) +} + +type netconfig struct { + cmd cmd.Interface + os wrappers.OSWrapper + host host.Interface + sriovnetLib sriovnet.Lib + netlinkLib netlink.Lib + + // In-memory storage - Mellanox device information + mellanoxDevices map[string]*MellanoxDevice +} + +// Save discovers and stores the current SRIOV configuration func (n *netconfig) Save(ctx context.Context) error { + log := logr.FromContextOrDiscard(ctx) + log.Info("Saving SRIOV configuration") + + // Check if mlx5_core driver is loaded + mlx5CoreLoaded, err := n.isMlx5CoreLoaded(ctx) + if err != nil { + return fmt.Errorf("failed to check if mlx5_core is loaded: %w", err) + } + + if !mlx5CoreLoaded { + log.Info("mlx5_core driver not loaded, skipped store netdev conf info") + return nil + } + + // Clear existing configuration + n.mellanoxDevices = make(map[string]*MellanoxDevice) + + // Discover Mellanox devices + devices, err := n.discoverMellanoxDevices(ctx) + if err != nil { + return fmt.Errorf("failed to discover Mellanox devices: %w", err) + } + + if len(devices) == 0 { + log.Info("No Mellanox devices found, skipping SRIOV configuration") + return nil + } + + // Discover switchdev representors for devices in switchdev mode + if err := n.discoverSwitchdevRepresentors(ctx); err != nil { + log.Error(err, "Failed to discover switchdev representors") + return fmt.Errorf("failed to discover switchdev representors: %w", err) + } + + log.Info("SRIOV configuration saved successfully", "devices", len(n.mellanoxDevices)) return nil } -// Restore is the default implementation of the netconfig.Interface. +// Restore restores the saved SRIOV configuration func (n *netconfig) Restore(ctx context.Context) error { + log := logr.FromContextOrDiscard(ctx) + log.Info("Restoring SRIOV configuration") + + if len(n.mellanoxDevices) == 0 { + log.Info("No SRIOV configuration to restore") + return nil + } + + // Restore each device + for devName, device := range n.mellanoxDevices { + log.Info("Restoring SRIOV config for device", "device", devName, "vfs", device.PfNumVfs) + + // Skip devices with no VFs configured + if device.PfNumVfs == 0 { + log.V(1).Info("Device has no VFs configured, skipping", "device", devName) + continue + } + + // Restore PF and VF configuration + if err := n.restoreDeviceConfig(ctx, devName, device); err != nil { + log.Error(err, "Failed to restore device config", "device", devName) + continue + } + + log.Info("Successfully restored SRIOV config for device", "device", devName, "vfs", device.PfNumVfs) + } + + log.Info("SRIOV configuration restored successfully") + return nil +} + +// restoreDeviceConfig restores the configuration for a single device and its VFs +func (n *netconfig) restoreDeviceConfig(ctx context.Context, devName string, device *MellanoxDevice) error { + log := logr.FromContextOrDiscard(ctx) + + // Get the current device name (might have changed after driver reload) + currentDevName, err := n.getCurrentDeviceName(device.PCIAddr) + if err != nil { + return fmt.Errorf("failed to get current device name: %w", err) + } + + log.Info("Restoring device config", "original_name", devName, "current_name", currentDevName, "pci", device.PCIAddr) + + // Handle switchdev mode (set to legacy first if needed) + // To support the old kernel versions, we need to follow the recommended way of creating switchdev VFs + // 1) Set the NIC in legacy mode + // 2) Create the required amount of VFs + // 3) Unbind all of the VFs + // 4) Set the NIC in switchdev mode + if device.EswitchMode == eswitchModeSwitchdev { + if err := n.setEswitchMode(ctx, device.PCIAddr, eswitchModeLegacy); err != nil { + log.Error(err, "Failed to set eswitch mode to legacy", "device", currentDevName) + return err + } + } + + // Restore PF admin state + if err := n.setDeviceAdminState(currentDevName, device.AdminState); err != nil { + log.Error(err, "Failed to set PF admin state", "device", currentDevName, "state", device.AdminState) + return err + } + + // Create VFs + if err := n.createVFs(device.PCIAddr, device.PfNumVfs); err != nil { + log.Error(err, "Failed to create VFs", "device", currentDevName, "vfs", device.PfNumVfs) + return err + } + + // Restore VF configurations (but don't rebind VFs if in switchdev mode) + if err := n.restoreVFConfigurations(ctx, currentDevName, device, device.EswitchMode); err != nil { + log.Error(err, "Failed to restore VF configurations", "device", currentDevName) + return err + } + + // Set switchdev mode if needed + if device.EswitchMode == eswitchModeSwitchdev { + if err := n.setEswitchMode(ctx, device.PCIAddr, eswitchModeSwitchdev); err != nil { + log.Error(err, "Failed to set eswitch mode to switchdev", "device", currentDevName) + return err + } + + // Rebind VFs in switchdev mode + if err := n.rebindVFsInSwitchdevMode(ctx, device); err != nil { + log.Error(err, "Failed to rebind VFs in switchdev mode", "device", currentDevName) + return err + } + } + + // Restore PF MTU + if err := n.setDeviceMTU(currentDevName, device.MTU); err != nil { + log.Error(err, "Failed to set PF MTU", "device", currentDevName, "mtu", device.MTU) + return err + } + + // Restore representors if in switchdev mode + if device.EswitchMode == eswitchModeSwitchdev && len(device.Representors) > 0 { + if err := n.restoreRepresentors(ctx, currentDevName, device); err != nil { + log.Error(err, "Failed to restore representors", "device", currentDevName) + // Don't fail the entire restore for representor issues + } + } + + return nil +} + +// getCurrentDeviceName gets the current device name after driver reload +func (n *netconfig) getCurrentDeviceName(pciAddr string) (string, error) { + // Get device name from PCI path: /sys/bus/pci/devices/{pci_addr}/net/ + pciDevPath := fmt.Sprintf("/sys/bus/pci/devices/%s/net", pciAddr) + entries, err := n.os.ReadDir(pciDevPath) + if err != nil { + return "", err + } + + if len(entries) == 0 { + return "", fmt.Errorf("no netdev found for PCI address %s", pciAddr) + } + + return entries[0].Name(), nil +} + +// setEswitchMode sets the eswitch mode for a device +func (n *netconfig) setEswitchMode(ctx context.Context, pciAddr, mode string) error { + // Use devlink command: devlink dev eswitch set pci/{pci_addr} mode {mode} + _, stderr, err := n.cmd.RunCommand(ctx, "devlink", "dev", "eswitch", "set", fmt.Sprintf("pci/%s", pciAddr), "mode", mode) + if err != nil { + return fmt.Errorf("failed to set eswitch mode to %s: %w, stderr: %s", mode, err, stderr) + } + return nil +} + +// setDeviceAdminState sets the admin state of a device +func (n *netconfig) setDeviceAdminState(devName, state string) error { + // Use netlink instead of ip command for better error handling and performance + link, err := n.netlinkLib.LinkByName(devName) + if err != nil { + return fmt.Errorf("failed to get link %s: %w", devName, err) + } + + if state == adminStateUp { + err = n.netlinkLib.LinkSetUp(link) + } else { + err = n.netlinkLib.LinkSetDown(link) + } + + if err != nil { + return fmt.Errorf("failed to set device admin state to %s: %w", state, err) + } + return nil +} + +// createVFs creates the specified number of VFs +func (n *netconfig) createVFs(pciAddr string, numVFs int) error { + // Write to sriov_numvfs: echo {num_vfs} > /sys/bus/pci/devices/{pci_addr}/sriov_numvfs + sriovNumVfsPath := fmt.Sprintf("/sys/bus/pci/devices/%s/sriov_numvfs", pciAddr) + numVFsStr := fmt.Sprintf("%d", numVFs) + + // Use the OS wrapper to write the file + if err := n.os.WriteFile(sriovNumVfsPath, []byte(numVFsStr), 0o644); err != nil { + return fmt.Errorf("failed to create %d VFs: %w", numVFs, err) + } + + return nil +} + +// restoreVFConfigurations restores the configuration for all VFs +func (n *netconfig) restoreVFConfigurations(ctx context.Context, devName string, device *MellanoxDevice, eswitchMode string) error { + log := logr.FromContextOrDiscard(ctx) + + for _, vf := range device.VFs { + log.V(1).Info("Restoring VF config", "device", devName, "vf_index", vf.VFIndex, "vf_pci", vf.VFPCIAddr) + + if err := n.restoreSingleVFConfig(ctx, devName, vf, device.DevType, eswitchMode); err != nil { + log.Error(err, "Failed to restore VF config", "device", devName, "vf_index", vf.VFIndex) + continue // Continue with other VFs + } + } + + return nil +} + +// restoreSingleVFConfig restores the configuration for a single VF +func (n *netconfig) restoreSingleVFConfig(ctx context.Context, devName string, vf VF, devType string, eswitchMode string) error { + log := logr.FromContextOrDiscard(ctx) + + // Restore VF-specific configuration based on device type + if devType == devTypeIB { + // For IB devices, set GUIDs + if vf.GUID != "-" && vf.GUID != "" { + if err := n.setIBGUIDs(ctx, devName, vf.VFIndex, vf.GUID); err != nil { + log.Error(err, "Failed to set IB GUIDs", "device", devName, "vf_index", vf.VFIndex, "guid", vf.GUID) + return err + } + } + } else { + // For Ethernet devices, set MAC addresses + if err := n.setEthernetMACs(ctx, devName, vf); err != nil { + log.Error(err, "Failed to set Ethernet MACs", "device", devName, "vf_index", vf.VFIndex) + return err + } + } + + // Unbind VF from driver (always unbind, matches bash script) + if err := n.unbindVFFromDriver(vf.VFPCIAddr); err != nil { + log.Error(err, "Failed to unbind VF from driver", "device", devName, "vf_index", vf.VFIndex, "vf_pci", vf.VFPCIAddr) + return err + } + + // Rebind VF to driver (skip if in switchdev mode - handled separately) + // This matches the bash script logic: if [ "${pf_eswitch_mode}" == "switchdev" ]; then continue; fi + if eswitchMode != eswitchModeSwitchdev { + if err := n.bindVFToDriver(vf.VFPCIAddr); err != nil { + log.Error(err, "Failed to rebind VF to driver", "device", devName, "vf_index", vf.VFIndex, "vf_pci", vf.VFPCIAddr) + return err + } + + // Wait for bind delay (matches bash script) + time.Sleep(3 * time.Second) // BIND_DELAY_SEC equivalent + + // Restore VF MTU and admin state after rebind + if err := n.restoreVFState(vf); err != nil { + log.Error(err, "Failed to restore VF state after rebind", "device", devName, "vf_index", vf.VFIndex, "vf_pci", vf.VFPCIAddr) + return err + } + } else { + log.V(1).Info("Skipping VF rebind for switchdev mode - will be handled after switchdev mode is set", + "device", devName, "vf_index", vf.VFIndex) + } + + return nil +} + +// setIBGUIDs sets the GUIDs for an IB VF +func (n *netconfig) setIBGUIDs(ctx context.Context, devName string, vfIndex int, guid string) error { + // Set port GUID: ip link set {dev_name} vf {vf_index} port_guid {guid} + _, stderr, err := n.cmd.RunCommand(ctx, "ip", "link", "set", devName, "vf", fmt.Sprintf("%d", vfIndex), "port_guid", guid) + if err != nil { + return fmt.Errorf("failed to set port GUID: %w, stderr: %s", err, stderr) + } + + // Set node GUID: ip link set {dev_name} vf {vf_index} node_guid {guid} + _, stderr, err = n.cmd.RunCommand(ctx, "ip", "link", "set", devName, "vf", fmt.Sprintf("%d", vfIndex), "node_guid", guid) + if err != nil { + return fmt.Errorf("failed to set node GUID: %w, stderr: %s", err, stderr) + } + + return nil +} + +// setEthernetMACs sets the MAC addresses for an Ethernet VF +func (n *netconfig) setEthernetMACs(ctx context.Context, devName string, vf VF) error { + // Get current VF device name + currentVFName, err := n.getCurrentVFName(vf.VFPCIAddr) + if err != nil { + return fmt.Errorf("failed to get current VF name: %w", err) + } + + // Set VF hardware MAC using netlink for better error handling + link, err := n.netlinkLib.LinkByName(currentVFName) + if err != nil { + return fmt.Errorf("failed to get VF link %s: %w", currentVFName, err) + } + + // Parse MAC address + hwAddr, err := net.ParseMAC(vf.MACAddress) + if err != nil { + return fmt.Errorf("failed to parse VF MAC address %s: %w", vf.MACAddress, err) + } + + if err := n.netlinkLib.LinkSetHardwareAddr(link, hwAddr); err != nil { + return fmt.Errorf("failed to set VF hardware MAC: %w", err) + } + + // Set VF admin MAC: ip link set dev {pf_name} vf {vf_index} mac {admin_mac} + // Note: This still requires ip command as netlink doesn't have direct VF admin MAC support + _, stderr, err := n.cmd.RunCommand(ctx, "ip", "link", "set", "dev", devName, "vf", fmt.Sprintf("%d", vf.VFIndex), "mac", vf.AdminMAC) + if err != nil { + return fmt.Errorf("failed to set VF admin MAC: %w, stderr: %s", err, stderr) + } + + return nil +} + +// getCurrentVFName gets the current VF device name after driver reload +func (n *netconfig) getCurrentVFName(vfPCIAddr string) (string, error) { + // Get VF name from PCI path: /sys/bus/pci/devices/{vf_pci_addr}/net/ + vfPciDevPath := fmt.Sprintf("/sys/bus/pci/devices/%s/net", vfPCIAddr) + entries, err := n.os.ReadDir(vfPciDevPath) + if err != nil { + return "", err + } + + if len(entries) == 0 { + return "", fmt.Errorf("no netdev found for VF PCI address %s", vfPCIAddr) + } + + return entries[0].Name(), nil +} + +// rebindVFsInSwitchdevMode rebinds VFs in switchdev mode +func (n *netconfig) rebindVFsInSwitchdevMode(ctx context.Context, device *MellanoxDevice) error { + log := logr.FromContextOrDiscard(ctx) + + for _, vf := range device.VFs { + log.V(1).Info("Rebinding VF in switchdev mode", "vf_pci", vf.VFPCIAddr) + + // Bind VF to driver + if err := n.bindVFToDriver(vf.VFPCIAddr); err != nil { + log.Error(err, "Failed to bind VF to driver", "vf_pci", vf.VFPCIAddr) + continue + } + + // Wait for bind delay (matches bash script) + time.Sleep(3 * time.Second) // BIND_DELAY_SEC equivalent + + // Restore VF MTU and admin state + if err := n.restoreVFState(vf); err != nil { + log.Error(err, "Failed to restore VF state", "vf_pci", vf.VFPCIAddr) + continue + } + } + + return nil +} + +// getDriverPath gets the driver path for a VF PCI address +func (n *netconfig) getDriverPath(vfPCIAddr string) string { + // Try to get the current driver from the VF's driver symlink + driverLink := fmt.Sprintf("/sys/bus/pci/devices/%s/driver", vfPCIAddr) + driverPath, err := n.os.Readlink(driverLink) + if err != nil { + // If no driver is bound, use the default mlx5_core driver + return defaultDriverPath + } + + // Extract the driver name from the symlink path + // driverPath is like "../../../../bus/pci/drivers/mlx5_core" + parts := strings.Split(driverPath, "/") + if len(parts) == 0 { + return defaultDriverPath // Fallback to default + } + + driverName := parts[len(parts)-1] + return fmt.Sprintf("/sys/bus/pci/drivers/%s", driverName) +} + +// unbindVFFromDriver unbinds a VF from its driver +func (n *netconfig) unbindVFFromDriver(vfPCIAddr string) error { + // Get the driver path for this VF + driverPath := n.getDriverPath(vfPCIAddr) + + // Write VF PCI address to driver unbind file + unbindFile := fmt.Sprintf("%s/unbind", driverPath) + + if err := n.os.WriteFile(unbindFile, []byte(vfPCIAddr), 0o644); err != nil { + return fmt.Errorf("failed to unbind VF from driver: %w", err) + } + + return nil +} + +// bindVFToDriver binds a VF to its driver +func (n *netconfig) bindVFToDriver(vfPCIAddr string) error { + // Get the driver path for this VF + driverPath := n.getDriverPath(vfPCIAddr) + + // Write VF PCI address to driver bind file + bindFile := fmt.Sprintf("%s/bind", driverPath) + + if err := n.os.WriteFile(bindFile, []byte(vfPCIAddr), 0o644); err != nil { + return fmt.Errorf("failed to bind VF to driver: %w", err) + } + + return nil +} + +// restoreVFState restores the MTU and admin state of a VF +func (n *netconfig) restoreVFState(vf VF) error { + // Get current VF name + currentVFName, err := n.getCurrentVFName(vf.VFPCIAddr) + if err != nil { + return fmt.Errorf("failed to get current VF name: %w", err) + } + + // Get VF link once and use it for both operations + link, err := n.netlinkLib.LinkByName(currentVFName) + if err != nil { + return fmt.Errorf("failed to get VF link %s: %w", currentVFName, err) + } + + // Set VF MTU using netlink + if err := n.netlinkLib.LinkSetMTU(link, vf.MTU); err != nil { + return fmt.Errorf("failed to set VF MTU to %d: %w", vf.MTU, err) + } + + // Set VF admin state using netlink + if vf.AdminState == adminStateUp { + err = n.netlinkLib.LinkSetUp(link) + } else { + err = n.netlinkLib.LinkSetDown(link) + } + + if err != nil { + return fmt.Errorf("failed to set VF admin state to %s: %w", vf.AdminState, err) + } + + return nil +} + +// setDeviceMTU sets the MTU of a device +func (n *netconfig) setDeviceMTU(devName string, mtu int) error { + // Use netlink instead of sysfs for better error handling and performance + link, err := n.netlinkLib.LinkByName(devName) + if err != nil { + return fmt.Errorf("failed to get link %s: %w", devName, err) + } + + if err := n.netlinkLib.LinkSetMTU(link, mtu); err != nil { + return fmt.Errorf("failed to set device MTU to %d: %w", mtu, err) + } + + return nil +} + +// isMlx5CoreLoaded checks if the mlx5_core driver is loaded +func (n *netconfig) isMlx5CoreLoaded(ctx context.Context) (bool, error) { + loadedModules, err := n.host.LsMod(ctx) + if err != nil { + return false, fmt.Errorf("failed to list loaded modules: %w", err) + } + + // Check if mlx5_core is in the loaded modules map + _, found := loadedModules["mlx5_core"] + return found, nil +} + +// discoverMellanoxDevices discovers all Mellanox network devices and collects detailed information +func (n *netconfig) discoverMellanoxDevices(ctx context.Context) ([]string, error) { + log := logr.FromContextOrDiscard(ctx) + + // Get all network interfaces from sysfs (matches bash script approach) + entries, err := n.os.ReadDir("/sys/class/net") + if err != nil { + return nil, fmt.Errorf("failed to read /sys/class/net: %w", err) + } + + devices := make([]string, 0, len(entries)) + + // Filter for Mellanox devices and collect detailed info + for _, entry := range entries { + devName := entry.Name() + + // Check vendor first (more efficient than PCI lookup) + if !n.isMellanoxDeviceByInterface(devName) { + continue + } + + // Get PCI address using sriovnet library + pciAddr, err := n.sriovnetLib.GetPciFromNetDevice(devName) + if err != nil { + log.V(1).Info("Could not get PCI address for device", "device", devName, "error", err) + continue + } + + log.V(1).Info("Found Mellanox device", "device", devName, "pci", pciAddr) + + // Get netlink link for additional attributes (admin state, MTU) + link, err := n.netlinkLib.LinkByName(devName) + if err != nil { + log.V(1).Info("Could not get netlink link", "device", devName, "error", err) + // Continue without netlink info - we can still collect basic info + link = nil + } + // Get eswitch mode + // This matches bash: eswitch_mode=$(devlink dev eswitch show pci/$pci_addr 2>/dev/null | + // awk '{for (i=1; i<=NF; i++) if ($i == "mode") {print $(i+1); exit}}') + eswitchMode, err := n.getEswitchMode(ctx, pciAddr) + if err != nil { + log.V(1).Info("Could not get eswitch mode", "device", devName, "pci", pciAddr, "error", err) + eswitchMode = eswitchModeLegacy // Default to legacy mode + } + + if eswitchMode == eswitchModeSwitchdev { + // Skip VF representors + if n.isRepresentor(devName) { + log.V(1).Info("Skipping VF representor", "device", devName) + continue + } + } + + // Collect detailed device information + device := n.collectDeviceInfo(ctx, devName, pciAddr, link) + + device.EswitchMode = eswitchMode + + // Collect VF information if VFs are configured + n.collectVFInfo(ctx, devName, device) + + // Store the device information + n.mellanoxDevices[devName] = device + devices = append(devices, devName) + + log.V(1).Info("Collected device info", "device", devName, "device", device, "vfs", len(device.VFs)) + } + + return devices, nil +} + +// collectDeviceInfo collects detailed information about a Mellanox device +func (n *netconfig) collectDeviceInfo(ctx context.Context, devName, pciAddr string, link netlink.Link) *MellanoxDevice { + log := logr.FromContextOrDiscard(ctx) + + device := &MellanoxDevice{ + PCIAddr: pciAddr, + VFs: make([]VF, 0), // Initialize empty VFs array + } + + // Get admin state and MTU from netlink (preferred method) + if link != nil { + // Get admin state from netlink flags + // This matches bash: dev_adminstate_flags=$(( $(cat "$netdev_path"/flags) & 1 )) + // dev_adminstate=$([[ $dev_adminstate_flags -eq 1 ]] && echo "up" || echo "down") + flags := link.Attrs().Flags + if flags&net.FlagUp != 0 { + device.AdminState = adminStateUp + } else { + device.AdminState = adminStateDown + } + + // Get MTU from netlink attributes + device.MTU = link.Attrs().MTU + } else { + // Fallback: read from sysfs directly (should be rare with netlink) + log.V(1).Info("Netlink unavailable, falling back to sysfs", "device", devName) + device.AdminState = n.getAdminStateFromSysfs(devName) + device.MTU = n.getMTUFromSysfs(devName) + } + + // Determine device type and get GUID + // This matches bash: if [[ "$dev_name" =~ ^ib.* ]]; then dev_type="ib"; else dev_type="eth"; fi + if strings.HasPrefix(devName, "ib") { + device.DevType = devTypeIB + // Get GUID for IB devices + guid, err := n.getIBGUID(devName) + if err != nil { + log.V(1).Info("Could not get IB GUID", "device", devName, "error", err) + device.GUID = "-" + } else { + device.GUID = n.restructureGUID(guid) + } + } else { + device.DevType = devTypeEth + device.GUID = "-" + } + + // Get number of VFs from sysfs (matches bash script approach) + device.PfNumVfs = n.getPfNumVfsFromSysfs(devName) + + return device +} + +// collectVFInfo collects detailed information about VFs for a given PF +func (n *netconfig) collectVFInfo(ctx context.Context, devName string, device *MellanoxDevice) { + log := logr.FromContextOrDiscard(ctx) + + // Skip if no VFs configured + if device.PfNumVfs == 0 { + return + } + + log.V(1).Info("Collecting VF information", "device", devName, "vfs", device.PfNumVfs) + + // Collect VF information for each VF index + for vfIndex := range device.PfNumVfs { + vf, err := n.collectSingleVFInfo(ctx, devName, vfIndex, device.DevType) + if err != nil { + log.V(1).Info("Could not collect VF info", "device", devName, "vf_index", vfIndex, "error", err) + continue // Continue with other VFs + } + + device.VFs = append(device.VFs, *vf) + log.V(1).Info("Collected VF info", "device", devName, "vf", vf) + } +} + +// collectSingleVFInfo collects information for a single VF +func (n *netconfig) collectSingleVFInfo(ctx context.Context, devName string, vfIndex int, devType string) (*VF, error) { + log := logr.FromContextOrDiscard(ctx) + + // VF device path: /sys/class/net/{PF_NAME}/device/virtfn{N}/net/{VF_NAME} + vfDevBasePath := fmt.Sprintf("/sys/class/net/%s/device/virtfn%d/net/", devName, vfIndex) + + // Get VF name + vfName, err := n.getVFName(vfDevBasePath) + if err != nil { + return nil, fmt.Errorf("could not get VF name: %w", err) + } + + vfNetdevPath := vfDevBasePath + vfName + + // Get VF PCI address + vfPCIAddr, err := n.getVFPCIAddr(vfNetdevPath) + if err != nil { + return nil, fmt.Errorf("could not get VF PCI address: %w", err) + } + + // Get VF admin state, MAC address, and MTU using netlink (preferred method) + vfAdminState, vfMAC, vfMTU, err := n.getVFAttributesFromNetlink(vfName) + if err != nil { + // Fallback to sysfs methods if netlink fails + log.V(1).Info("Netlink failed for VF, falling back to sysfs", "vf", vfName, "error", err) + + vfAdminState, err = n.getVFAdminState(vfNetdevPath) + if err != nil { + return nil, fmt.Errorf("could not get VF admin state: %w", err) + } + + vfMAC, err = n.getVFMACAddress(vfNetdevPath) + if err != nil { + return nil, fmt.Errorf("could not get VF MAC address: %w", err) + } + + vfMTU, err = n.getVFMTU(vfNetdevPath) + if err != nil { + return nil, fmt.Errorf("could not get VF MTU: %w", err) + } + } + + // Get VF admin MAC and GUID using ip command (matches bash script approach) + vfAdminMAC, vfGUID, err := n.getVFAdminMACAndGUID(ctx, devName, vfIndex, devType) + if err != nil { + log.V(1).Info("Could not get VF admin MAC/GUID", "device", devName, "vf_index", vfIndex, "error", err) + // Use fallback values + vfAdminMAC = vfMAC // Fallback to hardware MAC + vfGUID = "-" // Default for Ethernet + if devType == devTypeIB { + vfGUID = "" // Default for IB when extraction fails + } + } + + vf := &VF{ + VFIndex: vfIndex, + VFPCIAddr: vfPCIAddr, + VFName: vfName, + AdminState: vfAdminState, + MACAddress: vfMAC, + AdminMAC: vfAdminMAC, + MTU: vfMTU, + GUID: vfGUID, + } + + return vf, nil +} + +// getVFAttributesFromNetlink gets VF admin state, MAC address, and MTU using netlink +func (n *netconfig) getVFAttributesFromNetlink(vfName string) (string, string, int, error) { + link, err := n.netlinkLib.LinkByName(vfName) + if err != nil { + return "", "", 0, fmt.Errorf("failed to get VF link: %w", err) + } + + attrs := link.Attrs() + + // Get admin state from netlink flags + var adminState string + if attrs.Flags&net.FlagUp != 0 { + adminState = adminStateUp + } else { + adminState = adminStateDown + } + + // Get MAC address from netlink attributes + macAddr := attrs.HardwareAddr.String() + if macAddr == "" { + return "", "", 0, fmt.Errorf("no hardware address found") + } + + // Get MTU from netlink attributes + mtu := attrs.MTU + if mtu == 0 { + mtu = 1500 // Default MTU + } + + return adminState, macAddr, mtu, nil +} + +// getIBGUID gets the GUID for an InfiniBand device +func (n *netconfig) getIBGUID(devName string) (string, error) { + // This matches bash: sysfs_guid=$(cat ${netdev_path}/device/infiniband/*/node_guid) + // Look for the first infiniband directory under the device + devicePath := fmt.Sprintf("/sys/class/net/%s/device/infiniband", devName) + + // List infiniband directories + entries, err := n.os.ReadDir(devicePath) + if err != nil { + return "", err + } + + if len(entries) == 0 { + return "", fmt.Errorf("no infiniband directory found") + } + + // Read the first node_guid file + guidPath := fmt.Sprintf("%s/%s/node_guid", devicePath, entries[0].Name()) + guidData, err := n.os.ReadFile(guidPath) + if err != nil { + return "", err + } + + return strings.TrimSpace(string(guidData)), nil +} + +// restructureGUID restructures the GUID format +func (n *netconfig) restructureGUID(guid string) string { + // This matches the improved implementation + // sysfs_guid is like "0c42a1030016054c" + // restructure as "0c42:a103:0016:054c" + raw := strings.TrimSpace(guid) + if len(raw) != 16 { + return guid // Return original if not expected format + } + return fmt.Sprintf("%s:%s:%s:%s", raw[0:4], raw[4:8], raw[8:12], raw[12:16]) +} + +// getEswitchMode gets the eswitch mode for a PCI device +func (n *netconfig) getEswitchMode(ctx context.Context, pciAddr string) (string, error) { + // This matches bash: eswitch_mode=$(devlink dev eswitch show pci/$pci_addr 2>/dev/null | + // awk '{for (i=1; i<=NF; i++) if ($i == "mode") {print $(i+1); exit}}') + stdout, stderr, err := n.cmd.RunCommand(ctx, "devlink", "dev", "eswitch", "show", fmt.Sprintf("pci/%s", pciAddr)) + if err != nil { + return "", fmt.Errorf("failed to run devlink command: %w, stderr: %s", err, stderr) + } + + // Parse the output to find the mode + lines := strings.Split(stdout, "\n") + for _, line := range lines { + fields := strings.Fields(line) + for i, field := range fields { + if field == "mode" && i+1 < len(fields) { + return fields[i+1], nil + } + } + } + + return "legacy", nil // Default to legacy if not found +} + +// isMellanoxDeviceByInterface checks if a network interface is a Mellanox device by vendor +func (n *netconfig) isMellanoxDeviceByInterface(devName string) bool { + // Read vendor ID from sysfs + vendorPath := fmt.Sprintf("/sys/class/net/%s/device/vendor", devName) + vendorData, err := n.os.ReadFile(vendorPath) + if err != nil { + return false + } + + // Mellanox vendor ID is 0x15b3 + return strings.TrimSpace(string(vendorData)) == "0x15b3" +} + +// isRepresentor checks if a device is a VF representor +func (n *netconfig) isRepresentor(devName string) bool { + // Read phys_port_name to check if it's a representor + physPortNamePath := fmt.Sprintf("/sys/class/net/%s/phys_port_name", devName) + physPortNameData, err := n.os.ReadFile(physPortNamePath) + if err != nil { + return false + } + + physPortName := strings.TrimSpace(string(physPortNameData)) + // Check if it's a representor: starts with "pf" and contains "vf" + return strings.HasPrefix(physPortName, "pf") && strings.Contains(physPortName, "vf") +} + +// getAdminStateFromSysfs gets the admin state from sysfs flags +func (n *netconfig) getAdminStateFromSysfs(devName string) string { + // Read flags from sysfs: /sys/class/net/{dev}/flags + flagsPath := fmt.Sprintf("/sys/class/net/%s/flags", devName) + flagsData, err := n.os.ReadFile(flagsPath) + if err != nil { + return adminStateDown // Default to down if we can't read + } + + // Parse flags and check if bit 0 (IFF_UP) is set + // This matches bash: dev_adminstate_flags=$(( $(cat "$netdev_path"/flags) & 1 )) + flagsStr := strings.TrimSpace(string(flagsData)) + if flagsStr == "" { + return adminStateDown + } + + // Parse the flags value (handle both decimal and hexadecimal formats) + var flags int + if strings.HasPrefix(flagsStr, "0x") { + // Parse hexadecimal format + flags64, err := strconv.ParseInt(flagsStr, 0, 64) + if err != nil { + return adminStateDown + } + flags = int(flags64) + } else { + // Parse decimal format + flags, err = strconv.Atoi(flagsStr) + if err != nil { + return adminStateDown + } + } + + // Check if bit 0 is set (IFF_UP flag) + if flags&1 != 0 { + return adminStateUp + } + + return adminStateDown +} + +// getMTUFromSysfs gets the MTU from sysfs +func (n *netconfig) getMTUFromSysfs(devName string) int { + // Read MTU from sysfs: /sys/class/net/{dev}/mtu + mtuPath := fmt.Sprintf("/sys/class/net/%s/mtu", devName) + mtuData, err := n.os.ReadFile(mtuPath) + if err != nil { + return 1500 // Default MTU if we can't read + } + + // Parse MTU value + mtuStr := strings.TrimSpace(string(mtuData)) + if mtuStr == "" { + return 1500 + } + + // Convert to int + mtu, err := strconv.Atoi(mtuStr) + if err != nil { + return 1500 // Default MTU if parsing fails + } + + return mtu +} + +// getPfNumVfsFromSysfs gets the number of VFs from sysfs +func (n *netconfig) getPfNumVfsFromSysfs(devName string) int { + // Read sriov_numvfs from sysfs: /sys/class/net/{dev}/device/sriov_numvfs + sriovNumVfsPath := fmt.Sprintf("/sys/class/net/%s/device/sriov_numvfs", devName) + sriovNumVfsData, err := n.os.ReadFile(sriovNumVfsPath) + if err != nil { + return 0 // Default to 0 if we can't read (device not SRIOV capable) + } + + // Parse sriov_numvfs value + sriovNumVfsStr := strings.TrimSpace(string(sriovNumVfsData)) + if sriovNumVfsStr == "" { + return 0 + } + + // Convert to int + sriovNumVfs, err := strconv.Atoi(sriovNumVfsStr) + if err != nil { + return 0 // Default to 0 if parsing fails + } + + return sriovNumVfs +} + +// getVFName gets the VF netdev name from the VF device base path +func (n *netconfig) getVFName(vfDevBasePath string) (string, error) { + // List the net directory to get VF name (matches bash: vf_name=$(ls "$vf_dev_base_path")) + entries, err := n.os.ReadDir(vfDevBasePath) + if err != nil { + return "", err + } + + if len(entries) == 0 { + return "", fmt.Errorf("no VF netdev found in %s", vfDevBasePath) + } + + return entries[0].Name(), nil +} + +// getVFPCIAddr gets the VF PCI address from the VF netdev path +func (n *netconfig) getVFPCIAddr(vfNetdevPath string) (string, error) { + // Read the device symlink and get basename (matches bash: vf_pci_addr=$(basename $(readlink "$vf_netdev_path"/device))) + deviceLink := vfNetdevPath + "/device" + linkTarget, err := n.os.Readlink(deviceLink) + if err != nil { + return "", err + } + + // Get basename of the link target + parts := strings.Split(linkTarget, "/") + if len(parts) == 0 { + return "", fmt.Errorf("invalid device link target: %s", linkTarget) + } + + return parts[len(parts)-1], nil +} + +// getVFAdminState gets the VF admin state from the VF netdev path +func (n *netconfig) getVFAdminState(vfNetdevPath string) (string, error) { + // Read flags from sysfs (matches bash: vf_adminstate_flags=$(( $(cat "$vf_netdev_path"/flags) & 1 ))) + flagsPath := vfNetdevPath + "/flags" + flagsData, err := n.os.ReadFile(flagsPath) + if err != nil { + return "", err + } + + flagsStr := strings.TrimSpace(string(flagsData)) + if flagsStr == "" { + return adminStateDown, nil + } + + // Handle both decimal and hexadecimal formats + var flags int + if strings.HasPrefix(flagsStr, "0x") { + // Parse hexadecimal format + flags64, err := strconv.ParseInt(flagsStr, 0, 64) + if err != nil { + return adminStateDown, err + } + flags = int(flags64) + } else { + // Parse decimal format + flags, err = strconv.Atoi(flagsStr) + if err != nil { + return adminStateDown, err + } + } + + // Check if bit 0 is set (IFF_UP flag) + if flags&1 != 0 { + return adminStateUp, nil + } + + return adminStateDown, nil +} + +// getVFMACAddress gets the VF MAC address from the VF netdev path +func (n *netconfig) getVFMACAddress(vfNetdevPath string) (string, error) { + // Read MAC address from sysfs (matches bash: vf_mac=$(cat "$vf_netdev_path"/address)) + addressPath := vfNetdevPath + "/address" + macData, err := n.os.ReadFile(addressPath) + if err != nil { + return "", err + } + + return strings.TrimSpace(string(macData)), nil +} + +// getVFMTU gets the VF MTU from the VF netdev path +func (n *netconfig) getVFMTU(vfNetdevPath string) (int, error) { + // Read MTU from sysfs (matches bash: vf_mtu_val=$(cat "$vf_netdev_path"/mtu)) + mtuPath := vfNetdevPath + "/mtu" + mtuData, err := n.os.ReadFile(mtuPath) + if err != nil { + return 0, err + } + + mtuStr := strings.TrimSpace(string(mtuData)) + if mtuStr == "" { + return 1500, nil // Default MTU + } + + mtu, err := strconv.Atoi(mtuStr) + if err != nil { + return 1500, err // Default MTU if parsing fails + } + + return mtu, nil +} + +// getVFAdminMACAndGUID gets VF admin MAC and GUID using ip command (matches bash script approach) +func (n *netconfig) getVFAdminMACAndGUID(ctx context.Context, devName string, vfIndex int, devType string) (string, string, error) { + // Use ip command to get VF info (matches bash: vf_ip_link_json=$(ip -j link show $mlnx_dev_name | jq -r .[0].vfinfo_list[$vf_index])) + stdout, stderr, err := n.cmd.RunCommand(ctx, "ip", "-j", "link", "show", devName) + if err != nil { + return "", "", fmt.Errorf("failed to run ip command: %w, stderr: %s", err, stderr) + } + + // Parse JSON output to get VF info + var linkInfos []LinkInfo + if err := json.Unmarshal([]byte(stdout), &linkInfos); err != nil { + return "", "", fmt.Errorf("failed to parse JSON output: %w", err) + } + + if len(linkInfos) == 0 { + return "", "", fmt.Errorf("no link info found for device %s", devName) + } + + linkInfo := linkInfos[0] + if len(linkInfo.VFinfoList) <= vfIndex { + return "", "", fmt.Errorf("VF index %d not found in vfinfo_list for device %s", vfIndex, devName) + } + + vfInfo := linkInfo.VFinfoList[vfIndex] + + // Extract admin MAC (matches bash: vf_admin_mac=$(echo ${vf_ip_link_json} | jq -r .address)) + adminMAC := vfInfo.Address + + // Extract GUID for IB devices (matches bash: vf_guid=$(echo ${vf_ip_link_json} | jq -r '."port guid"')) + guid := "-" // Default for Ethernet + if devType == devTypeIB { + guid = vfInfo.PortGUID + } + + return adminMAC, guid, nil +} + +// discoverSwitchdevRepresentors discovers and stores switchdev representor information +func (n *netconfig) discoverSwitchdevRepresentors(ctx context.Context) error { + log := logr.FromContextOrDiscard(ctx) + log.Info("Discovering switchdev representors") + + representorCount := 0 + + // Iterate through all discovered devices + for devName, device := range n.mellanoxDevices { + // Only process devices in switchdev mode + if device.EswitchMode != eswitchModeSwitchdev { + log.V(1).Info("Device not in switchdev mode, skipping representor discovery", "device", devName) + continue + } + + // Skip devices with no VFs + if device.PfNumVfs == 0 { + log.V(1).Info("Device has no VFs, skipping representor discovery", "device", devName) + continue + } + + log.Info("Discovering representors for device", "device", devName, "vfs", device.PfNumVfs) + + // Get physical port information + physPortName, err := n.getPhysPortName(devName) + if err != nil { + log.Error(err, "Failed to get physical port name", "device", devName) + return fmt.Errorf("failed to get physical port name for device %s: %w", devName, err) + } + + physSwitchID, err := n.getPhysSwitchID(devName) + if err != nil { + log.Error(err, "Failed to get physical switch ID", "device", devName) + return fmt.Errorf("failed to get physical switch ID for device %s: %w", devName, err) + } + + // Parse physical port number from phys_port_name (format: "p1", "p2", etc.) + physPortNum, err := n.parsePhysPortNumber(physPortName) + if err != nil { + log.Error(err, "Failed to parse physical port number", "device", devName, "phys_port_name", physPortName) + return fmt.Errorf("failed to parse physical port number for device %s: %w", devName, err) + } + + // Discover representors in the device's subsystem + representors, err := n.findDeviceRepresentors(ctx, devName, physSwitchID, physPortNum) + if err != nil { + log.Error(err, "Failed to find representors for device", "device", devName) + return fmt.Errorf("failed to find representors for device %s: %w", devName, err) + } + + // Store representors in the device + device.Representors = representors + representorCount += len(representors) + + log.Info("Found representors for device", "device", devName, "count", len(representors)) + } + + log.Info("Switchdev representor discovery completed", "total_representors", representorCount) + return nil +} + +// getPhysPortName gets the physical port name for a device +func (n *netconfig) getPhysPortName(devName string) (string, error) { + physPortPath := fmt.Sprintf("/sys/class/net/%s/phys_port_name", devName) + physPortName, err := n.os.ReadFile(physPortPath) + if err != nil { + return "", fmt.Errorf("failed to read phys_port_name: %w", err) + } + return strings.TrimSpace(string(physPortName)), nil +} + +// getPhysSwitchID gets the physical switch ID for a device +func (n *netconfig) getPhysSwitchID(devName string) (string, error) { + physSwitchPath := fmt.Sprintf("/sys/class/net/%s/phys_switch_id", devName) + physSwitchID, err := n.os.ReadFile(physSwitchPath) + if err != nil { + return "", fmt.Errorf("failed to read phys_switch_id: %w", err) + } + return strings.TrimSpace(string(physSwitchID)), nil +} + +// parsePhysPortNumber parses the physical port number from phys_port_name +// Format: "p1", "p2", etc. -> returns "1", "2", etc. +func (n *netconfig) parsePhysPortNumber(physPortName string) (string, error) { + if !strings.HasPrefix(physPortName, "p") { + return "", fmt.Errorf("invalid phys_port_name format: %s", physPortName) + } + return strings.TrimPrefix(physPortName, "p"), nil +} + +// findDeviceRepresentors finds representors for a specific device +func (n *netconfig) findDeviceRepresentors(ctx context.Context, devName, physSwitchID, physPortNum string) ([]Representor, error) { + log := logr.FromContextOrDiscard(ctx) + representors := make([]Representor, 0, 10) // Pre-allocate with capacity + + // Look for representors in the device's subsystem + subsystemPath := fmt.Sprintf("/sys/class/net/%s/subsystem", devName) + entries, err := n.os.ReadDir(subsystemPath) + if err != nil { + return nil, fmt.Errorf("failed to read subsystem directory: %w", err) + } + + for _, entry := range entries { + representorName := entry.Name() + representorPath := fmt.Sprintf("/sys/class/net/%s/subsystem/%s", devName, representorName) + + // Check if this is a representor by examining phys_port_name + physPortNamePath := fmt.Sprintf("%s/phys_port_name", representorPath) + physPortName, err := n.os.ReadFile(physPortNamePath) + if err != nil { + continue // Skip if we can't read phys_port_name + } + + physPortNameStr := strings.TrimSpace(string(physPortName)) + + // Check if this is a representor (format: "pf{port_num}vf{vf_id}") + if !n.isRepresentorPhysPortName(physPortNameStr) { + continue + } + + // Parse representor information + pfPortNum, vfID, err := n.parseRepresentorPhysPortName(physPortNameStr) + if err != nil { + log.V(1).Info("Failed to parse representor phys_port_name", + "representor", representorName, "phys_port_name", physPortNameStr, "error", err) + continue + } + + // Verify this representor belongs to our PF + if pfPortNum != physPortNum { + log.V(1).Info("Representor does not belong to this PF", + "representor", representorName, "pf_port", physPortNum, "representor_pf_port", pfPortNum) + continue + } + + // Verify physical switch ID matches + representorSwitchID, err := n.getPhysSwitchID(representorName) + if err != nil || representorSwitchID != physSwitchID { + log.V(1).Info("Representor switch ID does not match PF", + "representor", representorName, "pf_switch_id", physSwitchID, "representor_switch_id", representorSwitchID) + continue + } + + // Get representor configuration + representor, err := n.collectRepresentorInfo(representorName, physSwitchID, physPortNum, vfID) + if err != nil { + log.Error(err, "Failed to collect representor info", "representor", representorName) + continue + } + + representors = append(representors, *representor) + log.V(1).Info("Found representor", "name", representorName, "vf_id", vfID, "admin_state", representor.AdminState, "mtu", representor.MTU) + } + + return representors, nil +} + +// isRepresentorPhysPortName checks if a phys_port_name indicates a representor +func (n *netconfig) isRepresentorPhysPortName(physPortName string) bool { + // Format: "pf{port_num}vf{vf_id}" (e.g., "pf1vf3") + re := regexp.MustCompile(`^pf(\d+)vf(\d+)$`) + return re.MatchString(physPortName) +} + +// parseRepresentorPhysPortName parses representor phys_port_name to extract PF port and VF ID +func (n *netconfig) parseRepresentorPhysPortName(physPortName string) (pfPortNum, vfID string, err error) { + re := regexp.MustCompile(`^pf(\d+)vf(\d+)$`) + matches := re.FindStringSubmatch(physPortName) + if len(matches) != 3 { + return "", "", fmt.Errorf("invalid representor phys_port_name format: %s", physPortName) + } + return matches[1], matches[2], nil +} + +// collectRepresentorInfo collects configuration information for a representor +func (n *netconfig) collectRepresentorInfo(representorName, physSwitchID, physPortNum, vfID string) (*Representor, error) { + // Get admin state and MTU using netlink + link, err := n.netlinkLib.LinkByName(representorName) + if err != nil { + return nil, fmt.Errorf("failed to get representor link: %w", err) + } + + attrs := link.Attrs() + + // Get admin state from netlink flags + var adminState string + if attrs.Flags&net.FlagUp != 0 { + adminState = adminStateUp + } else { + adminState = adminStateDown + } + + // Get MTU from netlink attributes + mtu := attrs.MTU + + return &Representor{ + PhysSwitchID: physSwitchID, + PhysPortNum: physPortNum, + VFID: vfID, + Name: representorName, + AdminState: adminState, + MTU: mtu, + }, nil +} + +// restoreRepresentors restores representor configurations +func (n *netconfig) restoreRepresentors(ctx context.Context, pfName string, device *MellanoxDevice) error { + log := logr.FromContextOrDiscard(ctx) + log.Info("Restoring representors", "device", pfName, "count", len(device.Representors)) + + // Get PF physical switch ID for matching + pfPhysSwitchID, err := n.getPhysSwitchID(pfName) + if err != nil { + return fmt.Errorf("failed to get PF physical switch ID: %w", err) + } + + // Get PF physical port number for matching + pfPhysPortName, err := n.getPhysPortName(pfName) + if err != nil { + return fmt.Errorf("failed to get PF physical port name: %w", err) + } + + pfPhysPortNum, err := n.parsePhysPortNumber(pfPhysPortName) + if err != nil { + return fmt.Errorf("failed to parse PF physical port number: %w", err) + } + + // Restore each representor + for _, representor := range device.Representors { + log.Info("Restoring representor", + "name", representor.Name, "vf_id", representor.VFID, "admin_state", representor.AdminState, "mtu", representor.MTU) + + // Find the current representor device + currentRepresentorName, err := n.findCurrentRepresentor(ctx, pfPhysSwitchID, pfPhysPortNum, representor.VFID) + if err != nil { + log.Error(err, "Failed to find current representor", "original_name", representor.Name, "vf_id", representor.VFID) + continue + } + + // Rename representor if needed + if currentRepresentorName != representor.Name { + if err := n.renameRepresentor(ctx, currentRepresentorName, representor.Name); err != nil { + log.Error(err, "Failed to rename representor", "current_name", currentRepresentorName, "target_name", representor.Name) + continue + } + log.Info("Renamed representor", "from", currentRepresentorName, "to", representor.Name) + } + + // Set representor MTU + if err := n.setRepresentorMTU(representor.Name, representor.MTU); err != nil { + log.Error(err, "Failed to set representor MTU", "representor", representor.Name, "mtu", representor.MTU) + continue + } + + // Set representor admin state + if err := n.setRepresentorAdminState(representor.Name, representor.AdminState); err != nil { + log.Error(err, "Failed to set representor admin state", "representor", representor.Name, "state", representor.AdminState) + continue + } + + log.Info("Successfully restored representor", "name", representor.Name) + } + + log.Info("Representor restoration completed", "device", pfName) + return nil +} + +// findCurrentRepresentor finds the current representor device based on physical attributes +func (n *netconfig) findCurrentRepresentor(ctx context.Context, physSwitchID, physPortNum, vfID string) (string, error) { + log := logr.FromContextOrDiscard(ctx) + + // Scan all network devices to find the representor + entries, err := n.os.ReadDir("/sys/class/net") + if err != nil { + return "", fmt.Errorf("failed to read network devices: %w", err) + } + + for _, entry := range entries { + devName := entry.Name() + + // Skip the PF itself + if devName == "lo" { + continue + } + + // Check if this device has the matching physical attributes + devPhysSwitchID, err := n.getPhysSwitchID(devName) + if err != nil { + continue // Skip if we can't read phys_switch_id + } + + if devPhysSwitchID != physSwitchID { + continue // Different switch + } + + // Check phys_port_name to see if it's a representor for our VF + devPhysPortName, err := n.getPhysPortName(devName) + if err != nil { + continue // Skip if we can't read phys_port_name + } + + // Check if this is a representor for our VF + if !n.isRepresentorPhysPortName(devPhysPortName) { + continue + } + + // Parse representor information + pfPortNum, devVFID, err := n.parseRepresentorPhysPortName(devPhysPortName) + if err != nil { + continue + } + + // Check if this representor belongs to our PF and VF + if pfPortNum == physPortNum && devVFID == vfID { + log.V(1).Info("Found current representor", "name", devName, "vf_id", vfID) + return devName, nil + } + } + + return "", fmt.Errorf("representor not found for VF ID %s", vfID) +} + +// renameRepresentor renames a representor device +func (n *netconfig) renameRepresentor(ctx context.Context, currentName, newName string) error { + // Use ip link set dev {current_name} name {new_name} + _, stderr, err := n.cmd.RunCommand(ctx, "ip", "link", "set", "dev", currentName, "name", newName) + if err != nil { + return fmt.Errorf("failed to rename representor from %s to %s: %w, stderr: %s", currentName, newName, err, stderr) + } + return nil +} + +// setRepresentorMTU sets the MTU for a representor +func (n *netconfig) setRepresentorMTU(representorName string, mtu int) error { + // Use netlink for better error handling + link, err := n.netlinkLib.LinkByName(representorName) + if err != nil { + return fmt.Errorf("failed to get representor link %s: %w", representorName, err) + } + + if err := n.netlinkLib.LinkSetMTU(link, mtu); err != nil { + return fmt.Errorf("failed to set representor MTU to %d: %w", mtu, err) + } + + return nil +} + +// setRepresentorAdminState sets the admin state for a representor +func (n *netconfig) setRepresentorAdminState(representorName, state string) error { + // Use netlink for better error handling + link, err := n.netlinkLib.LinkByName(representorName) + if err != nil { + return fmt.Errorf("failed to get representor link %s: %w", representorName, err) + } + + if state == adminStateUp { + err = n.netlinkLib.LinkSetUp(link) + } else { + err = n.netlinkLib.LinkSetDown(link) + } + + if err != nil { + return fmt.Errorf("failed to set representor admin state to %s: %w", state, err) + } + return nil } diff --git a/entrypoint/internal/netconfig/netconfig_suite_test.go b/entrypoint/internal/netconfig/netconfig_suite_test.go new file mode 100644 index 0000000..d531d28 --- /dev/null +++ b/entrypoint/internal/netconfig/netconfig_suite_test.go @@ -0,0 +1,29 @@ +/* + Copyright 2025, NVIDIA CORPORATION & AFFILIATES + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package netconfig + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestNetconfig(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Netconfig Suite") +} diff --git a/entrypoint/internal/netconfig/netconfig_test.go b/entrypoint/internal/netconfig/netconfig_test.go new file mode 100644 index 0000000..7be69c0 --- /dev/null +++ b/entrypoint/internal/netconfig/netconfig_test.go @@ -0,0 +1,623 @@ +/* + Copyright 2025, NVIDIA CORPORATION & AFFILIATES + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package netconfig + +import ( + "context" + "fmt" + "net" + "os" + + "github.com/vishvananda/netlink" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/stretchr/testify/mock" + + netlinkMockPkg "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/netlink/mocks" + sriovnetMockPkg "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/sriovnet/mocks" + cmdMockPkg "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/cmd/mocks" + "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/host" + hostMockPkg "github.com/Mellanox/doca-driver-build/entrypoint/internal/utils/host/mocks" + osMockPkg "github.com/Mellanox/doca-driver-build/entrypoint/internal/wrappers/mocks" +) + +// mockLink implements netlink.Link for testing +type mockLink struct { + attrs *netlink.LinkAttrs +} + +func (m *mockLink) Attrs() *netlink.LinkAttrs { + return m.attrs +} + +func (m *mockLink) Type() string { + return "mock" +} + +var _ = Describe("Netconfig", func() { + Context("New", func() { + It("should create a new netconfig instance", func() { + cmdMock := cmdMockPkg.NewInterface(GinkgoT()) + osMock := osMockPkg.NewOSWrapper(GinkgoT()) + hostMock := hostMockPkg.NewInterface(GinkgoT()) + sriovnetMock := sriovnetMockPkg.NewLib(GinkgoT()) + + netlinkMock := netlinkMockPkg.NewLib(GinkgoT()) + netconfig := New(cmdMock, osMock, hostMock, sriovnetMock, netlinkMock) + Expect(netconfig).NotTo(BeNil()) + }) + }) + + Context("Save", func() { + var ( + nc *netconfig + cmdMock *cmdMockPkg.Interface + osMock *osMockPkg.OSWrapper + hostMock *hostMockPkg.Interface + sriovnetMock *sriovnetMockPkg.Lib + netlinkMock *netlinkMockPkg.Lib + ctx context.Context + ) + + BeforeEach(func() { + cmdMock = cmdMockPkg.NewInterface(GinkgoT()) + osMock = osMockPkg.NewOSWrapper(GinkgoT()) + hostMock = hostMockPkg.NewInterface(GinkgoT()) + sriovnetMock = sriovnetMockPkg.NewLib(GinkgoT()) + netlinkMock = netlinkMockPkg.NewLib(GinkgoT()) + nc = New(cmdMock, osMock, hostMock, sriovnetMock, netlinkMock).(*netconfig) + ctx = context.Background() + }) + + It("should succeed when mlx5_core is not loaded", func() { + hostMock.On("LsMod", mock.Anything).Return(map[string]host.LoadedModule{}, nil).Once() + + err := nc.Save(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should fail when LsMod returns error", func() { + hostMock.On("LsMod", mock.Anything).Return(nil, fmt.Errorf("lsmod failed")).Once() + + err := nc.Save(ctx) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("failed to check if mlx5_core is loaded")) + }) + + It("should succeed when mlx5_core is loaded but no devices found", func() { + hostMock.On("LsMod", mock.Anything).Return(map[string]host.LoadedModule{ + "mlx5_core": {Name: "mlx5_core", RefCount: 1, UsedBy: []string{}}, + }, nil).Once() + osMock.On("ReadDir", "/sys/class/net").Return([]os.DirEntry{}, nil).Once() + + err := nc.Save(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should succeed when mlx5_core is loaded but no devices found", func() { + // Mock LsMod to return mlx5_core as loaded + hostMock.On("LsMod", mock.Anything).Return(map[string]host.LoadedModule{ + "mlx5_core": {Name: "mlx5_core", RefCount: 1, UsedBy: []string{}}, + }, nil).Once() + + // Mock device discovery - no devices found + osMock.On("ReadDir", "/sys/class/net").Return([]os.DirEntry{}, nil).Once() + + err := nc.Save(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should succeed when mlx5_core is loaded and devices are found", func() { + // Mock LsMod to return mlx5_core as loaded + hostMock.On("LsMod", mock.Anything).Return(map[string]host.LoadedModule{ + "mlx5_core": {Name: "mlx5_core", RefCount: 1, UsedBy: []string{}}, + }, nil).Once() + + // Mock device discovery + entries := []os.DirEntry{&mockDirEntry{name: "eth0"}} + osMock.On("ReadDir", "/sys/class/net").Return(entries, nil).Once() + + // Mock device vendor check + osMock.On("ReadFile", "/sys/class/net/eth0/device/vendor").Return([]byte("0x15b3"), nil).Once() + + // Mock sriovnet call - this is the key improvement! + sriovnetMock.On("GetPciFromNetDevice", "eth0").Return("0000:08:00.0", nil).Once() + + // Create a mock link object + mockLink := &mockLink{ + attrs: &netlink.LinkAttrs{ + Name: "eth0", + Flags: net.FlagUp, + MTU: 1500, + }, + } + + // Mock netlink call for device info collection + netlinkMock.On("LinkByName", "eth0").Return(mockLink, nil).Once() + + // Mock device attributes (fallback when netlink fails) + osMock.On("ReadFile", "/sys/class/net/eth0/flags").Return([]byte("0x1003"), nil).Maybe() + osMock.On("ReadFile", "/sys/class/net/eth0/mtu").Return([]byte("1500"), nil).Maybe() + osMock.On("ReadFile", "/sys/class/net/eth0/device/sriov_numvfs").Return([]byte("0"), nil).Once() + + // Mock devlink command + cmdMock.On("RunCommand", mock.Anything, "devlink", "dev", "eswitch", "show", mock.Anything).Return("mode legacy", "", nil).Once() + + err := nc.Save(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should handle sriovnet GetPciFromNetDevice error gracefully", func() { + // Mock LsMod to return mlx5_core as loaded + hostMock.On("LsMod", mock.Anything).Return(map[string]host.LoadedModule{ + "mlx5_core": {Name: "mlx5_core", RefCount: 1, UsedBy: []string{}}, + }, nil).Once() + + // Mock device discovery + entries := []os.DirEntry{&mockDirEntry{name: "eth0"}} + osMock.On("ReadDir", "/sys/class/net").Return(entries, nil).Once() + + // Mock device vendor check + osMock.On("ReadFile", "/sys/class/net/eth0/device/vendor").Return([]byte("0x15b3"), nil).Once() + + // Mock sriovnet call to return error - this tests error handling! + sriovnetMock.On("GetPciFromNetDevice", "eth0").Return("", fmt.Errorf("PCI address not found")).Once() + + err := nc.Save(ctx) + Expect(err).NotTo(HaveOccurred()) // Should continue gracefully + }) + + It("should fail when device discovery fails", func() { + hostMock.On("LsMod", mock.Anything).Return(map[string]host.LoadedModule{ + "mlx5_core": {Name: "mlx5_core", RefCount: 1, UsedBy: []string{}}, + }, nil).Once() + osMock.On("ReadDir", "/sys/class/net").Return(nil, fmt.Errorf("readdir failed")).Once() + + err := nc.Save(ctx) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("failed to discover Mellanox devices")) + }) + }) + + Context("Restore", func() { + var ( + nc *netconfig + cmdMock *cmdMockPkg.Interface + osMock *osMockPkg.OSWrapper + hostMock *hostMockPkg.Interface + sriovnetMock *sriovnetMockPkg.Lib + netlinkMock *netlinkMockPkg.Lib + ctx context.Context + ) + + BeforeEach(func() { + cmdMock = cmdMockPkg.NewInterface(GinkgoT()) + osMock = osMockPkg.NewOSWrapper(GinkgoT()) + hostMock = hostMockPkg.NewInterface(GinkgoT()) + sriovnetMock = sriovnetMockPkg.NewLib(GinkgoT()) + netlinkMock = netlinkMockPkg.NewLib(GinkgoT()) + nc = New(cmdMock, osMock, hostMock, sriovnetMock, netlinkMock).(*netconfig) + ctx = context.Background() + }) + + It("should succeed when no devices to restore", func() { + err := nc.Restore(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should succeed when device has no VFs", func() { + device := &MellanoxDevice{ + PCIAddr: "0000:08:00.0", + DevType: devTypeEth, + AdminState: adminStateUp, + MTU: 1500, + GUID: "-", + EswitchMode: eswitchModeLegacy, + PfNumVfs: 0, + VFs: []VF{}, + } + nc.mellanoxDevices["eth0"] = device + + err := nc.Restore(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should succeed when device has no VFs", func() { + device := &MellanoxDevice{ + PCIAddr: "0000:08:00.0", + DevType: devTypeEth, + AdminState: adminStateUp, + MTU: 1500, + GUID: "-", + EswitchMode: eswitchModeLegacy, + PfNumVfs: 0, + VFs: []VF{}, + } + nc.mellanoxDevices["eth0"] = device + + err := nc.Restore(ctx) + Expect(err).NotTo(HaveOccurred()) + }) + }) + + Context("Helper functions", func() { + var ( + nc *netconfig + cmdMock *cmdMockPkg.Interface + osMock *osMockPkg.OSWrapper + hostMock *hostMockPkg.Interface + sriovnetMock *sriovnetMockPkg.Lib + ) + + BeforeEach(func() { + cmdMock = cmdMockPkg.NewInterface(GinkgoT()) + osMock = osMockPkg.NewOSWrapper(GinkgoT()) + hostMock = hostMockPkg.NewInterface(GinkgoT()) + sriovnetMock = sriovnetMockPkg.NewLib(GinkgoT()) + netlinkMock := netlinkMockPkg.NewLib(GinkgoT()) + nc = New(cmdMock, osMock, hostMock, sriovnetMock, netlinkMock).(*netconfig) + }) + + Context("getCurrentDeviceName", func() { + It("should return device name when found", func() { + entries := []os.DirEntry{&mockDirEntry{name: "eth0"}} + osMock.On("ReadDir", "/sys/bus/pci/devices/0000:08:00.0/net").Return(entries, nil).Once() + + devName, err := nc.getCurrentDeviceName("0000:08:00.0") + Expect(err).NotTo(HaveOccurred()) + Expect(devName).To(Equal("eth0")) + }) + + It("should return error when no netdev found", func() { + osMock.On("ReadDir", "/sys/bus/pci/devices/0000:08:00.0/net").Return([]os.DirEntry{}, nil).Once() + + _, err := nc.getCurrentDeviceName("0000:08:00.0") + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("no netdev found for PCI address")) + }) + + It("should return error when ReadDir fails", func() { + osMock.On("ReadDir", "/sys/bus/pci/devices/0000:08:00.0/net").Return(nil, fmt.Errorf("readdir failed")).Once() + + _, err := nc.getCurrentDeviceName("0000:08:00.0") + Expect(err).To(HaveOccurred()) + }) + }) + + Context("setEswitchMode", func() { + It("should succeed", func() { + cmdMock.On("RunCommand", mock.Anything, "devlink", "dev", "eswitch", "set", "pci/0000:08:00.0", "mode", "legacy").Return("", "", nil).Once() + + err := nc.setEswitchMode(context.Background(), "0000:08:00.0", "legacy") + Expect(err).NotTo(HaveOccurred()) + }) + + It("should fail when command fails", func() { + cmdMock.On("RunCommand", mock.Anything, "devlink", "dev", "eswitch", "set", "pci/0000:08:00.0", "mode", "legacy").Return("", "error", fmt.Errorf("devlink failed")).Once() + + err := nc.setEswitchMode(context.Background(), "0000:08:00.0", "legacy") + Expect(err).To(HaveOccurred()) + }) + }) + + Context("createVFs", func() { + It("should succeed", func() { + osMock.On("WriteFile", "/sys/bus/pci/devices/0000:08:00.0/sriov_numvfs", []byte("4"), os.FileMode(0o644)).Return(nil).Once() + + err := nc.createVFs("0000:08:00.0", 4) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should fail when WriteFile fails", func() { + osMock.On("WriteFile", "/sys/bus/pci/devices/0000:08:00.0/sriov_numvfs", []byte("4"), os.FileMode(0o644)).Return(fmt.Errorf("write failed")).Once() + + err := nc.createVFs("0000:08:00.0", 4) + Expect(err).To(HaveOccurred()) + }) + }) + + Context("isMellanoxDeviceByInterface", func() { + It("should return true for Mellanox device", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/device/vendor").Return([]byte("0x15b3"), nil).Once() + + result := nc.isMellanoxDeviceByInterface("eth0") + Expect(result).To(BeTrue()) + }) + + It("should return false for non-Mellanox device", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/device/vendor").Return([]byte("0x8086"), nil).Once() + + result := nc.isMellanoxDeviceByInterface("eth0") + Expect(result).To(BeFalse()) + }) + + It("should return false when ReadFile fails", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/device/vendor").Return(nil, fmt.Errorf("read failed")).Once() + + result := nc.isMellanoxDeviceByInterface("eth0") + Expect(result).To(BeFalse()) + }) + }) + + Context("isRepresentor", func() { + It("should return true for representor", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/phys_port_name").Return([]byte("pf0vf0"), nil).Once() + + result := nc.isRepresentor("eth0") + Expect(result).To(BeTrue()) + }) + + It("should return false for non-representor", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/phys_port_name").Return([]byte("p0"), nil).Once() + + result := nc.isRepresentor("eth0") + Expect(result).To(BeFalse()) + }) + + It("should return false when ReadFile fails", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/phys_port_name").Return(nil, fmt.Errorf("read failed")).Once() + + result := nc.isRepresentor("eth0") + Expect(result).To(BeFalse()) + }) + }) + + Context("getAdminStateFromSysfs", func() { + It("should return up for device with up flag", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/flags").Return([]byte("0x1003"), nil).Once() + + result := nc.getAdminStateFromSysfs("eth0") + Expect(result).To(Equal(adminStateUp)) + }) + + It("should return down for device with down flag", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/flags").Return([]byte("0x1002"), nil).Once() + + result := nc.getAdminStateFromSysfs("eth0") + Expect(result).To(Equal(adminStateDown)) + }) + + It("should return down when ReadFile fails", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/flags").Return(nil, fmt.Errorf("read failed")).Once() + + result := nc.getAdminStateFromSysfs("eth0") + Expect(result).To(Equal(adminStateDown)) + }) + }) + + Context("getMTUFromSysfs", func() { + It("should return MTU value", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/mtu").Return([]byte("1500"), nil).Once() + + result := nc.getMTUFromSysfs("eth0") + Expect(result).To(Equal(1500)) + }) + + It("should return default MTU when ReadFile fails", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/mtu").Return(nil, fmt.Errorf("read failed")).Once() + + result := nc.getMTUFromSysfs("eth0") + Expect(result).To(Equal(1500)) + }) + }) + + Context("getPfNumVfsFromSysfs", func() { + It("should return number of VFs", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/device/sriov_numvfs").Return([]byte("4"), nil).Once() + + result := nc.getPfNumVfsFromSysfs("eth0") + Expect(result).To(Equal(4)) + }) + + It("should return 0 when ReadFile fails", func() { + osMock.On("ReadFile", "/sys/class/net/eth0/device/sriov_numvfs").Return(nil, fmt.Errorf("read failed")).Once() + + result := nc.getPfNumVfsFromSysfs("eth0") + Expect(result).To(Equal(0)) + }) + }) + + Context("restructureGUID", func() { + It("should restructure valid GUID", func() { + result := nc.restructureGUID("0c42a1030016054c") + Expect(result).To(Equal("0c42:a103:0016:054c")) + }) + + It("should return original for short GUID", func() { + result := nc.restructureGUID("0c42a103") + Expect(result).To(Equal("0c42a103")) + }) + + It("should return empty for empty GUID", func() { + result := nc.restructureGUID("") + Expect(result).To(Equal("")) + }) + }) + }) + + Context("Switchdev Flow", func() { + var ( + nc *netconfig + cmdMock *cmdMockPkg.Interface + osMock *osMockPkg.OSWrapper + hostMock *hostMockPkg.Interface + sriovnetMock *sriovnetMockPkg.Lib + netlinkMock *netlinkMockPkg.Lib + ctx context.Context + ) + + BeforeEach(func() { + cmdMock = cmdMockPkg.NewInterface(GinkgoT()) + osMock = osMockPkg.NewOSWrapper(GinkgoT()) + hostMock = hostMockPkg.NewInterface(GinkgoT()) + sriovnetMock = sriovnetMockPkg.NewLib(GinkgoT()) + netlinkMock = netlinkMockPkg.NewLib(GinkgoT()) + nc = New(cmdMock, osMock, hostMock, sriovnetMock, netlinkMock).(*netconfig) + ctx = context.Background() + }) + + Context("Helper functions for switchdev", func() { + Context("isRepresentorPhysPortName", func() { + It("should return true for valid representor phys port name", func() { + result := nc.isRepresentorPhysPortName("pf1vf0") + Expect(result).To(BeTrue()) + }) + + It("should return false for invalid phys port name", func() { + result := nc.isRepresentorPhysPortName("p0") + Expect(result).To(BeFalse()) + }) + + It("should return false for empty phys port name", func() { + result := nc.isRepresentorPhysPortName("") + Expect(result).To(BeFalse()) + }) + }) + + Context("parseRepresentorPhysPortName", func() { + It("should parse valid representor phys port name", func() { + pfID, vfID, err := nc.parseRepresentorPhysPortName("pf1vf0") + Expect(err).NotTo(HaveOccurred()) + Expect(pfID).To(Equal("1")) + Expect(vfID).To(Equal("0")) + }) + + It("should return error for invalid format", func() { + _, _, err := nc.parseRepresentorPhysPortName("p0") + Expect(err).To(HaveOccurred()) + }) + }) + }) + + Context("VF rebinding logic", func() { + It("should skip VF rebinding for switchdev mode", func() { + device := &MellanoxDevice{ + PCIAddr: "0000:08:00.1", + DevType: devTypeEth, + AdminState: adminStateDown, + MTU: 1500, + GUID: "-", + EswitchMode: eswitchModeSwitchdev, + PfNumVfs: 1, + VFs: []VF{ + {VFIndex: 0, VFPCIAddr: "0000:08:01.0", VFName: "eth10", AdminState: adminStateDown, MACAddress: "2a:c1:0b:f4:b5:3e", AdminMAC: "00:00:00:00:00:00", MTU: 1500, GUID: "-"}, + }, + } + + // Mock VF configuration + cmdMock.On("RunCommand", mock.Anything, "ip", "link", "set", "dev", "eth3", "vf", "0", "mac", "00:00:00:00:00:00").Return("", "", nil).Once() + + // Mock VF unbinding + osMock.On("WriteFile", "/sys/bus/pci/drivers/mlx5_core/unbind", []byte("0000:08:01.0"), os.FileMode(0o644)).Return(nil).Once() + + // Mock Readlink for driver check + osMock.On("Readlink", "/sys/bus/pci/devices/0000:08:01.0/driver").Return("../../../../bus/pci/drivers/mlx5_core", nil).Once() + + // Mock getCurrentDeviceName for VF + osMock.On("ReadDir", "/sys/bus/pci/devices/0000:08:01.0/net").Return([]os.DirEntry{&mockDirEntry{name: "eth10"}}, nil).Once() + + // Mock netlink call for VF state restoration + mockLink := &mockLink{ + attrs: &netlink.LinkAttrs{ + Name: "eth10", + Flags: net.FlagUp, + MTU: 1500, + }, + } + netlinkMock.On("LinkByName", "eth10").Return(mockLink, nil).Once() + netlinkMock.On("LinkSetHardwareAddr", mockLink, mock.AnythingOfType("net.HardwareAddr")).Return(nil).Once() + + err := nc.restoreVFConfigurations(ctx, "eth3", device, eswitchModeSwitchdev) + Expect(err).NotTo(HaveOccurred()) + + // Verify VF was configured and unbound, but not rebound + cmdMock.AssertExpectations(GinkgoT()) + }) + + It("should rebind VFs for legacy mode", func() { + device := &MellanoxDevice{ + PCIAddr: "0000:08:00.0", + DevType: devTypeEth, + AdminState: adminStateUp, + MTU: 1500, + GUID: "-", + EswitchMode: eswitchModeLegacy, + PfNumVfs: 1, + VFs: []VF{ + {VFIndex: 0, VFPCIAddr: "0000:08:00.2", VFName: "eth4", AdminState: adminStateUp, MACAddress: "aa:bb:cc:dd:ee:01", AdminMAC: "aa:bb:cc:dd:ee:01", MTU: 1500, GUID: "-"}, + }, + } + + // Mock VF configuration + cmdMock.On("RunCommand", mock.Anything, "ip", "link", "set", "dev", "eth2", "vf", "0", "mac", "aa:bb:cc:dd:ee:01").Return("", "", nil).Maybe() + + // Mock VF unbinding and rebinding + osMock.On("WriteFile", "/sys/bus/pci/drivers/mlx5_core/unbind", []byte("0000:08:00.2"), os.FileMode(0o644)).Return(nil).Maybe() + osMock.On("WriteFile", "/sys/bus/pci/drivers/mlx5_core/bind", []byte("0000:08:00.2"), os.FileMode(0o644)).Return(nil).Maybe() + + // Mock Readlink for driver check + osMock.On("Readlink", "/sys/bus/pci/devices/0000:08:00.2/driver").Return("../../../../bus/pci/drivers/mlx5_core", nil).Maybe() + + // Mock VF state restoration + cmdMock.On("RunCommand", mock.Anything, "ip", "link", "set", "dev", "eth4", "mtu", "1500").Return("", "", nil).Maybe() + cmdMock.On("RunCommand", mock.Anything, "ip", "link", "set", "dev", "eth4", "up").Return("", "", nil).Maybe() + + // Mock getCurrentDeviceName for VF + osMock.On("ReadDir", "/sys/bus/pci/devices/0000:08:00.2/net").Return([]os.DirEntry{&mockDirEntry{name: "eth4"}}, nil).Maybe() + + // Mock netlink call for VF state restoration + mockLink := &mockLink{ + attrs: &netlink.LinkAttrs{ + Name: "eth4", + Flags: net.FlagUp, + MTU: 1500, + }, + } + netlinkMock.On("LinkByName", "eth4").Return(mockLink, nil).Maybe() + netlinkMock.On("LinkSetHardwareAddr", mockLink, mock.AnythingOfType("net.HardwareAddr")).Return(nil).Maybe() + netlinkMock.On("LinkSetMTU", mockLink, 1500).Return(nil).Maybe() + netlinkMock.On("LinkSetUp", mockLink).Return(nil).Maybe() + + err := nc.restoreVFConfigurations(ctx, "eth2", device, eswitchModeLegacy) + Expect(err).NotTo(HaveOccurred()) + }) + }) + }) +}) + +// mockDirEntry is a mock implementation of os.DirEntry for testing +type mockDirEntry struct { + name string + isDir bool +} + +func (m *mockDirEntry) Name() string { + return m.name +} + +func (m *mockDirEntry) IsDir() bool { + return m.isDir +} + +func (m *mockDirEntry) Type() os.FileMode { + return 0 +} + +func (m *mockDirEntry) Info() (os.FileInfo, error) { + return nil, nil +} diff --git a/entrypoint/internal/netconfig/netlink/mocks/Lib.go b/entrypoint/internal/netconfig/netlink/mocks/Lib.go new file mode 100644 index 0000000..f4f4bc2 --- /dev/null +++ b/entrypoint/internal/netconfig/netlink/mocks/Lib.go @@ -0,0 +1,331 @@ +// Code generated by mockery v2.53.3. DO NOT EDIT. + +package netlink + +import ( + net "net" + + mock "github.com/stretchr/testify/mock" + + netlink "github.com/Mellanox/doca-driver-build/entrypoint/internal/netconfig/netlink" + vishvanandanetlink "github.com/vishvananda/netlink" +) + +// Lib is an autogenerated mock type for the Lib type +type Lib struct { + mock.Mock +} + +type Lib_Expecter struct { + mock *mock.Mock +} + +func (_m *Lib) EXPECT() *Lib_Expecter { + return &Lib_Expecter{mock: &_m.Mock} +} + +// GetLink provides a mock function with given fields: link +func (_m *Lib) GetLink(link netlink.Link) vishvanandanetlink.Link { + ret := _m.Called(link) + + if len(ret) == 0 { + panic("no return value specified for GetLink") + } + + var r0 vishvanandanetlink.Link + if rf, ok := ret.Get(0).(func(netlink.Link) vishvanandanetlink.Link); ok { + r0 = rf(link) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(vishvanandanetlink.Link) + } + } + + return r0 +} + +// Lib_GetLink_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLink' +type Lib_GetLink_Call struct { + *mock.Call +} + +// GetLink is a helper method to define mock.On call +// - link netlink.Link +func (_e *Lib_Expecter) GetLink(link interface{}) *Lib_GetLink_Call { + return &Lib_GetLink_Call{Call: _e.mock.On("GetLink", link)} +} + +func (_c *Lib_GetLink_Call) Run(run func(link netlink.Link)) *Lib_GetLink_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(netlink.Link)) + }) + return _c +} + +func (_c *Lib_GetLink_Call) Return(_a0 vishvanandanetlink.Link) *Lib_GetLink_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Lib_GetLink_Call) RunAndReturn(run func(netlink.Link) vishvanandanetlink.Link) *Lib_GetLink_Call { + _c.Call.Return(run) + return _c +} + +// LinkByName provides a mock function with given fields: name +func (_m *Lib) LinkByName(name string) (netlink.Link, error) { + ret := _m.Called(name) + + if len(ret) == 0 { + panic("no return value specified for LinkByName") + } + + var r0 netlink.Link + var r1 error + if rf, ok := ret.Get(0).(func(string) (netlink.Link, error)); ok { + return rf(name) + } + if rf, ok := ret.Get(0).(func(string) netlink.Link); ok { + r0 = rf(name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(netlink.Link) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Lib_LinkByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LinkByName' +type Lib_LinkByName_Call struct { + *mock.Call +} + +// LinkByName is a helper method to define mock.On call +// - name string +func (_e *Lib_Expecter) LinkByName(name interface{}) *Lib_LinkByName_Call { + return &Lib_LinkByName_Call{Call: _e.mock.On("LinkByName", name)} +} + +func (_c *Lib_LinkByName_Call) Run(run func(name string)) *Lib_LinkByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Lib_LinkByName_Call) Return(_a0 netlink.Link, _a1 error) *Lib_LinkByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Lib_LinkByName_Call) RunAndReturn(run func(string) (netlink.Link, error)) *Lib_LinkByName_Call { + _c.Call.Return(run) + return _c +} + +// LinkSetDown provides a mock function with given fields: link +func (_m *Lib) LinkSetDown(link netlink.Link) error { + ret := _m.Called(link) + + if len(ret) == 0 { + panic("no return value specified for LinkSetDown") + } + + var r0 error + if rf, ok := ret.Get(0).(func(netlink.Link) error); ok { + r0 = rf(link) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Lib_LinkSetDown_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LinkSetDown' +type Lib_LinkSetDown_Call struct { + *mock.Call +} + +// LinkSetDown is a helper method to define mock.On call +// - link netlink.Link +func (_e *Lib_Expecter) LinkSetDown(link interface{}) *Lib_LinkSetDown_Call { + return &Lib_LinkSetDown_Call{Call: _e.mock.On("LinkSetDown", link)} +} + +func (_c *Lib_LinkSetDown_Call) Run(run func(link netlink.Link)) *Lib_LinkSetDown_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(netlink.Link)) + }) + return _c +} + +func (_c *Lib_LinkSetDown_Call) Return(_a0 error) *Lib_LinkSetDown_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Lib_LinkSetDown_Call) RunAndReturn(run func(netlink.Link) error) *Lib_LinkSetDown_Call { + _c.Call.Return(run) + return _c +} + +// LinkSetHardwareAddr provides a mock function with given fields: link, hwaddr +func (_m *Lib) LinkSetHardwareAddr(link netlink.Link, hwaddr net.HardwareAddr) error { + ret := _m.Called(link, hwaddr) + + if len(ret) == 0 { + panic("no return value specified for LinkSetHardwareAddr") + } + + var r0 error + if rf, ok := ret.Get(0).(func(netlink.Link, net.HardwareAddr) error); ok { + r0 = rf(link, hwaddr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Lib_LinkSetHardwareAddr_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LinkSetHardwareAddr' +type Lib_LinkSetHardwareAddr_Call struct { + *mock.Call +} + +// LinkSetHardwareAddr is a helper method to define mock.On call +// - link netlink.Link +// - hwaddr net.HardwareAddr +func (_e *Lib_Expecter) LinkSetHardwareAddr(link interface{}, hwaddr interface{}) *Lib_LinkSetHardwareAddr_Call { + return &Lib_LinkSetHardwareAddr_Call{Call: _e.mock.On("LinkSetHardwareAddr", link, hwaddr)} +} + +func (_c *Lib_LinkSetHardwareAddr_Call) Run(run func(link netlink.Link, hwaddr net.HardwareAddr)) *Lib_LinkSetHardwareAddr_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(netlink.Link), args[1].(net.HardwareAddr)) + }) + return _c +} + +func (_c *Lib_LinkSetHardwareAddr_Call) Return(_a0 error) *Lib_LinkSetHardwareAddr_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Lib_LinkSetHardwareAddr_Call) RunAndReturn(run func(netlink.Link, net.HardwareAddr) error) *Lib_LinkSetHardwareAddr_Call { + _c.Call.Return(run) + return _c +} + +// LinkSetMTU provides a mock function with given fields: link, mtu +func (_m *Lib) LinkSetMTU(link netlink.Link, mtu int) error { + ret := _m.Called(link, mtu) + + if len(ret) == 0 { + panic("no return value specified for LinkSetMTU") + } + + var r0 error + if rf, ok := ret.Get(0).(func(netlink.Link, int) error); ok { + r0 = rf(link, mtu) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Lib_LinkSetMTU_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LinkSetMTU' +type Lib_LinkSetMTU_Call struct { + *mock.Call +} + +// LinkSetMTU is a helper method to define mock.On call +// - link netlink.Link +// - mtu int +func (_e *Lib_Expecter) LinkSetMTU(link interface{}, mtu interface{}) *Lib_LinkSetMTU_Call { + return &Lib_LinkSetMTU_Call{Call: _e.mock.On("LinkSetMTU", link, mtu)} +} + +func (_c *Lib_LinkSetMTU_Call) Run(run func(link netlink.Link, mtu int)) *Lib_LinkSetMTU_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(netlink.Link), args[1].(int)) + }) + return _c +} + +func (_c *Lib_LinkSetMTU_Call) Return(_a0 error) *Lib_LinkSetMTU_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Lib_LinkSetMTU_Call) RunAndReturn(run func(netlink.Link, int) error) *Lib_LinkSetMTU_Call { + _c.Call.Return(run) + return _c +} + +// LinkSetUp provides a mock function with given fields: link +func (_m *Lib) LinkSetUp(link netlink.Link) error { + ret := _m.Called(link) + + if len(ret) == 0 { + panic("no return value specified for LinkSetUp") + } + + var r0 error + if rf, ok := ret.Get(0).(func(netlink.Link) error); ok { + r0 = rf(link) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Lib_LinkSetUp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LinkSetUp' +type Lib_LinkSetUp_Call struct { + *mock.Call +} + +// LinkSetUp is a helper method to define mock.On call +// - link netlink.Link +func (_e *Lib_Expecter) LinkSetUp(link interface{}) *Lib_LinkSetUp_Call { + return &Lib_LinkSetUp_Call{Call: _e.mock.On("LinkSetUp", link)} +} + +func (_c *Lib_LinkSetUp_Call) Run(run func(link netlink.Link)) *Lib_LinkSetUp_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(netlink.Link)) + }) + return _c +} + +func (_c *Lib_LinkSetUp_Call) Return(_a0 error) *Lib_LinkSetUp_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Lib_LinkSetUp_Call) RunAndReturn(run func(netlink.Link) error) *Lib_LinkSetUp_Call { + _c.Call.Return(run) + return _c +} + +// NewLib creates a new instance of Lib. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLib(t interface { + mock.TestingT + Cleanup(func()) +}) *Lib { + mock := &Lib{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/entrypoint/internal/netconfig/netlink/mocks/Link.go b/entrypoint/internal/netconfig/netlink/mocks/Link.go new file mode 100644 index 0000000..b45f91e --- /dev/null +++ b/entrypoint/internal/netconfig/netlink/mocks/Link.go @@ -0,0 +1,128 @@ +// Code generated by mockery v2.53.3. DO NOT EDIT. + +package netlink + +import ( + mock "github.com/stretchr/testify/mock" + + netlink "github.com/vishvananda/netlink" +) + +// Link is an autogenerated mock type for the Link type +type Link struct { + mock.Mock +} + +type Link_Expecter struct { + mock *mock.Mock +} + +func (_m *Link) EXPECT() *Link_Expecter { + return &Link_Expecter{mock: &_m.Mock} +} + +// Attrs provides a mock function with no fields +func (_m *Link) Attrs() *netlink.LinkAttrs { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Attrs") + } + + var r0 *netlink.LinkAttrs + if rf, ok := ret.Get(0).(func() *netlink.LinkAttrs); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*netlink.LinkAttrs) + } + } + + return r0 +} + +// Link_Attrs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Attrs' +type Link_Attrs_Call struct { + *mock.Call +} + +// Attrs is a helper method to define mock.On call +func (_e *Link_Expecter) Attrs() *Link_Attrs_Call { + return &Link_Attrs_Call{Call: _e.mock.On("Attrs")} +} + +func (_c *Link_Attrs_Call) Run(run func()) *Link_Attrs_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Link_Attrs_Call) Return(_a0 *netlink.LinkAttrs) *Link_Attrs_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Link_Attrs_Call) RunAndReturn(run func() *netlink.LinkAttrs) *Link_Attrs_Call { + _c.Call.Return(run) + return _c +} + +// Type provides a mock function with no fields +func (_m *Link) Type() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Type") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Link_Type_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Type' +type Link_Type_Call struct { + *mock.Call +} + +// Type is a helper method to define mock.On call +func (_e *Link_Expecter) Type() *Link_Type_Call { + return &Link_Type_Call{Call: _e.mock.On("Type")} +} + +func (_c *Link_Type_Call) Run(run func()) *Link_Type_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Link_Type_Call) Return(_a0 string) *Link_Type_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Link_Type_Call) RunAndReturn(run func() string) *Link_Type_Call { + _c.Call.Return(run) + return _c +} + +// NewLink creates a new instance of Link. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLink(t interface { + mock.TestingT + Cleanup(func()) +}) *Link { + mock := &Link{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/entrypoint/internal/netconfig/netlink/netlink.go b/entrypoint/internal/netconfig/netlink/netlink.go new file mode 100644 index 0000000..866e3a8 --- /dev/null +++ b/entrypoint/internal/netconfig/netlink/netlink.go @@ -0,0 +1,68 @@ +package netlink + +import ( + "net" + + "github.com/vishvananda/netlink" +) + +func New() Lib { + return &libWrapper{} +} + +type Link interface { + netlink.Link +} + +type Lib interface { + // LinkByName finds a link by name and returns a pointer to the object. + LinkByName(name string) (Link, error) + // LinkSetUp enables the link device. + // Equivalent to: `ip link set $link up` + LinkSetUp(link Link) error + // LinkSetDown disables the link device. + // Equivalent to: `ip link set $link down` + LinkSetDown(link Link) error + // LinkSetMTU sets the mtu of the link device. + // Equivalent to: `ip link set $link mtu $mtu` + LinkSetMTU(link Link, mtu int) error + // LinkSetHardwareAddr sets the hardware address of a link. + LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error + // GetLink returns the underlying netlink.Link from a Link interface + GetLink(link Link) netlink.Link +} + +type libWrapper struct{} + +// LinkByName finds a link by name and returns a pointer to the object. +func (w *libWrapper) LinkByName(name string) (Link, error) { + return netlink.LinkByName(name) +} + +// LinkSetUp enables the link device. +// Equivalent to: `ip link set $link up` +func (w *libWrapper) LinkSetUp(link Link) error { + return netlink.LinkSetUp(link) +} + +// LinkSetDown disables the link device. +// Equivalent to: `ip link set $link down` +func (w *libWrapper) LinkSetDown(link Link) error { + return netlink.LinkSetDown(link) +} + +// LinkSetMTU sets the mtu of the link device. +// Equivalent to: `ip link set $link mtu $mtu` +func (w *libWrapper) LinkSetMTU(link Link, mtu int) error { + return netlink.LinkSetMTU(link, mtu) +} + +// LinkSetHardwareAddr sets the hardware address of a link. +func (w *libWrapper) LinkSetHardwareAddr(link Link, hwaddr net.HardwareAddr) error { + return netlink.LinkSetHardwareAddr(link, hwaddr) +} + +// GetLink returns the underlying netlink.Link from a Link interface +func (w *libWrapper) GetLink(link Link) netlink.Link { + return link +} diff --git a/entrypoint/internal/netconfig/sriovnet/mocks/Lib.go b/entrypoint/internal/netconfig/sriovnet/mocks/Lib.go new file mode 100644 index 0000000..5b5fcae --- /dev/null +++ b/entrypoint/internal/netconfig/sriovnet/mocks/Lib.go @@ -0,0 +1,88 @@ +// Code generated by mockery v2.53.3. DO NOT EDIT. + +package sriovnet + +import mock "github.com/stretchr/testify/mock" + +// Lib is an autogenerated mock type for the Lib type +type Lib struct { + mock.Mock +} + +type Lib_Expecter struct { + mock *mock.Mock +} + +func (_m *Lib) EXPECT() *Lib_Expecter { + return &Lib_Expecter{mock: &_m.Mock} +} + +// GetPciFromNetDevice provides a mock function with given fields: name +func (_m *Lib) GetPciFromNetDevice(name string) (string, error) { + ret := _m.Called(name) + + if len(ret) == 0 { + panic("no return value specified for GetPciFromNetDevice") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(name) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(name) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Lib_GetPciFromNetDevice_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPciFromNetDevice' +type Lib_GetPciFromNetDevice_Call struct { + *mock.Call +} + +// GetPciFromNetDevice is a helper method to define mock.On call +// - name string +func (_e *Lib_Expecter) GetPciFromNetDevice(name interface{}) *Lib_GetPciFromNetDevice_Call { + return &Lib_GetPciFromNetDevice_Call{Call: _e.mock.On("GetPciFromNetDevice", name)} +} + +func (_c *Lib_GetPciFromNetDevice_Call) Run(run func(name string)) *Lib_GetPciFromNetDevice_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Lib_GetPciFromNetDevice_Call) Return(_a0 string, _a1 error) *Lib_GetPciFromNetDevice_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Lib_GetPciFromNetDevice_Call) RunAndReturn(run func(string) (string, error)) *Lib_GetPciFromNetDevice_Call { + _c.Call.Return(run) + return _c +} + +// NewLib creates a new instance of Lib. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLib(t interface { + mock.TestingT + Cleanup(func()) +}) *Lib { + mock := &Lib{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/entrypoint/internal/netconfig/sriovnet/sriovnet.go b/entrypoint/internal/netconfig/sriovnet/sriovnet.go new file mode 100644 index 0000000..812714a --- /dev/null +++ b/entrypoint/internal/netconfig/sriovnet/sriovnet.go @@ -0,0 +1,21 @@ +package sriovnet + +import ( + "github.com/k8snetworkplumbingwg/sriovnet" +) + +func New() Lib { + return &libWrapper{} +} + +type Lib interface { + // GetPciFromNetDevice returns the PCI address associated with a network device name + GetPciFromNetDevice(name string) (string, error) +} + +type libWrapper struct{} + +// GetPciFromNetDevice returns the PCI address associated with a network device name +func (w *libWrapper) GetPciFromNetDevice(name string) (string, error) { + return sriovnet.GetPciFromNetDevice(name) +} diff --git a/entrypoint/internal/utils/udev/70-mlnx-ofed-naming.rules b/entrypoint/internal/utils/udev/70-mlnx-ofed-naming.rules new file mode 100644 index 0000000..3b7d468 --- /dev/null +++ b/entrypoint/internal/utils/udev/70-mlnx-ofed-naming.rules @@ -0,0 +1,17 @@ +ACTION!="add", GOTO="mlnx_ofed_name_end" +SUBSYSTEM!="net", GOTO="mlnx_ofed_name_end" + +# Rename physical interfaces (first case) of virtual functions (second case). +# Example names: +# enp8s0f0np0 -> enp8s0f0 +# enp8s0f0np1v12 -> enp8s0f0v12 + +DRIVERS=="mlx5_core", ENV{ID_NET_NAME_PATH}!="", \ +PROGRAM="/bin/sh -c 'echo $env{ID_NET_NAME_PATH} | sed -r -e s/np[01]$// -e s/np[01]v/v/'", \ + ENV{ID_NET_NAME_PATH}="$result" + +DRIVERS=="mlx5_core", ENV{ID_NET_NAME_SLOT}!="", \ +PROGRAM="/bin/sh -c 'echo $env{ID_NET_NAME_SLOT} | sed -r -e s/np[01]$// -e s/np[01]v/v/'", \ + ENV{ID_NET_NAME_SLOT}="$result" + +LABEL="mlnx_ofed_name_end" diff --git a/entrypoint/internal/utils/udev/udev.go b/entrypoint/internal/utils/udev/udev.go index 4bbbbca..9b7cf3b 100644 --- a/entrypoint/internal/utils/udev/udev.go +++ b/entrypoint/internal/utils/udev/udev.go @@ -18,12 +18,17 @@ package udev import ( "context" + _ "embed" + "os" "github.com/go-logr/logr" "github.com/Mellanox/doca-driver-build/entrypoint/internal/wrappers" ) +//go:embed 70-mlnx-ofed-naming.rules +var udevRulesContent string + // New initialize default implementation of the udev.Interface. func New(path string, osWrapper wrappers.OSWrapper) Interface { return &udev{ @@ -50,15 +55,50 @@ type udev struct { // CreateRules is the default implementation of the udev.Interface. func (u *udev) CreateRules(ctx context.Context) error { - _ = logr.FromContextOrDiscard(ctx) - // TODO add implementation + log := logr.FromContextOrDiscard(ctx) + log.Info("create udev rules") + + // Write the udev rules file + if err := u.os.WriteFile(u.path, []byte(udevRulesContent), 0o644); err != nil { + log.Error(err, "failed to create udev rules file", "path", u.path) + return err + } + + log.Info("udev rules file created successfully", "path", u.path) + + // Log the file content on debug level (equivalent to bash: debug_print `cat ${MLX_UDEV_RULES_FILE}`) + log.V(1).Info("udev rules file content", "path", u.path, "content", udevRulesContent) + return nil } // RemoveRules is the default implementation of the udev.Interface. func (u *udev) RemoveRules(ctx context.Context) error { - _ = logr.FromContextOrDiscard(ctx) - // TODO add implementation + log := logr.FromContextOrDiscard(ctx) + log.Info("remove udev rules") + + // Check if the udev rules file exists + _, err := u.os.Stat(u.path) + if err != nil { + // Check if it's a "file not found" error + if os.IsNotExist(err) { + // File doesn't exist, log and skip + log.Info("udev rules file was not previously created, skipping", "path", u.path) + return nil + } + // Other errors (permission denied, etc.) should be returned + log.Error(err, "failed to check if udev rules file exists", "path", u.path) + return err + } + + // File exists, delete it + log.Info("deleting udev rules", "path", u.path) + if err := u.os.RemoveAll(u.path); err != nil { + log.Error(err, "failed to remove udev rules file", "path", u.path) + return err + } + + log.Info("udev rules file deleted successfully", "path", u.path) return nil } diff --git a/entrypoint/internal/utils/udev/udev_suite_test.go b/entrypoint/internal/utils/udev/udev_suite_test.go new file mode 100644 index 0000000..b67ecfd --- /dev/null +++ b/entrypoint/internal/utils/udev/udev_suite_test.go @@ -0,0 +1,29 @@ +/* + Copyright 2025, NVIDIA CORPORATION & AFFILIATES + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package udev + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestUdev(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Udev Suite") +} diff --git a/entrypoint/internal/utils/udev/udev_test.go b/entrypoint/internal/utils/udev/udev_test.go new file mode 100644 index 0000000..e9b40ac --- /dev/null +++ b/entrypoint/internal/utils/udev/udev_test.go @@ -0,0 +1,226 @@ +/* + Copyright 2025, NVIDIA CORPORATION & AFFILIATES + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package udev + +import ( + "context" + "os" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + + osMockPkg "github.com/Mellanox/doca-driver-build/entrypoint/internal/wrappers/mocks" +) + +// mockFileInfo is a simple mock implementation of os.FileInfo +type mockFileInfo struct{} + +func (m mockFileInfo) Name() string { return "mock" } +func (m mockFileInfo) Size() int64 { return 0 } +func (m mockFileInfo) Mode() os.FileMode { return 0 } +func (m mockFileInfo) ModTime() time.Time { return time.Now() } +func (m mockFileInfo) IsDir() bool { return false } +func (m mockFileInfo) Sys() interface{} { return nil } + +var _ = Describe("Udev", func() { + Context("CreateRules", func() { + var ( + u Interface + osMock *osMockPkg.OSWrapper + testPath string + ) + + BeforeEach(func() { + osMock = osMockPkg.NewOSWrapper(GinkgoT()) + testPath = "/host/etc/udev/rules.d/77-mlnx-net-names.rules" + u = New(testPath, osMock) + }) + + It("should create udev rules file successfully", func() { + expectedContent := `ACTION!="add", GOTO="mlnx_ofed_name_end" +SUBSYSTEM!="net", GOTO="mlnx_ofed_name_end" + +# Rename physical interfaces (first case) of virtual functions (second case). +# Example names: +# enp8s0f0np0 -> enp8s0f0 +# enp8s0f0np1v12 -> enp8s0f0v12 + +DRIVERS=="mlx5_core", ENV{ID_NET_NAME_PATH}!="", \ +PROGRAM="/bin/sh -c 'echo $env{ID_NET_NAME_PATH} | sed -r -e s/np[01]$// -e s/np[01]v/v/'", \ + ENV{ID_NET_NAME_PATH}="$result" + +DRIVERS=="mlx5_core", ENV{ID_NET_NAME_SLOT}!="", \ +PROGRAM="/bin/sh -c 'echo $env{ID_NET_NAME_SLOT} | sed -r -e s/np[01]$// -e s/np[01]v/v/'", \ + ENV{ID_NET_NAME_SLOT}="$result" + +LABEL="mlnx_ofed_name_end" +` + + osMock.EXPECT().WriteFile(testPath, []byte(expectedContent), os.FileMode(0o644)).Return(nil) + + err := u.CreateRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle file creation failure", func() { + osMock.EXPECT().WriteFile(testPath, mock.AnythingOfType("[]uint8"), os.FileMode(0o644)).Return(assert.AnError) + + err := u.CreateRules(context.Background()) + Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(assert.AnError)) + }) + + It("should handle different file paths", func() { + customPath := "/custom/path/to/udev/rules.d/99-custom.rules" + u = New(customPath, osMock) + + osMock.EXPECT().WriteFile(customPath, mock.AnythingOfType("[]uint8"), os.FileMode(0o644)).Return(nil) + + err := u.CreateRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle nested directory paths", func() { + nestedPath := "/host/etc/udev/rules.d/nested/deep/path/77-mlnx-net-names.rules" + u = New(nestedPath, osMock) + + osMock.EXPECT().WriteFile(nestedPath, mock.AnythingOfType("[]uint8"), os.FileMode(0o644)).Return(nil) + + err := u.CreateRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should create rules with correct content structure", func() { + var capturedContent []byte + osMock.EXPECT().WriteFile(testPath, mock.AnythingOfType("[]uint8"), os.FileMode(0o644)).Run(func(name string, data []byte, perm os.FileMode) { + capturedContent = data + }).Return(nil) + + err := u.CreateRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + + content := string(capturedContent) + Expect(content).To(ContainSubstring(`ACTION!="add", GOTO="mlnx_ofed_name_end"`)) + Expect(content).To(ContainSubstring(`SUBSYSTEM!="net", GOTO="mlnx_ofed_name_end"`)) + Expect(content).To(ContainSubstring(`DRIVERS=="mlx5_core", ENV{ID_NET_NAME_PATH}!=""`)) + Expect(content).To(ContainSubstring(`DRIVERS=="mlx5_core", ENV{ID_NET_NAME_SLOT}!=""`)) + Expect(content).To(ContainSubstring(`LABEL="mlnx_ofed_name_end"`)) + Expect(content).To(ContainSubstring(`sed -r -e s/np[01]$// -e s/np[01]v/v/`)) + }) + + It("should handle multiple calls to CreateRules", func() { + osMock.EXPECT().WriteFile(testPath, mock.AnythingOfType("[]uint8"), os.FileMode(0o644)).Return(nil).Times(2) + + err := u.CreateRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + + err = u.CreateRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + }) + + Context("RemoveRules", func() { + var ( + u Interface + osMock *osMockPkg.OSWrapper + testPath string + ) + + BeforeEach(func() { + osMock = osMockPkg.NewOSWrapper(GinkgoT()) + testPath = "/host/etc/udev/rules.d/77-mlnx-net-names.rules" + u = New(testPath, osMock) + }) + + It("should remove udev rules file when it exists", func() { + // Mock file exists check + osMock.EXPECT().Stat(testPath).Return(mockFileInfo{}, nil) + osMock.EXPECT().RemoveAll(testPath).Return(nil) + + err := u.RemoveRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle file not existing gracefully", func() { + // Mock file doesn't exist (Stat returns os.ErrNotExist) + osMock.EXPECT().Stat(testPath).Return(nil, os.ErrNotExist) + + err := u.RemoveRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle file removal failure", func() { + // Mock file exists but removal fails + osMock.EXPECT().Stat(testPath).Return(mockFileInfo{}, nil) + osMock.EXPECT().RemoveAll(testPath).Return(assert.AnError) + + err := u.RemoveRules(context.Background()) + Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(assert.AnError)) + }) + + It("should handle different file paths", func() { + customPath := "/custom/path/to/udev/rules.d/99-custom.rules" + u = New(customPath, osMock) + + osMock.EXPECT().Stat(customPath).Return(mockFileInfo{}, nil) + osMock.EXPECT().RemoveAll(customPath).Return(nil) + + err := u.RemoveRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle nested directory paths", func() { + nestedPath := "/host/etc/udev/rules.d/nested/deep/path/77-mlnx-net-names.rules" + u = New(nestedPath, osMock) + + osMock.EXPECT().Stat(nestedPath).Return(mockFileInfo{}, nil) + osMock.EXPECT().RemoveAll(nestedPath).Return(nil) + + err := u.RemoveRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle multiple calls to RemoveRules", func() { + // First call - file exists + osMock.EXPECT().Stat(testPath).Return(mockFileInfo{}, nil) + osMock.EXPECT().RemoveAll(testPath).Return(nil) + + err := u.RemoveRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + + // Second call - file no longer exists + osMock.EXPECT().Stat(testPath).Return(nil, os.ErrNotExist) + + err = u.RemoveRules(context.Background()) + Expect(err).ToNot(HaveOccurred()) + }) + + It("should handle Stat error other than file not found", func() { + // Mock Stat returning a different error (e.g., permission denied) + osMock.EXPECT().Stat(testPath).Return(nil, assert.AnError) + + err := u.RemoveRules(context.Background()) + Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(assert.AnError)) + }) + }) +})