diff --git a/cmd/client-keystone-auth/main.go b/cmd/client-keystone-auth/main.go index 86e10ba6c2..d8a39d0ffb 100644 --- a/cmd/client-keystone-auth/main.go +++ b/cmd/client-keystone-auth/main.go @@ -19,11 +19,12 @@ package main import ( "fmt" "io" + "net/http" "os" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/utils/openstack/clientconfig" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/utils/v2/openstack/clientconfig" "github.com/spf13/cobra" "k8s.io/component-base/cli" @@ -215,7 +216,7 @@ func handle() { token, err := keystone.GetToken(options) if err != nil { - if _, ok := err.(gophercloud.ErrDefault401); ok { + if gophercloud.ResponseCodeIs(err, http.StatusUnauthorized) { fmt.Println(errRespTemplate) os.Stderr.WriteString("Invalid user credentials were provided\n") os.Exit(0) diff --git a/go.mod b/go.mod index 90cfaf7da5..5c139510de 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.22.0 require ( github.com/container-storage-interface/spec v1.8.0 github.com/go-chi/chi/v5 v5.0.8 - github.com/gophercloud/gophercloud v1.6.0 - github.com/gophercloud/utils v0.0.0-20230330070308-5bd5e1d608f8 + github.com/gophercloud/gophercloud/v2 v2.0.0 + github.com/gophercloud/utils/v2 v2.0.0-20240701101423-2401526caee5 github.com/hashicorp/go-version v1.6.0 github.com/kubernetes-csi/csi-lib-utils v0.13.0 github.com/kubernetes-csi/csi-test/v5 v5.0.0 @@ -21,9 +21,8 @@ require ( github.com/spf13/viper v1.15.0 github.com/stretchr/testify v1.8.4 go.uber.org/goleak v1.3.0 - golang.org/x/net v0.23.0 - golang.org/x/sys v0.18.0 - golang.org/x/term v0.18.0 + golang.org/x/sys v0.21.0 + golang.org/x/term v0.21.0 google.golang.org/grpc v1.58.3 google.golang.org/protobuf v1.33.0 gopkg.in/gcfg.v1 v1.2.3 @@ -80,6 +79,7 @@ require ( github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect + github.com/gofrs/uuid/v5 v5.2.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect @@ -137,13 +137,14 @@ require ( go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect - golang.org/x/crypto v0.21.0 // indirect + golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect + golang.org/x/net v0.25.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.18.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect diff --git a/go.sum b/go.sum index c4f6fd3f77..b9f871e89a 100644 --- a/go.sum +++ b/go.sum @@ -144,6 +144,8 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofrs/uuid/v5 v5.2.0 h1:qw1GMx6/y8vhVsx626ImfKMuS5CvJmhIKKtuyvfajMM= +github.com/gofrs/uuid/v5 v5.2.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= @@ -232,11 +234,10 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ 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/gophercloud/gophercloud v1.3.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM= -github.com/gophercloud/gophercloud v1.6.0 h1:JwJN1bauRnWPba5ueWs9IluONHteXPWjjK+MvfM4krY= -github.com/gophercloud/gophercloud v1.6.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM= -github.com/gophercloud/utils v0.0.0-20230330070308-5bd5e1d608f8 h1:K9r5WEeAiaEgFZsuOP0OYjE4TtyFcCLG1nI08t9AP6A= -github.com/gophercloud/utils v0.0.0-20230330070308-5bd5e1d608f8/go.mod h1:VSalo4adEk+3sNkmVJLnhHoOyOYYS8sTWLG4mv5BKto= +github.com/gophercloud/gophercloud/v2 v2.0.0 h1:iH0x0Ji79a/ULzmq95fvOBAyie7+M+wUAEu+JrRMsCk= +github.com/gophercloud/gophercloud/v2 v2.0.0/go.mod h1:ZKbcGNjxFTSaP5wlvtLDdsppllD/UGGvXBPqcjeqA8Y= +github.com/gophercloud/utils/v2 v2.0.0-20240701101423-2401526caee5 h1:/mLIQMTyjIVfiwQkknJS9XxEPLFuB70ss+ZrofChBf8= +github.com/gophercloud/utils/v2 v2.0.0-20240701101423-2401526caee5/go.mod h1:3tI9DoiOJFBkqbOeAPqPns/QUnMCiflwYBvgR6KJdM4= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -248,7 +249,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= -github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -400,7 +400,6 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.etcd.io/etcd/api/v3 v3.5.10 h1:szRajuUUbLyppkhs9K6BRtjY37l66XQQmw7oZRANE4k= @@ -457,9 +456,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= 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= @@ -497,9 +495,8 @@ 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/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -539,10 +536,9 @@ golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= 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= @@ -565,9 +561,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ 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/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -617,16 +612,14 @@ golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= 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= @@ -635,9 +628,8 @@ 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.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= 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= @@ -695,9 +687,8 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 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= diff --git a/pkg/autohealing/cloudprovider/openstack/provider.go b/pkg/autohealing/cloudprovider/openstack/provider.go index 93fb151078..24058859cb 100644 --- a/pkg/autohealing/cloudprovider/openstack/provider.go +++ b/pkg/autohealing/cloudprovider/openstack/provider.go @@ -24,17 +24,16 @@ import ( "strings" "time" - "github.com/gophercloud/gophercloud" - gopenstack "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" - "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop" - "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clusters" - "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/nodegroups" - "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stackresources" - "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" - "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/v2" + gopenstack "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v2/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/volumeattach" + "github.com/gophercloud/gophercloud/v2/openstack/containerinfra/v1/clusters" + "github.com/gophercloud/gophercloud/v2/openstack/containerinfra/v1/nodegroups" + "github.com/gophercloud/gophercloud/v2/openstack/orchestration/v1/stackresources" + "github.com/gophercloud/gophercloud/v2/openstack/orchestration/v1/stacks" + "github.com/gophercloud/gophercloud/v2/pagination" uuid "github.com/pborman/uuid" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -97,7 +96,7 @@ func (provider CloudProvider) GetName() string { // getStackName finds the name of a stack matching a given ID. func (provider *CloudProvider) getStackName(stackID string) (string, error) { - stack, err := stacks.Find(provider.Heat, stackID).Extract() + stack, err := stacks.Find(context.TODO(), provider.Heat, stackID).Extract() if err != nil { return "", err } @@ -116,7 +115,7 @@ func (provider *CloudProvider) getAllStackResourceMapping(stackName, stackID str mapping := make(map[string]ResourceStackRelationship) - serverPages, err := stackresources.List(provider.Heat, stackName, stackID, stackresources.ListOpts{Depth: 2}).AllPages() + serverPages, err := stackresources.List(provider.Heat, stackName, stackID, stackresources.ListOpts{Depth: 2}).AllPages(context.TODO()) if err != nil { return m, err } @@ -156,15 +155,15 @@ func (provider *CloudProvider) getAllStackResourceMapping(stackName, stackID str } func (provider CloudProvider) waitForServerPoweredOff(serverID string, timeout time.Duration) error { - err := startstop.Stop(provider.Nova, serverID).ExtractErr() + ctx := context.Background() + err := servers.Stop(ctx, provider.Nova, serverID).ExtractErr() if err != nil { return err } - ctx := context.Background() err = wait.PollUntilContextTimeout(ctx, 3*time.Second, timeout, false, func(ctx context.Context) (bool, error) { - server, err := servers.Get(provider.Nova, serverID).Extract() + server, err := servers.Get(ctx, provider.Nova, serverID).Extract() if err != nil { return false, err } @@ -187,7 +186,7 @@ func (provider CloudProvider) waitForClusterComplete(clusterID string, timeout t ctx := context.Background() err := wait.PollUntilContextTimeout(ctx, 3*time.Second, timeout, false, func(ctx context.Context) (bool, error) { - cluster, err := clusters.Get(provider.Magnum, clusterID).Extract() + cluster, err := clusters.Get(ctx, provider.Magnum, clusterID).Extract() if err != nil { return false, err } @@ -204,14 +203,15 @@ func (provider CloudProvider) waitForClusterComplete(clusterID string, timeout t // server with the timeout. And if there is a root volume of the server, the root // volume ID will be returned. func (provider CloudProvider) waitForServerDetachVolumes(serverID string, timeout time.Duration) (string, error) { + ctx := context.Background() rootVolumeID := "" - err := volumeattach.List(provider.Nova, serverID).EachPage(func(page pagination.Page) (bool, error) { + err := volumeattach.List(provider.Nova, serverID).EachPage(ctx, func(ctx context.Context, page pagination.Page) (bool, error) { attachments, err := volumeattach.ExtractVolumeAttachments(page) if err != nil { return false, err } for _, attachment := range attachments { - volume, err := volumes.Get(provider.Cinder, attachment.VolumeID).Extract() + volume, err := volumes.Get(ctx, provider.Cinder, attachment.VolumeID).Extract() if err != nil { return false, fmt.Errorf("failed to get volume %s, error: %v", attachment.VolumeID, err) } @@ -225,7 +225,7 @@ func (provider CloudProvider) waitForServerDetachVolumes(serverID string, timeou if !bootable { log.Infof("detaching volume %s for instance %s", attachment.VolumeID, serverID) - err := volumeattach.Delete(provider.Nova, serverID, attachment.ID).ExtractErr() + err := volumeattach.Delete(ctx, provider.Nova, serverID, attachment.ID).ExtractErr() if err != nil { return false, fmt.Errorf("failed to detach volume %s from instance %s, error: %v", attachment.VolumeID, serverID, err) } @@ -239,10 +239,9 @@ func (provider CloudProvider) waitForServerDetachVolumes(serverID string, timeou if err != nil { return rootVolumeID, err } - ctx := context.Background() err = wait.PollUntilContextTimeout(ctx, 3*time.Second, timeout, false, func(ctx context.Context) (bool, error) { - server, err := servers.Get(provider.Nova, serverID).Extract() + server, err := servers.Get(ctx, provider.Nova, serverID).Extract() if err != nil { return false, err } @@ -282,7 +281,7 @@ func (provider CloudProvider) firstTimeRepair(n healthcheck.NodeInfo, serverID s if firstTimeUnhealthy { log.Infof("rebooting node %s to repair it", serverID) - if res := servers.Reboot(provider.Nova, serverID, servers.RebootOpts{Type: servers.SoftReboot}); res.Err != nil { + if res := servers.Reboot(context.TODO(), provider.Nova, serverID, servers.RebootOpts{Type: servers.SoftReboot}); res.Err != nil { // Usually it means the node is being rebooted log.Warningf("failed to reboot node %s, error: %v", serverID, res.Err) if strings.Contains(res.Err.Error(), "reboot_started") { @@ -376,7 +375,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { return fmt.Errorf("failed to update the health status of cluster %s, error: %v", clusterName, err) } - cluster, err := clusters.Get(provider.Magnum, clusterName).Extract() + cluster, err := clusters.Get(context.TODO(), provider.Magnum, clusterName).Extract() if err != nil { return fmt.Errorf("failed to get the cluster %s, error: %v", clusterName, err) } @@ -421,7 +420,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { NodesToRemove: nodesToReplace.List(), } - clusters.Resize(provider.Magnum, clusterName, opts) + clusters.Resize(context.TODO(), provider.Magnum, clusterName, opts) // Wait 10 seconds to make sure Magnum has already got the request // to avoid sending all of the resize API calls at the same time. time.Sleep(10 * time.Second) @@ -471,7 +470,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { } else { // Mark root volume as unhealthy if rootVolumeID != "" { - err = stackresources.MarkUnhealthy(provider.Heat, allMapping[serverID].StackName, allMapping[serverID].StackID, rootVolumeID, opts).ExtractErr() + err = stackresources.MarkUnhealthy(context.TODO(), provider.Heat, allMapping[serverID].StackName, allMapping[serverID].StackID, rootVolumeID, opts).ExtractErr() if err != nil { log.Errorf("failed to mark resource %s unhealthy, error: %v", rootVolumeID, err) } @@ -482,7 +481,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { log.Warningf("Failed to shutdown the server %s, error: %v", serverID, err) // If the server is failed to delete after 180s, then delete it to avoid the // stack update failure later. - res := servers.ForceDelete(provider.Nova, serverID) + res := servers.ForceDelete(context.TODO(), provider.Nova, serverID) if res.Err != nil { log.Warningf("Failed to delete the server %s, error: %v", serverID, err) } @@ -491,7 +490,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { log.Infof("Marking Nova VM %s(Heat resource %s) unhealthy for Heat stack %s", serverID, allMapping[serverID].ResourceID, cluster.StackID) // Mark VM as unhealthy - err = stackresources.MarkUnhealthy(provider.Heat, allMapping[serverID].StackName, allMapping[serverID].StackID, allMapping[serverID].ResourceID, opts).ExtractErr() + err = stackresources.MarkUnhealthy(context.TODO(), provider.Heat, allMapping[serverID].StackName, allMapping[serverID].StackID, allMapping[serverID].ResourceID, opts).ExtractErr() if err != nil { log.Errorf("failed to mark resource %s unhealthy, error: %v", serverID, err) } @@ -499,7 +498,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { delete(unHealthyNodes, serverID) } - if err := stacks.UpdatePatch(provider.Heat, clusterStackName, cluster.StackID, stacks.UpdateOpts{}).ExtractErr(); err != nil { + if err := stacks.UpdatePatch(context.TODO(), provider.Heat, clusterStackName, cluster.StackID, stacks.UpdateOpts{}).ExtractErr(); err != nil { return fmt.Errorf("failed to update Heat stack to rebuild resources, error: %v", err) } @@ -524,7 +523,7 @@ func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error { func (provider CloudProvider) getNodeGroup(clusterName string, node healthcheck.NodeInfo) (nodegroups.NodeGroup, error) { var ng nodegroups.NodeGroup - ngPages, err := nodegroups.List(provider.Magnum, clusterName, nodegroups.ListOpts{}).AllPages() + ngPages, err := nodegroups.List(provider.Magnum, clusterName, nodegroups.ListOpts{}).AllPages(context.TODO()) if err == nil { ngs, err := nodegroups.ExtractNodeGroups(ngPages) if err != nil { @@ -532,7 +531,7 @@ func (provider CloudProvider) getNodeGroup(clusterName string, node healthcheck. return ng, err } for _, ng := range ngs { - ngInfo, err := nodegroups.Get(provider.Magnum, clusterName, ng.UUID).Extract() + ngInfo, err := nodegroups.Get(context.TODO(), provider.Magnum, clusterName, ng.UUID).Extract() if err != nil { log.Warningf("Failed to get node group for cluster %s, error: %v", clusterName, err) return ng, err @@ -599,7 +598,7 @@ func (provider CloudProvider) UpdateHealthStatus(masters []healthcheck.NodeInfo, } log.Infof("updating cluster health status as %s for reason %s.", healthStatus, healthStatusReason) - res := clusters.Update(provider.Magnum, clusterName, updateOpts) + res := clusters.Update(context.TODO(), provider.Magnum, clusterName, updateOpts) if res.Err != nil { return fmt.Errorf("failed to update the health status of cluster %s error: %v", clusterName, res.Err) @@ -619,7 +618,7 @@ func (provider CloudProvider) UpdateHealthStatus(masters []healthcheck.NodeInfo, func (provider CloudProvider) Enabled() bool { clusterName := provider.Config.ClusterName - cluster, err := clusters.Get(provider.Magnum, clusterName).Extract() + cluster, err := clusters.Get(context.TODO(), provider.Magnum, clusterName).Extract() if err != nil { log.Warningf("failed to get the cluster %s, error: %v", clusterName, err) return false @@ -648,7 +647,7 @@ func (provider CloudProvider) Enabled() bool { log.Warningf("Failed to get the Heat stack ID for cluster %s, error: %v", clusterName, err) return false } - stack, err := stacks.Get(provider.Heat, clusterStackName, cluster.StackID).Extract() + stack, err := stacks.Get(context.TODO(), provider.Heat, clusterStackName, cluster.StackID).Extract() if err != nil { log.Warningf("Failed to get Heat stack %s for cluster %s, error: %v", cluster.StackID, clusterName, err) return false diff --git a/pkg/client/client.go b/pkg/client/client.go index 721f548fd3..e9be5312b2 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -17,6 +17,7 @@ limitations under the License. package client import ( + "context" "crypto/tls" "crypto/x509" "fmt" @@ -24,12 +25,10 @@ import ( "runtime" "strings" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts" - "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" - "github.com/gophercloud/utils/client" - "github.com/gophercloud/utils/openstack/clientconfig" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/utils/v2/client" + "github.com/gophercloud/utils/v2/openstack/clientconfig" "k8s.io/apimachinery/pkg/util/net" "k8s.io/client-go/util/cert" @@ -111,7 +110,7 @@ func (l Logger) Printf(format string, args ...interface{}) { var gc = "/github.com/gophercloud/gophercloud" // detect the depth of the actual function, which calls gophercloud code - // 10 is the common depth from the logger to "github.com/gophercloud/gophercloud" + // 10 is the common depth from the logger to "github.com/gophercloud/gophercloud/v2" for i := 10; i <= 20; i++ { if _, file, _, ok := runtime.Caller(i); ok && !found && strings.Contains(file, gc) { found = true @@ -166,10 +165,10 @@ func (authOpts AuthOpts) ToAuthOptions() gophercloud.AuthOptions { return *ao } -func (authOpts AuthOpts) ToAuth3Options() tokens.AuthOptions { +func (authOpts AuthOpts) ToAuth3Options() gophercloud.AuthOptions { ao := authOpts.ToAuthOptions() - var scope tokens.Scope + var scope gophercloud.AuthScope if ao.Scope != nil { scope.ProjectID = ao.Scope.ProjectID scope.ProjectName = ao.Scope.ProjectName @@ -177,7 +176,7 @@ func (authOpts AuthOpts) ToAuth3Options() tokens.AuthOptions { scope.DomainName = ao.Scope.DomainName } - return tokens.AuthOptions{ + return gophercloud.AuthOptions{ IdentityEndpoint: ao.IdentityEndpoint, UserID: ao.UserID, Username: ao.Username, @@ -187,7 +186,7 @@ func (authOpts AuthOpts) ToAuth3Options() tokens.AuthOptions { ApplicationCredentialID: ao.ApplicationCredentialID, ApplicationCredentialName: ao.ApplicationCredentialName, ApplicationCredentialSecret: ao.ApplicationCredentialSecret, - Scope: scope, + Scope: &scope, AllowReauth: ao.AllowReauth, } } @@ -298,18 +297,15 @@ func NewOpenStackClient(cfg *AuthOpts, userAgent string, extraUserAgent ...strin // if TrusteeID and TrusteePassword were defined, then use them opts.UserID = replaceEmpty(cfg.TrusteeID, opts.UserID) opts.Password = replaceEmpty(cfg.TrusteePassword, opts.Password) + opts.Scope.TrustID = replaceEmpty(cfg.TrustID, opts.Scope.TrustID) - authOptsExt := trusts.AuthOptsExt{ - TrustID: cfg.TrustID, - AuthOptionsBuilder: &opts, - } - err = openstack.AuthenticateV3(provider, authOptsExt, gophercloud.EndpointOpts{}) + err = openstack.AuthenticateV3(context.TODO(), provider, &opts, gophercloud.EndpointOpts{}) return provider, err } opts := cfg.ToAuthOptions() - err = openstack.Authenticate(provider, opts) + err = openstack.Authenticate(context.TODO(), provider, opts) return provider, err } diff --git a/pkg/client/service.go b/pkg/client/service.go index 91fd02954d..e5c47d7585 100644 --- a/pkg/client/service.go +++ b/pkg/client/service.go @@ -19,8 +19,8 @@ package client import ( "fmt" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" ) // NewNetworkV2 creates a ServiceClient that may be used with the neutron v2 API diff --git a/pkg/csi/cinder/controllerserver.go b/pkg/csi/cinder/controllerserver.go index fcf7aacbd7..cecc753c35 100644 --- a/pkg/csi/cinder/controllerserver.go +++ b/pkg/csi/cinder/controllerserver.go @@ -17,15 +17,15 @@ limitations under the License. package cinder import ( + "context" "fmt" "strconv" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/backups" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" "github.com/kubernetes-csi/csi-lib-utils/protosanitizer" - "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/timestamppb" diff --git a/pkg/csi/cinder/fake.go b/pkg/csi/cinder/fake.go index 3d3efbe28d..20903d4244 100644 --- a/pkg/csi/cinder/fake.go +++ b/pkg/csi/cinder/fake.go @@ -17,10 +17,11 @@ limitations under the License. package cinder import ( - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/backups" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - "golang.org/x/net/context" + "context" + + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" "k8s.io/cloud-provider-openstack/pkg/util/mount" ) diff --git a/pkg/csi/cinder/identityserver.go b/pkg/csi/cinder/identityserver.go index 553b7a88cc..7a73ac9870 100644 --- a/pkg/csi/cinder/identityserver.go +++ b/pkg/csi/cinder/identityserver.go @@ -17,8 +17,9 @@ limitations under the License. package cinder import ( + "context" + "github.com/container-storage-interface/spec/lib/go/csi" - "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "k8s.io/klog/v2" diff --git a/pkg/csi/cinder/nodeserver.go b/pkg/csi/cinder/nodeserver.go index 2c4879d4cc..f29049e6a1 100644 --- a/pkg/csi/cinder/nodeserver.go +++ b/pkg/csi/cinder/nodeserver.go @@ -17,6 +17,7 @@ limitations under the License. package cinder import ( + "context" "fmt" "os" "path/filepath" @@ -24,9 +25,8 @@ import ( "strings" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" "github.com/kubernetes-csi/csi-lib-utils/protosanitizer" - "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "k8s.io/klog/v2" diff --git a/pkg/csi/cinder/openstack/openstack.go b/pkg/csi/cinder/openstack/openstack.go index ee603bae74..c4e98b9063 100644 --- a/pkg/csi/cinder/openstack/openstack.go +++ b/pkg/csi/cinder/openstack/openstack.go @@ -21,12 +21,12 @@ import ( "net/http" "os" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/backups" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" "github.com/spf13/pflag" gcfg "gopkg.in/gcfg.v1" "k8s.io/cloud-provider-openstack/pkg/client" diff --git a/pkg/csi/cinder/openstack/openstack_backups.go b/pkg/csi/cinder/openstack/openstack_backups.go index ddc98cc624..e291309b45 100644 --- a/pkg/csi/cinder/openstack/openstack_backups.go +++ b/pkg/csi/cinder/openstack/openstack_backups.go @@ -19,14 +19,14 @@ limitations under the License. package openstack import ( + "context" "errors" "fmt" "strconv" "time" - "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/backups" - "golang.org/x/net/context" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" "k8s.io/cloud-provider-openstack/pkg/metrics" "k8s.io/klog/v2" ) @@ -79,7 +79,7 @@ func (os *OpenStack) CreateBackup(name, volID, snapshotID, availabilityZone stri // TODO: Do some check before really call openstack API on the input mc := metrics.NewMetricContext("backup", "create") - backup, err := backups.Create(blockstorageServiceClient, opts).Extract() + backup, err := backups.Create(context.TODO(), blockstorageServiceClient, opts).Extract() if mc.ObserveRequest(err) != nil { return &backups.Backup{}, err } @@ -115,7 +115,7 @@ func (os *OpenStack) ListBackups(filters map[string]string) ([]backups.Backup, e } mc := metrics.NewMetricContext("backup", "list") - allPages, err := backups.List(os.blockstorage, opts).AllPages() + allPages, err := backups.List(os.blockstorage, opts).AllPages(context.TODO()) if err != nil { return nil, err } @@ -134,7 +134,7 @@ func (os *OpenStack) ListBackups(filters map[string]string) ([]backups.Backup, e // DeleteBackup issues a request to delete the Backup with the specified ID from the Cinder backend. func (os *OpenStack) DeleteBackup(backupID string) error { mc := metrics.NewMetricContext("backup", "delete") - err := backups.Delete(os.blockstorage, backupID).ExtractErr() + err := backups.Delete(context.TODO(), os.blockstorage, backupID).ExtractErr() if mc.ObserveRequest(err) != nil { klog.Errorf("Failed to delete backup: %v", err) } @@ -144,7 +144,7 @@ func (os *OpenStack) DeleteBackup(backupID string) error { // GetBackupByID returns backup details by id. func (os *OpenStack) GetBackupByID(backupID string) (*backups.Backup, error) { mc := metrics.NewMetricContext("backup", "get") - backup, err := backups.Get(os.blockstorage, backupID).Extract() + backup, err := backups.Get(context.TODO(), os.blockstorage, backupID).Extract() if mc.ObserveRequest(err) != nil { klog.Errorf("Failed to get backup: %v", err) return nil, err diff --git a/pkg/csi/cinder/openstack/openstack_instances.go b/pkg/csi/cinder/openstack/openstack_instances.go index ae42c8437b..a4c093bf75 100644 --- a/pkg/csi/cinder/openstack/openstack_instances.go +++ b/pkg/csi/cinder/openstack/openstack_instances.go @@ -1,14 +1,16 @@ package openstack import ( - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + "context" + + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" "k8s.io/cloud-provider-openstack/pkg/metrics" ) // GetInstanceByID returns server with specified instanceID func (os *OpenStack) GetInstanceByID(instanceID string) (*servers.Server, error) { mc := metrics.NewMetricContext("server", "get") - server, err := servers.Get(os.compute, instanceID).Extract() + server, err := servers.Get(context.TODO(), os.compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { return nil, err } diff --git a/pkg/csi/cinder/openstack/openstack_mock.go b/pkg/csi/cinder/openstack/openstack_mock.go index 14fa4bba09..53263e1f8e 100644 --- a/pkg/csi/cinder/openstack/openstack_mock.go +++ b/pkg/csi/cinder/openstack/openstack_mock.go @@ -17,10 +17,10 @@ limitations under the License. package openstack import ( - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/backups" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" "github.com/stretchr/testify/mock" "k8s.io/cloud-provider-openstack/pkg/util/metadata" ) diff --git a/pkg/csi/cinder/openstack/openstack_snapshots.go b/pkg/csi/cinder/openstack/openstack_snapshots.go index c3405de1eb..6999f9e790 100644 --- a/pkg/csi/cinder/openstack/openstack_snapshots.go +++ b/pkg/csi/cinder/openstack/openstack_snapshots.go @@ -19,13 +19,14 @@ limitations under the License. package openstack import ( + "context" "fmt" "net/url" "strconv" "time" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/v2/pagination" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/cloud-provider-openstack/pkg/metrics" "k8s.io/klog/v2" @@ -71,7 +72,7 @@ func (os *OpenStack) CreateSnapshot(name, volID string, tags map[string]string) } // TODO: Do some check before really call openstack API on the input mc := metrics.NewMetricContext("snapshot", "create") - snap, err := snapshots.Create(os.blockstorage, opts).Extract() + snap, err := snapshots.Create(context.TODO(), os.blockstorage, opts).Extract() if mc.ObserveRequest(err) != nil { return &snapshots.Snapshot{}, err } @@ -107,7 +108,7 @@ func (os *OpenStack) ListSnapshots(filters map[string]string) ([]snapshots.Snaps } } mc := metrics.NewMetricContext("snapshot", "list") - err := snapshots.List(os.blockstorage, opts).EachPage(func(page pagination.Page) (bool, error) { + err := snapshots.List(os.blockstorage, opts).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { var err error snaps, err = snapshots.ExtractSnapshots(page) @@ -140,7 +141,7 @@ func (os *OpenStack) ListSnapshots(filters map[string]string) ([]snapshots.Snaps // DeleteSnapshot issues a request to delete the Snapshot with the specified ID from the Cinder backend func (os *OpenStack) DeleteSnapshot(snapID string) error { mc := metrics.NewMetricContext("snapshot", "delete") - err := snapshots.Delete(os.blockstorage, snapID).ExtractErr() + err := snapshots.Delete(context.TODO(), os.blockstorage, snapID).ExtractErr() if mc.ObserveRequest(err) != nil { klog.Errorf("Failed to delete snapshot: %v", err) } @@ -150,7 +151,7 @@ func (os *OpenStack) DeleteSnapshot(snapID string) error { // GetSnapshotByID returns snapshot details by id func (os *OpenStack) GetSnapshotByID(snapshotID string) (*snapshots.Snapshot, error) { mc := metrics.NewMetricContext("snapshot", "get") - s, err := snapshots.Get(os.blockstorage, snapshotID).Extract() + s, err := snapshots.Get(context.TODO(), os.blockstorage, snapshotID).Extract() if mc.ObserveRequest(err) != nil { klog.Errorf("Failed to get snapshot: %v", err) return nil, err diff --git a/pkg/csi/cinder/openstack/openstack_test.go b/pkg/csi/cinder/openstack/openstack_test.go index e6649b3436..f41eac2764 100644 --- a/pkg/csi/cinder/openstack/openstack_test.go +++ b/pkg/csi/cinder/openstack/openstack_test.go @@ -21,7 +21,7 @@ import ( "reflect" "testing" - "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/v2" "github.com/spf13/pflag" "github.com/stretchr/testify/assert" ) diff --git a/pkg/csi/cinder/openstack/openstack_volumes.go b/pkg/csi/cinder/openstack/openstack_volumes.go index 3da3de550d..116f35c467 100644 --- a/pkg/csi/cinder/openstack/openstack_volumes.go +++ b/pkg/csi/cinder/openstack/openstack_volumes.go @@ -17,15 +17,15 @@ limitations under the License. package openstack import ( + "context" "fmt" "net/url" "time" - "github.com/gophercloud/gophercloud/openstack" - volumeexpand "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/volumeattach" + "github.com/gophercloud/gophercloud/v2/pagination" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/cloud-provider-openstack/pkg/metrics" cpoerrors "k8s.io/cloud-provider-openstack/pkg/util/errors" @@ -79,7 +79,7 @@ func (os *OpenStack) CreateVolume(name string, size int, vtype, availability str } mc := metrics.NewMetricContext("volume", "create") - vol, err := volumes.Create(blockstorageClient, opts).Extract() + vol, err := volumes.Create(context.TODO(), blockstorageClient, opts, nil).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -94,7 +94,7 @@ func (os *OpenStack) ListVolumes(limit int, startingToken string) ([]volumes.Vol opts := volumes.ListOpts{Limit: limit, Marker: startingToken} mc := metrics.NewMetricContext("volume", "list") - err := volumes.List(os.blockstorage, opts).EachPage(func(page pagination.Page) (bool, error) { + err := volumes.List(os.blockstorage, opts).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { var err error vols, err = volumes.ExtractVolumes(page) @@ -141,7 +141,7 @@ func (os *OpenStack) GetVolumesByName(n string) ([]volumes.Volume, error) { opts := volumes.ListOpts{Name: n} mc := metrics.NewMetricContext("volume", "list") - pages, err := volumes.List(blockstorageClient, opts).AllPages() + pages, err := volumes.List(blockstorageClient, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } @@ -165,14 +165,14 @@ func (os *OpenStack) DeleteVolume(volumeID string) error { } mc := metrics.NewMetricContext("volume", "delete") - err = volumes.Delete(os.blockstorage, volumeID, nil).ExtractErr() + err = volumes.Delete(context.TODO(), os.blockstorage, volumeID, nil).ExtractErr() return mc.ObserveRequest(err) } // GetVolume retrieves Volume by its ID. func (os *OpenStack) GetVolume(volumeID string) (*volumes.Volume, error) { mc := metrics.NewMetricContext("volume", "get") - vol, err := volumes.Get(os.blockstorage, volumeID).Extract() + vol, err := volumes.Get(context.TODO(), os.blockstorage, volumeID).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -207,7 +207,7 @@ func (os *OpenStack) AttachVolume(instanceID, volumeID string) (string, error) { } mc := metrics.NewMetricContext("volume", "attach") - _, err = volumeattach.Create(computeServiceClient, instanceID, &volumeattach.CreateOpts{ + _, err = volumeattach.Create(context.TODO(), computeServiceClient, instanceID, &volumeattach.CreateOpts{ VolumeID: volume.ID, }).Extract() @@ -295,7 +295,7 @@ func (os *OpenStack) DetachVolume(instanceID, volumeID string) error { for _, att := range volume.Attachments { if att.ServerID == instanceID { mc := metrics.NewMetricContext("volume", "detach") - err = volumeattach.Delete(os.compute, instanceID, volume.ID).ExtractErr() + err = volumeattach.Delete(context.TODO(), os.compute, instanceID, volume.ID).ExtractErr() if mc.ObserveRequest(err) != nil { return fmt.Errorf("failed to detach volume %s from compute %s : %v", volume.ID, instanceID, err) } @@ -354,7 +354,7 @@ func (os *OpenStack) GetAttachmentDiskPath(instanceID, volumeID string) (string, // ExpandVolume expands the volume to new size func (os *OpenStack) ExpandVolume(volumeID string, status string, newSize int) error { - extendOpts := volumeexpand.ExtendSizeOpts{ + extendOpts := volumes.ExtendSizeOpts{ NewSize: newSize, } @@ -377,10 +377,10 @@ func (os *OpenStack) ExpandVolume(volumeID string, status string, newSize int) e blockstorageClient.Microversion = "3.42" mc := metrics.NewMetricContext("volume", "expand") - return mc.ObserveRequest(volumeexpand.ExtendSize(blockstorageClient, volumeID, extendOpts).ExtractErr()) + return mc.ObserveRequest(volumes.ExtendSize(context.TODO(), blockstorageClient, volumeID, extendOpts).ExtractErr()) case VolumeAvailableStatus: mc := metrics.NewMetricContext("volume", "expand") - return mc.ObserveRequest(volumeexpand.ExtendSize(os.blockstorage, volumeID, extendOpts).ExtractErr()) + return mc.ObserveRequest(volumes.ExtendSize(context.TODO(), os.blockstorage, volumeID, extendOpts).ExtractErr()) } // cinder volume can not be expanded when volume status is not volumeInUseStatus or not volumeAvailableStatus diff --git a/pkg/csi/cinder/utils.go b/pkg/csi/cinder/utils.go index 5758065cde..c4ecb6ffe9 100644 --- a/pkg/csi/cinder/utils.go +++ b/pkg/csi/cinder/utils.go @@ -1,13 +1,13 @@ package cinder import ( + "context" "fmt" "strings" "sync/atomic" "github.com/container-storage-interface/spec/lib/go/csi" "github.com/kubernetes-csi/csi-lib-utils/protosanitizer" - "golang.org/x/net/context" "google.golang.org/grpc" "k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack" "k8s.io/cloud-provider-openstack/pkg/util/metadata" diff --git a/pkg/csi/manila/csiclient/interface.go b/pkg/csi/manila/csiclient/interface.go index 51499c036b..9b2b944a64 100644 --- a/pkg/csi/manila/csiclient/interface.go +++ b/pkg/csi/manila/csiclient/interface.go @@ -18,9 +18,10 @@ package csiclient import ( "context" + "time" + "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc" - "time" ) type Node interface { diff --git a/pkg/csi/manila/manilaclient/builder.go b/pkg/csi/manila/manilaclient/builder.go index 2d3bd88864..fa2b53d62d 100644 --- a/pkg/csi/manila/manilaclient/builder.go +++ b/pkg/csi/manila/manilaclient/builder.go @@ -17,14 +17,15 @@ limitations under the License. package manilaclient import ( + "context" "fmt" "regexp" "strconv" "strings" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/apiversions" "k8s.io/cloud-provider-openstack/pkg/client" ) @@ -98,7 +99,7 @@ func compareManilaVersionsLessThan(a, b string) bool { } func validateManilaClient(c *gophercloud.ServiceClient) error { - serverVersion, err := apiversions.Get(c, "v2").Extract() + serverVersion, err := apiversions.Get(context.TODO(), c, "v2").Extract() if err != nil { return fmt.Errorf("failed to get Manila v2 API microversions: %v", err) } diff --git a/pkg/csi/manila/manilaclient/client.go b/pkg/csi/manila/manilaclient/client.go index 46a9a0cc06..1e0962b79e 100644 --- a/pkg/csi/manila/manilaclient/client.go +++ b/pkg/csi/manila/manilaclient/client.go @@ -17,14 +17,16 @@ limitations under the License. package manilaclient import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/messages" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots" - shares_utils "github.com/gophercloud/utils/openstack/sharedfilesystems/v2/shares" - sharetypes_utils "github.com/gophercloud/utils/openstack/sharedfilesystems/v2/sharetypes" - snapshots_utils "github.com/gophercloud/utils/openstack/sharedfilesystems/v2/snapshots" + "context" + + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/messages" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/sharetypes" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/snapshots" + shares_utils "github.com/gophercloud/utils/v2/openstack/sharedfilesystems/v2/shares" + sharetypes_utils "github.com/gophercloud/utils/v2/openstack/sharedfilesystems/v2/sharetypes" + snapshots_utils "github.com/gophercloud/utils/v2/openstack/sharedfilesystems/v2/snapshots" ) type Client struct { @@ -32,73 +34,73 @@ type Client struct { } func (c Client) GetShareByID(shareID string) (*shares.Share, error) { - return shares.Get(c.c, shareID).Extract() + return shares.Get(context.TODO(), c.c, shareID).Extract() } func (c Client) GetShareByName(shareName string) (*shares.Share, error) { - shareID, err := shares_utils.IDFromName(c.c, shareName) + shareID, err := shares_utils.IDFromName(context.TODO(), c.c, shareName) if err != nil { return nil, err } - return shares.Get(c.c, shareID).Extract() + return shares.Get(context.TODO(), c.c, shareID).Extract() } func (c Client) CreateShare(opts shares.CreateOptsBuilder) (*shares.Share, error) { - return shares.Create(c.c, opts).Extract() + return shares.Create(context.TODO(), c.c, opts).Extract() } func (c Client) DeleteShare(shareID string) error { - return shares.Delete(c.c, shareID).ExtractErr() + return shares.Delete(context.TODO(), c.c, shareID).ExtractErr() } func (c Client) ExtendShare(shareID string, opts shares.ExtendOptsBuilder) error { - return shares.Extend(c.c, shareID, opts).ExtractErr() + return shares.Extend(context.TODO(), c.c, shareID, opts).ExtractErr() } func (c Client) GetExportLocations(shareID string) ([]shares.ExportLocation, error) { - return shares.ListExportLocations(c.c, shareID).Extract() + return shares.ListExportLocations(context.TODO(), c.c, shareID).Extract() } func (c Client) SetShareMetadata(shareID string, opts shares.SetMetadataOptsBuilder) (map[string]string, error) { - return shares.SetMetadata(c.c, shareID, opts).Extract() + return shares.SetMetadata(context.TODO(), c.c, shareID, opts).Extract() } func (c Client) GetAccessRights(shareID string) ([]shares.AccessRight, error) { - return shares.ListAccessRights(c.c, shareID).Extract() + return shares.ListAccessRights(context.TODO(), c.c, shareID).Extract() } func (c Client) GrantAccess(shareID string, opts shares.GrantAccessOptsBuilder) (*shares.AccessRight, error) { - return shares.GrantAccess(c.c, shareID, opts).Extract() + return shares.GrantAccess(context.TODO(), c.c, shareID, opts).Extract() } func (c Client) GetSnapshotByID(snapID string) (*snapshots.Snapshot, error) { - return snapshots.Get(c.c, snapID).Extract() + return snapshots.Get(context.TODO(), c.c, snapID).Extract() } func (c Client) GetSnapshotByName(snapName string) (*snapshots.Snapshot, error) { - snapID, err := snapshots_utils.IDFromName(c.c, snapName) + snapID, err := snapshots_utils.IDFromName(context.TODO(), c.c, snapName) if err != nil { return nil, err } - return snapshots.Get(c.c, snapID).Extract() + return snapshots.Get(context.TODO(), c.c, snapID).Extract() } func (c Client) CreateSnapshot(opts snapshots.CreateOptsBuilder) (*snapshots.Snapshot, error) { - return snapshots.Create(c.c, opts).Extract() + return snapshots.Create(context.TODO(), c.c, opts).Extract() } func (c Client) DeleteSnapshot(snapID string) error { - return snapshots.Delete(c.c, snapID).ExtractErr() + return snapshots.Delete(context.TODO(), c.c, snapID).ExtractErr() } func (c Client) GetExtraSpecs(shareTypeID string) (sharetypes.ExtraSpecs, error) { - return sharetypes.GetExtraSpecs(c.c, shareTypeID).Extract() + return sharetypes.GetExtraSpecs(context.TODO(), c.c, shareTypeID).Extract() } func (c Client) GetShareTypes() ([]sharetypes.ShareType, error) { - allPages, err := sharetypes.List(c.c, sharetypes.ListOpts{}).AllPages() + allPages, err := sharetypes.List(c.c, sharetypes.ListOpts{}).AllPages(context.TODO()) if err != nil { return nil, err } @@ -107,11 +109,11 @@ func (c Client) GetShareTypes() ([]sharetypes.ShareType, error) { } func (c Client) GetShareTypeIDFromName(shareTypeName string) (string, error) { - return sharetypes_utils.IDFromName(c.c, shareTypeName) + return sharetypes_utils.IDFromName(context.TODO(), c.c, shareTypeName) } func (c Client) GetUserMessages(opts messages.ListOptsBuilder) ([]messages.Message, error) { - allPages, err := messages.List(c.c, opts).AllPages() + allPages, err := messages.List(c.c, opts).AllPages(context.TODO()) if err != nil { return nil, err } diff --git a/pkg/csi/manila/manilaclient/interface.go b/pkg/csi/manila/manilaclient/interface.go index 0e01c64138..a6be597bcd 100644 --- a/pkg/csi/manila/manilaclient/interface.go +++ b/pkg/csi/manila/manilaclient/interface.go @@ -17,10 +17,10 @@ limitations under the License. package manilaclient import ( - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/messages" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/messages" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/sharetypes" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/snapshots" "k8s.io/cloud-provider-openstack/pkg/client" ) diff --git a/pkg/csi/manila/nodeserver.go b/pkg/csi/manila/nodeserver.go index 1d8dfda264..0c9da1824c 100644 --- a/pkg/csi/manila/nodeserver.go +++ b/pkg/csi/manila/nodeserver.go @@ -22,7 +22,7 @@ import ( "sync" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "k8s.io/cloud-provider-openstack/pkg/client" diff --git a/pkg/csi/manila/share.go b/pkg/csi/manila/share.go index 33badf09d5..f3f68f5982 100644 --- a/pkg/csi/manila/share.go +++ b/pkg/csi/manila/share.go @@ -20,7 +20,7 @@ import ( "fmt" "time" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "k8s.io/apimachinery/pkg/util/wait" diff --git a/pkg/csi/manila/shareadapters/cephfs.go b/pkg/csi/manila/shareadapters/cephfs.go index 7ecd55181f..38b0e7119c 100644 --- a/pkg/csi/manila/shareadapters/cephfs.go +++ b/pkg/csi/manila/shareadapters/cephfs.go @@ -20,8 +20,8 @@ import ( "fmt" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" "k8s.io/apimachinery/pkg/util/wait" manilautil "k8s.io/cloud-provider-openstack/pkg/csi/manila/util" "k8s.io/klog/v2" diff --git a/pkg/csi/manila/shareadapters/nfs.go b/pkg/csi/manila/shareadapters/nfs.go index 63f771a6a9..ab24320741 100644 --- a/pkg/csi/manila/shareadapters/nfs.go +++ b/pkg/csi/manila/shareadapters/nfs.go @@ -21,8 +21,8 @@ import ( "net" "strings" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" "k8s.io/cloud-provider-openstack/pkg/csi/manila/runtimeconfig" manilautil "k8s.io/cloud-provider-openstack/pkg/csi/manila/util" "k8s.io/klog/v2" diff --git a/pkg/csi/manila/shareadapters/shareadapter.go b/pkg/csi/manila/shareadapters/shareadapter.go index f6cf115374..d1e1d6fe0e 100644 --- a/pkg/csi/manila/shareadapters/shareadapter.go +++ b/pkg/csi/manila/shareadapters/shareadapter.go @@ -17,7 +17,7 @@ limitations under the License. package shareadapters import ( - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" "k8s.io/cloud-provider-openstack/pkg/csi/manila/options" ) diff --git a/pkg/csi/manila/snapshot.go b/pkg/csi/manila/snapshot.go index 5fe2045421..79d8cd8d7c 100644 --- a/pkg/csi/manila/snapshot.go +++ b/pkg/csi/manila/snapshot.go @@ -20,7 +20,7 @@ import ( "fmt" "time" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/snapshots" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" clouderrors "k8s.io/cloud-provider-openstack/pkg/util/errors" diff --git a/pkg/csi/manila/util.go b/pkg/csi/manila/util.go index 090a6c80e4..67715bfc50 100644 --- a/pkg/csi/manila/util.go +++ b/pkg/csi/manila/util.go @@ -22,9 +22,9 @@ import ( "strings" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/messages" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/messages" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/snapshots" "google.golang.org/grpc/codes" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" "k8s.io/cloud-provider-openstack/pkg/csi/manila/options" diff --git a/pkg/csi/manila/util/exportlocation.go b/pkg/csi/manila/util/exportlocation.go index 902210e8af..8a3c3bb23f 100644 --- a/pkg/csi/manila/util/exportlocation.go +++ b/pkg/csi/manila/util/exportlocation.go @@ -17,7 +17,7 @@ import ( "errors" "strings" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" ) // Predicate type for filtering out export locations. diff --git a/pkg/csi/manila/util/exportlocation_test.go b/pkg/csi/manila/util/exportlocation_test.go index 0f383d0f5b..61b9aa5fe7 100644 --- a/pkg/csi/manila/util/exportlocation_test.go +++ b/pkg/csi/manila/util/exportlocation_test.go @@ -16,7 +16,7 @@ package util import ( "testing" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" ) // Tests FindExportLocation with AnyExportLocation predicate diff --git a/pkg/csi/manila/volumesource.go b/pkg/csi/manila/volumesource.go index 634040bef2..c7d20f4554 100644 --- a/pkg/csi/manila/volumesource.go +++ b/pkg/csi/manila/volumesource.go @@ -18,7 +18,7 @@ package manila import ( "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "k8s.io/apimachinery/pkg/util/wait" diff --git a/pkg/identity/keystone/authenticator.go b/pkg/identity/keystone/authenticator.go index 017d1d9f0c..6c7d2c433c 100644 --- a/pkg/identity/keystone/authenticator.go +++ b/pkg/identity/keystone/authenticator.go @@ -17,12 +17,13 @@ limitations under the License. package keystone import ( + "context" "fmt" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" - "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" - "github.com/gophercloud/gophercloud/openstack/identity/v3/users" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/groups" + "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens" + "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/users" "k8s.io/apiserver/pkg/authentication/user" ) @@ -54,7 +55,7 @@ func NewKeystoner(client *gophercloud.ServiceClient) *Keystoner { // revive:disable:unexported-return func (k *Keystoner) GetTokenInfo(token string) (*tokenInfo, error) { k.client.ProviderClient.SetToken(token) - ret := tokens.Get(k.client, token) + ret := tokens.Get(context.TODO(), k.client, token) tokenUser, err := ret.ExtractUser() if err != nil { @@ -91,7 +92,7 @@ func (k *Keystoner) GetTokenInfo(token string) (*tokenInfo, error) { func (k *Keystoner) GetGroups(token string, userID string) ([]string, error) { k.client.ProviderClient.SetToken(token) - allGroupPages, err := users.ListGroups(k.client, userID).AllPages() + allGroupPages, err := users.ListGroups(k.client, userID).AllPages(context.TODO()) if err != nil { return nil, fmt.Errorf("failed to get user groups from Keystone: %v", err) } diff --git a/pkg/identity/keystone/authenticator_test.go b/pkg/identity/keystone/authenticator_test.go index 5bb8d21c54..4deca5f90b 100644 --- a/pkg/identity/keystone/authenticator_test.go +++ b/pkg/identity/keystone/authenticator_test.go @@ -16,7 +16,7 @@ package keystone import ( "testing" - th "github.com/gophercloud/gophercloud/testhelper" + th "github.com/gophercloud/gophercloud/v2/testhelper" "k8s.io/apiserver/pkg/authentication/user" ) diff --git a/pkg/identity/keystone/authorizer.go b/pkg/identity/keystone/authorizer.go index 147f50587c..28f72fba89 100644 --- a/pkg/identity/keystone/authorizer.go +++ b/pkg/identity/keystone/authorizer.go @@ -23,7 +23,7 @@ import ( "strings" "sync" - "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/v2" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" diff --git a/pkg/identity/keystone/authorizer_test.go b/pkg/identity/keystone/authorizer_test.go index 066061beaa..ddd97e70be 100644 --- a/pkg/identity/keystone/authorizer_test.go +++ b/pkg/identity/keystone/authorizer_test.go @@ -20,9 +20,9 @@ import ( "os" "testing" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + th "github.com/gophercloud/gophercloud/v2/testhelper" "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authorization/authorizer" diff --git a/pkg/identity/keystone/keystone.go b/pkg/identity/keystone/keystone.go index 2a8e7933d5..39a6a2c768 100644 --- a/pkg/identity/keystone/keystone.go +++ b/pkg/identity/keystone/keystone.go @@ -25,9 +25,9 @@ import ( "time" "github.com/go-chi/chi/v5" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/utils" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/utils" "github.com/spf13/pflag" "gopkg.in/yaml.v2" apiv1 "k8s.io/api/core/v1" @@ -542,7 +542,7 @@ func createIdentityV3Provider(options gophercloud.AuthOptions, transport http.Ro versions := []*utils.Version{ {ID: "v3", Priority: 30, Suffix: "/v3/"}, } - chosen, _, err := utils.ChooseVersion(client, versions) + chosen, _, err := utils.ChooseVersion(context.TODO(), client, versions) if err != nil { return nil, fmt.Errorf("unable to find identity API v3 version : %v", err) } diff --git a/pkg/identity/keystone/sync_test.go b/pkg/identity/keystone/sync_test.go index 1d95530331..05c826df4c 100644 --- a/pkg/identity/keystone/sync_test.go +++ b/pkg/identity/keystone/sync_test.go @@ -21,7 +21,7 @@ import ( "strings" "testing" - th "github.com/gophercloud/gophercloud/testhelper" + th "github.com/gophercloud/gophercloud/v2/testhelper" ) func TestSyncConfigFromFile(t *testing.T) { diff --git a/pkg/identity/keystone/token_getter.go b/pkg/identity/keystone/token_getter.go index 12f0b5677c..68dd774e4f 100644 --- a/pkg/identity/keystone/token_getter.go +++ b/pkg/identity/keystone/token_getter.go @@ -17,15 +17,16 @@ limitations under the License. package keystone import ( + "context" "crypto/tls" "fmt" "net/http" "os" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" - "github.com/gophercloud/utils/client" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + tokens3 "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens" + "github.com/gophercloud/utils/v2/client" certutil "k8s.io/client-go/util/cert" osClient "k8s.io/cloud-provider-openstack/pkg/client" "k8s.io/cloud-provider-openstack/pkg/version" @@ -112,7 +113,7 @@ func GetToken(options Options) (*tokens3.Token, error) { } // Issue new unscoped token - result := tokens3.Create(v3Client, &options.AuthOptions) + result := tokens3.Create(context.TODO(), v3Client, &options.AuthOptions) if result.Err != nil { return token, result.Err } diff --git a/pkg/identity/keystone/token_getter_test.go b/pkg/identity/keystone/token_getter_test.go index cdc966fdf3..6562da7545 100644 --- a/pkg/identity/keystone/token_getter_test.go +++ b/pkg/identity/keystone/token_getter_test.go @@ -20,8 +20,8 @@ import ( "net/http" "testing" - "github.com/gophercloud/gophercloud" - th "github.com/gophercloud/gophercloud/testhelper" + "github.com/gophercloud/gophercloud/v2" + th "github.com/gophercloud/gophercloud/v2/testhelper" ) func TestTokenGetter(t *testing.T) { @@ -98,7 +98,7 @@ func TestTokenGetter(t *testing.T) { options.AuthOptions.Password = "wrongpw" _, err = GetToken(options) - if _, ok := err.(gophercloud.ErrDefault401); !ok { + if !gophercloud.ResponseCodeIs(err, http.StatusUnauthorized) { t.FailNow() } diff --git a/pkg/ingress/controller/controller.go b/pkg/ingress/controller/controller.go index 249813098c..6ffa241fe4 100644 --- a/pkg/ingress/controller/controller.go +++ b/pkg/ingress/controller/controller.go @@ -30,9 +30,9 @@ import ( "strings" "time" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/l7policies" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/groups" log "github.com/sirupsen/logrus" apiv1 "k8s.io/api/core/v1" nwv1 "k8s.io/api/networking/v1" diff --git a/pkg/ingress/controller/openstack/client.go b/pkg/ingress/controller/openstack/client.go index 518e322607..4a19dfab0a 100644 --- a/pkg/ingress/controller/openstack/client.go +++ b/pkg/ingress/controller/openstack/client.go @@ -19,8 +19,8 @@ package openstack import ( "fmt" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" log "github.com/sirupsen/logrus" "k8s.io/cloud-provider-openstack/pkg/client" diff --git a/pkg/ingress/controller/openstack/neutron.go b/pkg/ingress/controller/openstack/neutron.go index 0a3c0a0684..8e89646a16 100644 --- a/pkg/ingress/controller/openstack/neutron.go +++ b/pkg/ingress/controller/openstack/neutron.go @@ -17,16 +17,17 @@ limitations under the License. package openstack import ( + "context" "fmt" "strconv" "strings" - neutrontags "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" - "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + neutrontags "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/attributestags" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/floatingips" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/groups" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/rules" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets" log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -35,7 +36,7 @@ import ( ) func (os *OpenStack) getFloatingIPs(listOpts floatingips.ListOpts) ([]floatingips.FloatingIP, error) { - allPages, err := floatingips.List(os.neutron, listOpts).AllPages() + allPages, err := floatingips.List(os.neutron, listOpts).AllPages(context.TODO()) if err != nil { return []floatingips.FloatingIP{}, err } @@ -53,7 +54,7 @@ func (os *OpenStack) createFloatingIP(portID string, floatingNetworkID string, d FloatingNetworkID: floatingNetworkID, Description: description, } - return floatingips.Create(os.neutron, floatIPOpts).Extract() + return floatingips.Create(context.TODO(), os.neutron, floatIPOpts).Extract() } // associateFloatingIP associate an unused floating IP to a given Port @@ -62,7 +63,7 @@ func (os *OpenStack) associateFloatingIP(fip *floatingips.FloatingIP, portID str PortID: &portID, Description: &description, } - return floatingips.Update(os.neutron, fip.ID, updateOpts).Extract() + return floatingips.Update(context.TODO(), os.neutron, fip.ID, updateOpts).Extract() } // disassociateFloatingIP disassociate a floating IP from a port @@ -71,12 +72,12 @@ func (os *OpenStack) disassociateFloatingIP(fip *floatingips.FloatingIP, descrip PortID: new(string), Description: &description, } - return floatingips.Update(os.neutron, fip.ID, updateDisassociateOpts).Extract() + return floatingips.Update(context.TODO(), os.neutron, fip.ID, updateDisassociateOpts).Extract() } // GetSubnet get a subnet by the given ID. func (os *OpenStack) GetSubnet(subnetID string) (*subnets.Subnet, error) { - subnet, err := subnets.Get(os.neutron, subnetID).Extract() + subnet, err := subnets.Get(context.TODO(), os.neutron, subnetID).Extract() if err != nil { return nil, err } @@ -85,7 +86,7 @@ func (os *OpenStack) GetSubnet(subnetID string) (*subnets.Subnet, error) { // getPorts gets all the filtered ports. func (os *OpenStack) getPorts(listOpts ports.ListOpts) ([]ports.Port, error) { - allPages, err := ports.List(os.neutron, listOpts).AllPages() + allPages, err := ports.List(os.neutron, listOpts).AllPages(context.TODO()) if err != nil { return []ports.Port{}, err } @@ -108,7 +109,7 @@ func (os *OpenStack) EnsureFloatingIP(needDelete bool, portID string, existingfl // If needed, delete the floating IPs and return. if needDelete { for _, fip := range fips { - if err := floatingips.Delete(os.neutron, fip.ID).ExtractErr(); err != nil { + if err := floatingips.Delete(context.TODO(), os.neutron, fip.ID).ExtractErr(); err != nil { return "", err } } @@ -186,7 +187,7 @@ func (os *OpenStack) EnsureFloatingIP(needDelete bool, portID string, existingfl // GetSecurityGroups gets all the filtered security groups. func (os *OpenStack) GetSecurityGroups(listOpts groups.ListOpts) ([]groups.SecGroup, error) { - allPages, err := groups.List(os.neutron, listOpts).AllPages() + allPages, err := groups.List(os.neutron, listOpts).AllPages(context.TODO()) if err != nil { return []groups.SecGroup{}, err } @@ -211,7 +212,7 @@ func (os *OpenStack) EnsureSecurityGroup(needDelete bool, name string, descripti // If needed, delete the security groups and return. if needDelete { for _, group := range allGroups { - if err := groups.Delete(os.neutron, group.ID).ExtractErr(); err != nil { + if err := groups.Delete(context.TODO(), os.neutron, group.ID).ExtractErr(); err != nil { return "", err } } @@ -229,7 +230,7 @@ func (os *OpenStack) EnsureSecurityGroup(needDelete bool, name string, descripti Name: name, Description: description, } - group, err = groups.Create(os.neutron, createOpts).Extract() + group, err = groups.Create(context.TODO(), os.neutron, createOpts).Extract() if err != nil { return "", err } @@ -241,7 +242,7 @@ func (os *OpenStack) EnsureSecurityGroup(needDelete bool, name string, descripti //} for _, t := range tags { - if err := neutrontags.Add(os.neutron, "security_groups", group.ID, t).ExtractErr(); err != nil { + if err := neutrontags.Add(context.TODO(), os.neutron, "security_groups", group.ID, t).ExtractErr(); err != nil { return "", fmt.Errorf("failed to add tag %s to security group %s: %v", t, group.ID, err) } } @@ -259,7 +260,7 @@ func (os *OpenStack) EnsureSecurityGroupRules(sgID string, sourceIP string, dstP SecGroupID: sgID, RemoteIPPrefix: sourceIP, } - allPages, err := rules.List(os.neutron, listOpts).AllPages() + allPages, err := rules.List(os.neutron, listOpts).AllPages(context.TODO()) if err != nil { return err } @@ -272,7 +273,7 @@ func (os *OpenStack) EnsureSecurityGroupRules(sgID string, sourceIP string, dstP // Delete all the rules and return. for _, rule := range allRules { - if err := rules.Delete(os.neutron, rule.ID).ExtractErr(); err != nil { + if err := rules.Delete(context.TODO(), os.neutron, rule.ID).ExtractErr(); err != nil { return err } } @@ -291,7 +292,7 @@ func (os *OpenStack) EnsureSecurityGroupRules(sgID string, sourceIP string, dstP for _, rule := range allRules { if !dstPortsSet.Has(strconv.Itoa(rule.PortRangeMin)) { // Delete the rule - if err := rules.Delete(os.neutron, rule.ID).ExtractErr(); err != nil { + if err := rules.Delete(context.TODO(), os.neutron, rule.ID).ExtractErr(); err != nil { return err } } else { @@ -315,7 +316,7 @@ func (os *OpenStack) EnsureSecurityGroupRules(sgID string, sourceIP string, dstP RemoteIPPrefix: sourceIP, SecGroupID: sgID, } - if _, err := rules.Create(os.neutron, createOpts).Extract(); err != nil { + if _, err := rules.Create(context.TODO(), os.neutron, createOpts).Extract(); err != nil { return err } } @@ -345,7 +346,7 @@ func (os *OpenStack) EnsurePortSecurityGroup(needDelete bool, sgID string, nodes sgSet.Delete(sgID) newSGs := sets.List(sgSet) updateOpts := ports.UpdateOpts{SecurityGroups: &newSGs} - if _, err := ports.Update(os.neutron, port.ID, updateOpts).Extract(); err != nil { + if _, err := ports.Update(context.TODO(), os.neutron, port.ID, updateOpts).Extract(); err != nil { return err } @@ -357,7 +358,7 @@ func (os *OpenStack) EnsurePortSecurityGroup(needDelete bool, sgID string, nodes sgSet.Insert(sgID) newSGs := sets.List(sgSet) updateOpts := ports.UpdateOpts{SecurityGroups: &newSGs} - if _, err := ports.Update(os.neutron, port.ID, updateOpts).Extract(); err != nil { + if _, err := ports.Update(context.TODO(), os.neutron, port.ID, updateOpts).Extract(); err != nil { return err } diff --git a/pkg/ingress/controller/openstack/octavia.go b/pkg/ingress/controller/openstack/octavia.go index 7924595c07..c846c1e5fc 100644 --- a/pkg/ingress/controller/openstack/octavia.go +++ b/pkg/ingress/controller/openstack/octavia.go @@ -17,17 +17,18 @@ limitations under the License. package openstack import ( + "context" "errors" "fmt" "reflect" "strings" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/l7policies" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/loadbalancers" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" log "github.com/sirupsen/logrus" apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -260,7 +261,7 @@ func (os *OpenStack) waitLoadbalancerActiveProvisioningStatus(loadbalancerID str var provisioningStatus string err := wait.ExponentialBackoff(backoff, func() (bool, error) { - loadbalancer, err := loadbalancers.Get(os.Octavia, loadbalancerID).Extract() + loadbalancer, err := loadbalancers.Get(context.TODO(), os.Octavia, loadbalancerID).Extract() if err != nil { return false, err } @@ -298,7 +299,7 @@ func (os *OpenStack) EnsureLoadBalancer(name string, subnetID string, ingNamespa Provider: os.config.Octavia.Provider, FlavorID: flavorId, } - loadbalancer, err = loadbalancers.Create(os.Octavia, createOpts).Extract() + loadbalancer, err = loadbalancers.Create(context.TODO(), os.Octavia, createOpts).Extract() if err != nil { return nil, fmt.Errorf("error creating loadbalancer %v: %v", createOpts, err) } @@ -318,7 +319,7 @@ func (os *OpenStack) EnsureLoadBalancer(name string, subnetID string, ingNamespa // UpdateLoadBalancerDescription updates the load balancer description field. func (os *OpenStack) UpdateLoadBalancerDescription(lbID string, newDescription string) error { - _, err := loadbalancers.Update(os.Octavia, lbID, loadbalancers.UpdateOpts{ + _, err := loadbalancers.Update(context.TODO(), os.Octavia, lbID, loadbalancers.UpdateOpts{ Description: &newDescription, }).Extract() if err != nil { @@ -358,7 +359,7 @@ func (os *OpenStack) EnsureListener(name string, lbID string, secretRefs []strin if len(listenerAllowedCIDRs) > 0 { opts.AllowedCIDRs = listenerAllowedCIDRs } - listener, err = listeners.Create(os.Octavia, opts).Extract() + listener, err = listeners.Create(context.TODO(), os.Octavia, opts).Extract() if err != nil { return nil, fmt.Errorf("error creating listener: %v", err) } @@ -381,7 +382,7 @@ func (os *OpenStack) EnsureListener(name string, lbID string, secretRefs []strin } if updateOpts != (listeners.UpdateOpts{}) { - _, err := listeners.Update(os.Octavia, listener.ID, updateOpts).Extract() + _, err := listeners.Update(context.TODO(), os.Octavia, listener.ID, updateOpts).Extract() if err != nil { return nil, fmt.Errorf("failed to update listener options: %v", err) } @@ -412,7 +413,7 @@ func (os *OpenStack) EnsurePoolMembers(deleted bool, poolName string, lbID strin } // Delete the existing pool, members are deleted automatically - err = pools.Delete(os.Octavia, pool.ID).ExtractErr() + err = pools.Delete(context.TODO(), os.Octavia, pool.ID).ExtractErr() if err != nil && !cpoerrors.IsNotFound(err) { return nil, fmt.Errorf("error deleting pool %s: %v", pool.ID, err) } @@ -452,7 +453,7 @@ func (os *OpenStack) EnsurePoolMembers(deleted bool, poolName string, lbID strin Persistence: nil, } } - pool, err = pools.Create(os.Octavia, opts).Extract() + pool, err = pools.Create(context.TODO(), os.Octavia, opts).Extract() if err != nil { return nil, fmt.Errorf("error creating pool: %v", err) } @@ -505,7 +506,7 @@ func (os *OpenStack) EnsurePoolMembers(deleted bool, poolName string, lbID strin return nil, fmt.Errorf("error because no members in pool: %s", pool.ID) } - if err := pools.BatchUpdateMembers(os.Octavia, pool.ID, members).ExtractErr(); err != nil { + if err := pools.BatchUpdateMembers(context.TODO(), os.Octavia, pool.ID, members).ExtractErr(); err != nil { return nil, fmt.Errorf("error batch updating members for pool %s: %v", pool.ID, err) } _, err = os.waitLoadbalancerActiveProvisioningStatus(lbID) diff --git a/pkg/kms/barbican/barbican.go b/pkg/kms/barbican/barbican.go index 460d0220d0..f56b9a77df 100644 --- a/pkg/kms/barbican/barbican.go +++ b/pkg/kms/barbican/barbican.go @@ -1,9 +1,11 @@ package barbican import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + "context" + + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack" + "github.com/gophercloud/gophercloud/v2/openstack/keymanager/v1/secrets" "k8s.io/cloud-provider-openstack/pkg/client" ) @@ -41,7 +43,7 @@ func (barbican *Barbican) GetSecret(keyID string) ([]byte, error) { PayloadContentType: "application/octet-stream", } - key, err := secrets.GetPayload(barbican.Client, keyID, opts).Extract() + key, err := secrets.GetPayload(context.TODO(), barbican.Client, keyID, opts).Extract() if err != nil { return nil, err } diff --git a/pkg/kms/client/client.go b/pkg/kms/client/client.go index e04c8897a6..6b10e37f3b 100644 --- a/pkg/kms/client/client.go +++ b/pkg/kms/client/client.go @@ -1,9 +1,9 @@ package main import ( + "context" "log" - "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" pb "k8s.io/kms/apis/v2" diff --git a/pkg/kms/server/server.go b/pkg/kms/server/server.go index 363cfc3e5f..b3f0242032 100644 --- a/pkg/kms/server/server.go +++ b/pkg/kms/server/server.go @@ -1,11 +1,11 @@ package server import ( + "context" "fmt" "net" "os" - "golang.org/x/net/context" "golang.org/x/sys/unix" "google.golang.org/grpc" gcfg "gopkg.in/gcfg.v1" diff --git a/pkg/kms/server/server_test.go b/pkg/kms/server/server_test.go index f1f2fdff0c..7674ffa311 100644 --- a/pkg/kms/server/server_test.go +++ b/pkg/kms/server/server_test.go @@ -2,9 +2,9 @@ package server import ( "bytes" + "context" "testing" - "golang.org/x/net/context" "k8s.io/cloud-provider-openstack/pkg/kms/barbican" pb "k8s.io/kms/apis/v2" ) diff --git a/pkg/openstack/instances.go b/pkg/openstack/instances.go index 60c7745411..f799c6137c 100644 --- a/pkg/openstack/instances.go +++ b/pkg/openstack/instances.go @@ -26,12 +26,12 @@ import ( "sort" "strings" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" - neutronports "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/networks" + neutronports "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/v2/pagination" "github.com/mitchellh/mapstructure" v1 "k8s.io/api/core/v1" "k8s.io/klog/v2" @@ -229,7 +229,7 @@ func (i *Instances) NodeAddressesByProviderID(ctx context.Context, providerID st } mc := metrics.NewMetricContext("server", "get") - server, err := servers.Get(i.compute, instanceID).Extract() + server, err := servers.Get(ctx, i.compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { return []v1.NodeAddress{}, err @@ -267,7 +267,7 @@ func instanceExistsByProviderID(ctx context.Context, compute *gophercloud.Servic } mc := metrics.NewMetricContext("server", "get") - _, err = servers.Get(compute, instanceID).Extract() + _, err = servers.Get(ctx, compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { if errors.IsNotFound(err) { return false, nil @@ -301,7 +301,7 @@ func instanceShutdownByProviderID(ctx context.Context, compute *gophercloud.Serv } mc := metrics.NewMetricContext("server", "get") - server, err := servers.Get(compute, instanceID).Extract() + server, err := servers.Get(ctx, compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { return false, err } @@ -331,7 +331,7 @@ func (i *Instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud } mc := metrics.NewMetricContext("server", "get") - srv, err := servers.Get(i.compute, instanceID).Extract() + srv, err := servers.Get(ctx, i.compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -390,7 +390,7 @@ func (i *Instances) InstanceTypeByProviderID(ctx context.Context, providerID str } mc := metrics.NewMetricContext("server", "get") - server, err := servers.Get(i.compute, instanceID).Extract() + server, err := servers.Get(ctx, i.compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { return "", err @@ -407,7 +407,7 @@ func (i *Instances) InstanceType(ctx context.Context, name types.NodeName) (stri return "", err } - return srvInstanceType(i.compute, &srv.Server) + return srvInstanceType(i.compute, srv) } func srvInstanceType(client *gophercloud.ServiceClient, srv *servers.Server) (string, error) { @@ -429,7 +429,7 @@ func srvInstanceType(client *gophercloud.ServiceClient, srv *servers.Server) (st // get flavor name by id mc := metrics.NewMetricContext("flavor", "get") - f, err := flavors.Get(client, flavor).Extract() + f, err := flavors.Get(context.TODO(), client, flavor).Extract() if mc.ObserveRequest(err) == nil { if isValidLabelValue(f.Name) { return f.Name, nil @@ -536,19 +536,19 @@ func readInstanceID(searchOrder string) (string, error) { return "", err } -func getServerByName(client *gophercloud.ServiceClient, name types.NodeName) (*ServerAttributesExt, error) { +func getServerByName(client *gophercloud.ServiceClient, name types.NodeName) (*servers.Server, error) { opts := servers.ListOpts{ Name: fmt.Sprintf("^%s$", regexp.QuoteMeta(mapNodeNameToServerName(name))), } - var s []ServerAttributesExt - serverList := make([]ServerAttributesExt, 0, 1) + serverList := make([]servers.Server, 0, 1) mc := metrics.NewMetricContext("server", "list") pager := servers.List(client, opts) - err := pager.EachPage(func(page pagination.Page) (bool, error) { - if err := servers.ExtractServersInto(page, &s); err != nil { + err := pager.EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { + s, err := servers.ExtractServers(page) + if err != nil { return false, err } serverList = append(serverList, s...) @@ -637,12 +637,12 @@ func nodeAddresses(srv *servers.Server, ports []PortWithTrunkDetails, client *go // This exposes the vlan networks to which subports are attached for _, port := range ports { for _, subport := range port.TrunkDetails.SubPorts { - p, err := neutronports.Get(client, subport.PortID).Extract() + p, err := neutronports.Get(context.TODO(), client, subport.PortID).Extract() if err != nil { klog.Errorf("Failed to get subport %s details: %v", subport.PortID, err) continue } - n, err := networks.Get(client, p.NetworkID).Extract() + n, err := networks.Get(context.TODO(), client, p.NetworkID).Extract() if err != nil { klog.Errorf("Failed to get subport %s network details: %v", subport.PortID, err) continue @@ -731,7 +731,7 @@ func getAddressesByName(client *gophercloud.ServiceClient, name types.NodeName, return nil, err } - return nodeAddresses(&srv.Server, ports, client, networkingOpts) + return nodeAddresses(srv, ports, client, networkingOpts) } // getAttachedPorts returns a list of ports attached to a server. @@ -742,7 +742,7 @@ func getAttachedPorts(client *gophercloud.ServiceClient, serverID string) ([]Por var ports []PortWithTrunkDetails - allPages, err := neutronports.List(client, listOpts).AllPages() + allPages, err := neutronports.List(client, listOpts).AllPages(context.TODO()) if err != nil { return ports, err } diff --git a/pkg/openstack/instancesv2.go b/pkg/openstack/instancesv2.go index 3e6f770f7e..c27c7a6ce3 100644 --- a/pkg/openstack/instancesv2.go +++ b/pkg/openstack/instancesv2.go @@ -21,8 +21,8 @@ import ( "fmt" sysos "os" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" v1 "k8s.io/api/core/v1" cloudprovider "k8s.io/cloud-provider" "k8s.io/cloud-provider-openstack/pkg/client" @@ -113,12 +113,12 @@ func (i *InstancesV2) InstanceMetadata(ctx context.Context, node *v1.Node) (*clo if err != nil { return nil, err } - server := ServerAttributesExt{} + var server servers.Server if srv != nil { server = *srv } - instanceType, err := srvInstanceType(i.compute, &server.Server) + instanceType, err := srvInstanceType(i.compute, &server) if err != nil { return nil, err } @@ -128,13 +128,13 @@ func (i *InstancesV2) InstanceMetadata(ctx context.Context, node *v1.Node) (*clo return nil, err } - addresses, err := nodeAddresses(&server.Server, ports, i.network, i.networkingOpts) + addresses, err := nodeAddresses(&server, ports, i.network, i.networkingOpts) if err != nil { return nil, err } return &cloudprovider.InstanceMetadata{ - ProviderID: i.makeInstanceID(&server.Server), + ProviderID: i.makeInstanceID(&server), InstanceType: instanceType, NodeAddresses: addresses, Zone: server.AvailabilityZone, @@ -149,19 +149,18 @@ func (i *InstancesV2) makeInstanceID(srv *servers.Server) string { return fmt.Sprintf("%s:///%s", ProviderName, srv.ID) } -func (i *InstancesV2) getInstance(ctx context.Context, node *v1.Node) (*ServerAttributesExt, error) { +func (i *InstancesV2) getInstance(ctx context.Context, node *v1.Node) (*servers.Server, error) { if node.Spec.ProviderID == "" { opt := servers.ListOpts{ Name: fmt.Sprintf("^%s$", node.Name), } mc := metrics.NewMetricContext("server", "list") - allPages, err := servers.List(i.compute, opt).AllPages() + allPages, err := servers.List(i.compute, opt).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, fmt.Errorf("error listing servers %v: %v", opt, err) } - serverList := []ServerAttributesExt{} - err = servers.ExtractServersInto(allPages, &serverList) + serverList, err := servers.ExtractServers(allPages) if err != nil { return nil, fmt.Errorf("error extracting servers from pages: %v", err) } @@ -183,14 +182,13 @@ func (i *InstancesV2) getInstance(ctx context.Context, node *v1.Node) (*ServerAt return nil, fmt.Errorf("ProviderID \"%s\" didn't match supported region \"%s\"", node.Spec.ProviderID, i.region) } - server := ServerAttributesExt{} mc := metrics.NewMetricContext("server", "get") - err = servers.Get(i.compute, instanceID).ExtractInto(&server) + server, err := servers.Get(context.TODO(), i.compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { if errors.IsNotFound(err) { return nil, cloudprovider.InstanceNotFound } return nil, err } - return &server, nil + return server, nil } diff --git a/pkg/openstack/loadbalancer.go b/pkg/openstack/loadbalancer.go index 7cf74011d6..2a82cba807 100644 --- a/pkg/openstack/loadbalancer.go +++ b/pkg/openstack/loadbalancer.go @@ -20,24 +20,26 @@ import ( "context" "encoding/json" "fmt" + "net/http" "regexp" "strconv" "strings" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" - "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" - v2monitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" - v2pools "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/keymanager/v1/containers" + "github.com/gophercloud/gophercloud/v2/openstack/keymanager/v1/secrets" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/loadbalancers" + v2monitors "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/monitors" + v2pools "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/floatingips" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" cloudprovider "k8s.io/cloud-provider" "k8s.io/klog/v2" netutils "k8s.io/utils/net" + "k8s.io/utils/ptr" "k8s.io/cloud-provider-openstack/pkg/metrics" cpoutil "k8s.io/cloud-provider-openstack/pkg/util" @@ -273,7 +275,7 @@ func (lbaas *LbaasV2) createOctaviaLoadBalancer(name, clusterName string, servic if !lbaas.opts.ProviderRequiresSerialAPICalls { for portIndex, port := range service.Spec.Ports { listenerCreateOpt := lbaas.buildListenerCreateOpt(port, svcConf, cpoutil.Sprintf255(listenerFormat, portIndex, name)) - members, newMembers, err := lbaas.buildBatchUpdateMemberOpts(port, nodes, svcConf) + members, newMembers, err := lbaas.buildCreateMemberOpts(port, nodes, svcConf) if err != nil { return nil, err } @@ -294,7 +296,7 @@ func (lbaas *LbaasV2) createOctaviaLoadBalancer(name, clusterName string, servic } mc := metrics.NewMetricContext("loadbalancer", "create") - loadbalancer, err := loadbalancers.Create(lbaas.lb, createOpts).Extract() + loadbalancer, err := loadbalancers.Create(context.TODO(), lbaas.lb, createOpts).Extract() if mc.ObserveRequest(err) != nil { var printObj interface{} = createOpts if opts, err := json.Marshal(createOpts); err == nil { @@ -576,7 +578,7 @@ func (lbaas *LbaasV2) deleteOctaviaListeners(lbID string, listenerList []listene func (lbaas *LbaasV2) createFloatingIP(msg string, floatIPOpts floatingips.CreateOpts) (*floatingips.FloatingIP, error) { klog.V(4).Infof("%s floating ip with opts %+v", msg, floatIPOpts) mc := metrics.NewMetricContext("floating_ip", "create") - floatIP, err := floatingips.Create(lbaas.network, floatIPOpts).Extract() + floatIP, err := floatingips.Create(context.TODO(), lbaas.network, floatIPOpts).Extract() err = PreserveGopherError(err) if mc.ObserveRequest(err) != nil { return floatIP, fmt.Errorf("error creating LB floatingip: %v", err) @@ -594,7 +596,7 @@ func (lbaas *LbaasV2) updateFloatingIP(floatingip *floatingips.FloatingIP, portI klog.V(4).Infof("Detaching floating ip %q from port %q", floatingip.FloatingIP, floatingip.PortID) } mc := metrics.NewMetricContext("floating_ip", "update") - floatingip, err := floatingips.Update(lbaas.network, floatingip.ID, floatUpdateOpts).Extract() + floatingip, err := floatingips.Update(context.TODO(), lbaas.network, floatingip.ID, floatUpdateOpts).Extract() if mc.ObserveRequest(err) != nil { return nil, fmt.Errorf("error updating LB floatingip %+v: %v", floatUpdateOpts, err) } @@ -1003,6 +1005,31 @@ func (lbaas *LbaasV2) buildBatchUpdateMemberOpts(port corev1.ServicePort, nodes return members, newMembers, nil } +func (lbaas *LbaasV2) buildCreateMemberOpts(port corev1.ServicePort, nodes []*corev1.Node, svcConf *serviceConfig) ([]v2pools.CreateMemberOpts, sets.Set[string], error) { + batchUpdateMemberOpts, newMembers, err := lbaas.buildBatchUpdateMemberOpts(port, nodes, svcConf) + if err != nil { + return nil, nil, err + } + + createMemberOpts := make([]v2pools.CreateMemberOpts, len(batchUpdateMemberOpts)) + for i := range batchUpdateMemberOpts { + createMemberOpts[i] = v2pools.CreateMemberOpts{ + Address: batchUpdateMemberOpts[i].Address, + ProtocolPort: batchUpdateMemberOpts[i].ProtocolPort, + Name: ptr.Deref(batchUpdateMemberOpts[i].Name, ""), + ProjectID: batchUpdateMemberOpts[i].ProjectID, + Weight: batchUpdateMemberOpts[i].Weight, + SubnetID: ptr.Deref(batchUpdateMemberOpts[i].SubnetID, ""), + AdminStateUp: batchUpdateMemberOpts[i].AdminStateUp, + Backup: batchUpdateMemberOpts[i].Backup, + MonitorAddress: ptr.Deref(batchUpdateMemberOpts[i].MonitorAddress, ""), + MonitorPort: batchUpdateMemberOpts[i].MonitorPort, + Tags: batchUpdateMemberOpts[i].Tags, + } + } + return createMemberOpts, newMembers, nil +} + // Make sure the listener is created for Service func (lbaas *LbaasV2) ensureOctaviaListener(lbID string, name string, curListenerMapping map[listenerKey]*listeners.Listener, port corev1.ServicePort, svcConf *serviceConfig, _ *corev1.Service) (*listeners.Listener, error) { listener, isPresent := curListenerMapping[listenerKey{ @@ -1371,13 +1398,13 @@ func (lbaas *LbaasV2) checkService(service *corev1.Service, nodes []*corev1.Node barbicanUUID := slice[len(slice)-1] barbicanType := slice[len(slice)-2] if barbicanType == "containers" { - container, err := containers.Get(lbaas.secret, barbicanUUID).Extract() + container, err := containers.Get(context.TODO(), lbaas.secret, barbicanUUID).Extract() if err != nil { return fmt.Errorf("failed to get tls container %q: %v", svcConf.tlsContainerRef, err) } klog.V(4).Infof("Default TLS container %q found", container.ContainerRef) } else if barbicanType == "secrets" { - secret, err := secrets.Get(lbaas.secret, barbicanUUID).Extract() + secret, err := secrets.Get(context.TODO(), lbaas.secret, barbicanUUID).Extract() if err != nil { return fmt.Errorf("failed to get tls secret %q: %v", svcConf.tlsContainerRef, err) } @@ -1488,7 +1515,7 @@ func (lbaas *LbaasV2) checkService(service *corev1.Service, nodes []*corev1.Node // check configured subnet belongs to network if floatingNetworkID != "" && floatingSubnet.subnetID != "" { mc := metrics.NewMetricContext("subnet", "get") - subnet, err := subnets.Get(lbaas.network, floatingSubnet.subnetID).Extract() + subnet, err := subnets.Get(context.TODO(), lbaas.network, floatingSubnet.subnetID).Extract() if mc.ObserveRequest(err) != nil { return fmt.Errorf("failed to find subnet %q: %v", floatingSubnet.subnetID, err) } @@ -1829,7 +1856,7 @@ func (lbaas *LbaasV2) listSubnetsForNetwork(networkID string, tweak ...TweakSubN } } mc := metrics.NewMetricContext("subnet", "list") - allPages, err := subnets.List(lbaas.network, opts).AllPages() + allPages, err := subnets.List(lbaas.network, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, fmt.Errorf("error listing subnets of network %s: %v", networkID, err) } @@ -1952,7 +1979,7 @@ func (lbaas *LbaasV2) deleteFIPIfCreatedByProvider(fip *floatingips.FloatingIP, } klog.InfoS("Deleting floating IP for service", "floatingIP", fip.FloatingIP, "service", klog.KObj(service)) mc := metrics.NewMetricContext("floating_ip", "delete") - err = floatingips.Delete(lbaas.network, fip.ID).ExtractErr() + err = floatingips.Delete(context.TODO(), lbaas.network, fip.ID).ExtractErr() if mc.ObserveRequest(err) != nil { return false, fmt.Errorf("failed to delete floating IP %s for loadbalancer VIP port %s: %v", fip.FloatingIP, portID, err) } @@ -2193,25 +2220,30 @@ func PreserveGopherError(rawError error) error { rawError = v.ErrOriginal } var details []byte - switch e := rawError.(type) { - case gophercloud.ErrDefault400: - case gophercloud.ErrDefault401: - details = e.Body - case gophercloud.ErrDefault403: - case gophercloud.ErrDefault404: - details = e.Body - case gophercloud.ErrDefault405: - details = e.Body - case gophercloud.ErrDefault408: - details = e.Body - case gophercloud.ErrDefault409: - case gophercloud.ErrDefault429: - details = e.Body - case gophercloud.ErrDefault500: - details = e.Body - case gophercloud.ErrDefault503: - details = e.Body - default: + + if e, ok := rawError.(gophercloud.ErrUnexpectedResponseCode); ok { + switch e.Actual { + case http.StatusBadRequest: + case http.StatusUnauthorized: + details = e.Body + case http.StatusForbidden: + case http.StatusNotFound: + details = e.Body + case http.StatusMethodNotAllowed: + details = e.Body + case http.StatusRequestTimeout: + details = e.Body + case http.StatusConflict: + case http.StatusTooManyRequests: + details = e.Body + case http.StatusInternalServerError: + details = e.Body + case http.StatusServiceUnavailable: + details = e.Body + default: + return rawError + } + } else { return rawError } diff --git a/pkg/openstack/loadbalancer_rename.go b/pkg/openstack/loadbalancer_rename.go index eab867d507..50eeb7fad5 100644 --- a/pkg/openstack/loadbalancer_rename.go +++ b/pkg/openstack/loadbalancer_rename.go @@ -18,16 +18,16 @@ package openstack import ( "fmt" - "k8s.io/cloud-provider-openstack/pkg/util" "regexp" "strings" - "github.com/gophercloud/gophercloud" + "k8s.io/cloud-provider-openstack/pkg/util" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/loadbalancers" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" openstackutil "k8s.io/cloud-provider-openstack/pkg/util/openstack" ) diff --git a/pkg/openstack/loadbalancer_rename_test.go b/pkg/openstack/loadbalancer_rename_test.go index 3e9f85cb13..3e2a751fea 100644 --- a/pkg/openstack/loadbalancer_rename_test.go +++ b/pkg/openstack/loadbalancer_rename_test.go @@ -17,10 +17,11 @@ limitations under the License. package openstack import ( - "k8s.io/cloud-provider-openstack/pkg/util" "strings" "testing" + "k8s.io/cloud-provider-openstack/pkg/util" + "github.com/stretchr/testify/assert" ) diff --git a/pkg/openstack/loadbalancer_sg.go b/pkg/openstack/loadbalancer_sg.go index f38a9d54b4..875de31e32 100644 --- a/pkg/openstack/loadbalancer_sg.go +++ b/pkg/openstack/loadbalancer_sg.go @@ -17,16 +17,17 @@ limitations under the License. package openstack import ( + "context" "fmt" "strings" - "github.com/gophercloud/gophercloud" - neutrontags "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" - neutronports "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" - secgroups "github.com/gophercloud/utils/openstack/networking/v2/extensions/security/groups" + "github.com/gophercloud/gophercloud/v2" + neutrontags "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/attributestags" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/groups" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/rules" + neutronports "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets" + secgroups "github.com/gophercloud/utils/v2/openstack/networking/v2/extensions/security/groups" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" @@ -91,7 +92,7 @@ func applyNodeSecurityGroupIDForLB(network *gophercloud.ServiceClient, svcConf * newSGs := append(port.SecurityGroups, sg) updateOpts := neutronports.UpdateOpts{SecurityGroups: &newSGs} mc := metrics.NewMetricContext("port", "update") - res := neutronports.Update(network, port.ID, updateOpts) + res := neutronports.Update(context.TODO(), network, port.ID, updateOpts) if mc.ObserveRequest(res.Err) != nil { return fmt.Errorf("failed to update security group for port %s: %v", port.ID, res.Err) } @@ -124,7 +125,7 @@ func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg strin // we don't trigger a lost update issue. updateOpts := neutronports.UpdateOpts{SecurityGroups: &newSGs} mc := metrics.NewMetricContext("port", "update") - res := neutronports.Update(network, port.ID, updateOpts) + res := neutronports.Update(context.TODO(), network, port.ID, updateOpts) if mc.ObserveRequest(res.Err) != nil { return fmt.Errorf("failed to update security group for port %s: %v", port.ID, res.Err) } @@ -133,7 +134,7 @@ func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg strin // so this stays for backward compatibility. It's reasonable to delete it in the future. 404s are ignored. if slices.Contains(port.Tags, sg) { mc = metrics.NewMetricContext("port_tag", "delete") - err := neutrontags.Delete(network, "ports", port.ID, sg).ExtractErr() + err := neutrontags.Delete(context.TODO(), network, "ports", port.ID, sg).ExtractErr() if mc.ObserveRequest(err) != nil { return fmt.Errorf("failed to remove tag %s to port %s: %v", sg, port.ID, res.Err) } @@ -146,7 +147,7 @@ func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg strin // group, if it not present. func (lbaas *LbaasV2) ensureSecurityRule(sgRuleCreateOpts rules.CreateOpts) error { mc := metrics.NewMetricContext("security_group_rule", "create") - _, err := rules.Create(lbaas.network, sgRuleCreateOpts).Extract() + _, err := rules.Create(context.TODO(), lbaas.network, sgRuleCreateOpts).Extract() if err != nil && cpoerrors.IsConflictError(err) { // Conflict means the SG rule already exists, so ignoring that error. klog.Warningf("Security group rule already found when trying to create it. This indicates concurrent "+ @@ -212,7 +213,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap // ensure security group for LB lbSecGroupName := getSecurityGroupName(apiService) - lbSecGroupID, err := secgroups.IDFromName(lbaas.network, lbSecGroupName) + lbSecGroupID, err := secgroups.IDFromName(context.TODO(), lbaas.network, lbSecGroupName) if err != nil { // If the security group of LB not exist, create it later if cpoerrors.IsNotFound(err) { @@ -229,7 +230,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap } mc := metrics.NewMetricContext("security_group", "create") - lbSecGroup, err := groups.Create(lbaas.network, lbSecGroupCreateOpts).Extract() + lbSecGroup, err := groups.Create(context.TODO(), lbaas.network, lbSecGroupCreateOpts).Extract() if mc.ObserveRequest(err) != nil { return fmt.Errorf("failed to create Security Group for loadbalancer service %s/%s: %v", apiService.Namespace, apiService.Name, err) } @@ -237,7 +238,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap } mc := metrics.NewMetricContext("subnet", "get") - subnet, err := subnets.Get(lbaas.network, svcConf.lbMemberSubnetID).Extract() + subnet, err := subnets.Get(context.TODO(), lbaas.network, svcConf.lbMemberSubnetID).Extract() if mc.ObserveRequest(err) != nil { return fmt.Errorf( "failed to find subnet %s from openstack: %v", svcConf.lbMemberSubnetID, err) @@ -315,7 +316,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap for _, existingRule := range toDelete { klog.Infof("Deleting rule %s from security group %s (%s)", existingRule.ID, existingRule.SecGroupID, lbSecGroupName) mc := metrics.NewMetricContext("security_group_rule", "delete") - err := rules.Delete(lbaas.network, existingRule.ID).ExtractErr() + err := rules.Delete(context.TODO(), lbaas.network, existingRule.ID).ExtractErr() if err != nil && cpoerrors.IsNotFound(err) { // ignore 404 klog.Warningf("Security group rule %s found missing when trying to delete it. This indicates concurrent "+ @@ -336,7 +337,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap func (lbaas *LbaasV2) ensureSecurityGroupDeleted(_ string, service *corev1.Service) error { // Generate Name lbSecGroupName := getSecurityGroupName(service) - lbSecGroupID, err := secgroups.IDFromName(lbaas.network, lbSecGroupName) + lbSecGroupID, err := secgroups.IDFromName(context.TODO(), lbaas.network, lbSecGroupName) if err != nil { if cpoerrors.IsNotFound(err) { // It is OK when the security group has been deleted by others. @@ -351,7 +352,7 @@ func (lbaas *LbaasV2) ensureSecurityGroupDeleted(_ string, service *corev1.Servi } mc := metrics.NewMetricContext("security_group", "delete") - lbSecGroup := groups.Delete(lbaas.network, lbSecGroupID) + lbSecGroup := groups.Delete(context.TODO(), lbaas.network, lbSecGroupID) if lbSecGroup.Err != nil && !cpoerrors.IsNotFound(lbSecGroup.Err) { return mc.ObserveRequest(lbSecGroup.Err) } diff --git a/pkg/openstack/loadbalancer_subnet_match.go b/pkg/openstack/loadbalancer_subnet_match.go index f2041bd583..790045b51b 100644 --- a/pkg/openstack/loadbalancer_subnet_match.go +++ b/pkg/openstack/loadbalancer_subnet_match.go @@ -21,7 +21,7 @@ import ( "regexp" "strings" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets" "gopkg.in/godo.v2/glob" ) diff --git a/pkg/openstack/loadbalancer_subnet_match_test.go b/pkg/openstack/loadbalancer_subnet_match_test.go index a999ab9ac7..8293877088 100644 --- a/pkg/openstack/loadbalancer_subnet_match_test.go +++ b/pkg/openstack/loadbalancer_subnet_match_test.go @@ -20,7 +20,7 @@ import ( "strings" "testing" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets" "github.com/stretchr/testify/assert" ) diff --git a/pkg/openstack/loadbalancer_test.go b/pkg/openstack/loadbalancer_test.go index bf3b5d63e2..a696282dea 100644 --- a/pkg/openstack/loadbalancer_test.go +++ b/pkg/openstack/loadbalancer_test.go @@ -7,11 +7,11 @@ import ( "sort" "testing" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" - v2monitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/listeners" + v2monitors "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/rules" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/openstack/openstack.go b/pkg/openstack/openstack.go index 1cc97ca480..e6b18189cd 100644 --- a/pkg/openstack/openstack.go +++ b/pkg/openstack/openstack.go @@ -24,12 +24,11 @@ import ( "strings" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunk_details" - neutronports "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/portsecurity" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/trunk_details" + neutronports "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" "github.com/spf13/pflag" gcfg "gopkg.in/gcfg.v1" "k8s.io/apimachinery/pkg/types" @@ -37,7 +36,7 @@ import ( cloudprovider "k8s.io/cloud-provider" "k8s.io/klog/v2" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/client-go/informers" coreinformers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes/scheme" @@ -153,11 +152,6 @@ type RouterOpts struct { RouterID string `gcfg:"router-id"` } -type ServerAttributesExt struct { - servers.Server - availabilityzones.ServerAvailabilityZoneExt -} - // OpenStack is an implementation of cloud provider Interface for OpenStack. type OpenStack struct { provider *gophercloud.ProviderClient @@ -424,18 +418,17 @@ func (os *OpenStack) GetZoneByProviderID(ctx context.Context, providerID string) return cloudprovider.Zone{}, err } - var serverWithAttributesExt ServerAttributesExt mc := metrics.NewMetricContext("server", "get") - err = servers.Get(compute, instanceID).ExtractInto(&serverWithAttributesExt) + server, err := servers.Get(ctx, compute, instanceID).Extract() if mc.ObserveRequest(err) != nil { return cloudprovider.Zone{}, err } zone := cloudprovider.Zone{ - FailureDomain: serverWithAttributesExt.AvailabilityZone, + FailureDomain: server.AvailabilityZone, Region: os.epOpts.Region, } - klog.V(4).Infof("The instance %s in zone %v", serverWithAttributesExt.Name, zone) + klog.V(4).Infof("The instance %s in zone %v", server.Name, zone) return zone, nil } diff --git a/pkg/openstack/openstack_test.go b/pkg/openstack/openstack_test.go index 1b436b5043..9e2ac70efc 100644 --- a/pkg/openstack/openstack_test.go +++ b/pkg/openstack/openstack_test.go @@ -26,9 +26,9 @@ import ( "testing" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - neutronports "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" + neutronports "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" "github.com/spf13/pflag" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/openstack/routes.go b/pkg/openstack/routes.go index 59cb5ba8b9..96bf8e5929 100644 --- a/pkg/openstack/routes.go +++ b/pkg/openstack/routes.go @@ -18,16 +18,17 @@ package openstack import ( "context" - openstackutil "k8s.io/cloud-provider-openstack/pkg/util/openstack" "net" "sync" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/extraroutes" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" - "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" + v1 "k8s.io/api/core/v1" + openstackutil "k8s.io/cloud-provider-openstack/pkg/util/openstack" + + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/extraroutes" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/routers" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" - "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" cloudprovider "k8s.io/cloud-provider" @@ -81,7 +82,7 @@ func (r *Routes) ListRoutes(ctx context.Context, clusterName string) ([]*cloudpr } mc := metrics.NewMetricContext("router", "get") - router, err := routers.Get(r.network, r.os.routeOpts.RouterID).Extract() + router, err := routers.Get(context.TODO(), r.network, r.os.routeOpts.RouterID).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -112,7 +113,7 @@ func getRouterNetworkIDs(network *gophercloud.ServiceClient, routerID string) ([ DeviceID: routerID, } mc := metrics.NewMetricContext("port", "list") - pages, err := ports.List(network, opts).AllPages() + pages, err := ports.List(network, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } @@ -176,7 +177,7 @@ func updateRoutes(network *gophercloud.ServiceClient, router *routers.Router, ne origRoutes := router.Routes // shallow copy mc := metrics.NewMetricContext("router", "update") - _, err := routers.Update(network, router.ID, routers.UpdateOpts{ + _, err := routers.Update(context.TODO(), network, router.ID, routers.UpdateOpts{ Routes: &newRoutes, }).Extract() if mc.ObserveRequest(err) != nil { @@ -186,7 +187,7 @@ func updateRoutes(network *gophercloud.ServiceClient, router *routers.Router, ne unwinder := func() { klog.V(4).Infof("Reverting routes change to router %v", router.ID) mc := metrics.NewMetricContext("router", "update") - _, err := routers.Update(network, router.ID, routers.UpdateOpts{ + _, err := routers.Update(context.TODO(), network, router.ID, routers.UpdateOpts{ Routes: &origRoutes, }).Extract() if mc.ObserveRequest(err) != nil { @@ -199,7 +200,7 @@ func updateRoutes(network *gophercloud.ServiceClient, router *routers.Router, ne func addRoute(network *gophercloud.ServiceClient, routerID string, newRoute []routers.Route) (func(), error) { mc := metrics.NewMetricContext("router", "update") - _, err := extraroutes.Add(network, routerID, extraroutes.Opts{ + _, err := extraroutes.Add(context.TODO(), network, routerID, extraroutes.Opts{ Routes: &newRoute, }).Extract() if mc.ObserveRequest(err) != nil { @@ -209,7 +210,7 @@ func addRoute(network *gophercloud.ServiceClient, routerID string, newRoute []ro unwinder := func() { klog.V(4).Infof("Reverting routes change to router %v", routerID) mc := metrics.NewMetricContext("router", "update") - _, err := extraroutes.Remove(network, routerID, extraroutes.Opts{ + _, err := extraroutes.Remove(context.TODO(), network, routerID, extraroutes.Opts{ Routes: &newRoute, }).Extract() if mc.ObserveRequest(err) != nil { @@ -222,7 +223,7 @@ func addRoute(network *gophercloud.ServiceClient, routerID string, newRoute []ro func removeRoute(network *gophercloud.ServiceClient, routerID string, oldRoute []routers.Route) (func(), error) { mc := metrics.NewMetricContext("router", "update") - _, err := extraroutes.Remove(network, routerID, extraroutes.Opts{ + _, err := extraroutes.Remove(context.TODO(), network, routerID, extraroutes.Opts{ Routes: &oldRoute, }).Extract() if mc.ObserveRequest(err) != nil { @@ -232,7 +233,7 @@ func removeRoute(network *gophercloud.ServiceClient, routerID string, oldRoute [ unwinder := func() { klog.V(4).Infof("Reverting routes change to router %v", routerID) mc := metrics.NewMetricContext("router", "update") - _, err := extraroutes.Add(network, routerID, extraroutes.Opts{ + _, err := extraroutes.Add(context.TODO(), network, routerID, extraroutes.Opts{ Routes: &oldRoute, }).Extract() if mc.ObserveRequest(err) != nil { @@ -247,7 +248,7 @@ func updateAllowedAddressPairs(network *gophercloud.ServiceClient, port *PortWit origPairs := port.AllowedAddressPairs // shallow copy mc := metrics.NewMetricContext("port", "update") - _, err := ports.Update(network, port.ID, ports.UpdateOpts{ + _, err := ports.Update(context.TODO(), network, port.ID, ports.UpdateOpts{ AllowedAddressPairs: &newPairs, }).Extract() if mc.ObserveRequest(err) != nil { @@ -257,7 +258,7 @@ func updateAllowedAddressPairs(network *gophercloud.ServiceClient, port *PortWit unwinder := func() { klog.V(4).Infof("Reverting allowed-address-pairs change to port %v", port.ID) mc := metrics.NewMetricContext("port", "update") - _, err := ports.Update(network, port.ID, ports.UpdateOpts{ + _, err := ports.Update(context.TODO(), network, port.ID, ports.UpdateOpts{ AllowedAddressPairs: &origPairs, }).Extract() if mc.ObserveRequest(err) != nil { @@ -294,7 +295,7 @@ func (r *Routes) CreateRoute(ctx context.Context, clusterName string, nameHint s defer r.Unlock() mc := metrics.NewMetricContext("router", "get") - router, err := routers.Get(r.network, r.os.routeOpts.RouterID).Extract() + router, err := routers.Get(context.TODO(), r.network, r.os.routeOpts.RouterID).Extract() if mc.ObserveRequest(err) != nil { return err } @@ -403,7 +404,7 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo defer r.Unlock() mc := metrics.NewMetricContext("router", "get") - router, err := routers.Get(r.network, r.os.routeOpts.RouterID).Extract() + router, err := routers.Get(context.TODO(), r.network, r.os.routeOpts.RouterID).Extract() if mc.ObserveRequest(err) != nil { return err } diff --git a/pkg/openstack/routes_test.go b/pkg/openstack/routes_test.go index 350b744254..c7d89c9864 100644 --- a/pkg/openstack/routes_test.go +++ b/pkg/openstack/routes_test.go @@ -21,9 +21,9 @@ import ( "net" "testing" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" - "k8s.io/api/core/v1" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/routers" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" cloudprovider "k8s.io/cloud-provider" @@ -170,7 +170,7 @@ func getServers(os *OpenStack) []servers.Server { opts := servers.ListOpts{ Status: "ACTIVE", } - allPages, err := servers.List(c, opts).AllPages() + allPages, err := servers.List(c, opts).AllPages(context.TODO()) if err != nil { panic(err) } @@ -190,7 +190,7 @@ func getRouters(os *OpenStack) []routers.Router { if err != nil { panic(err) } - allPages, err := routers.List(n, listOpts).AllPages() + allPages, err := routers.List(n, listOpts).AllPages(context.TODO()) if err != nil { panic(err) } diff --git a/pkg/util/errors/errors.go b/pkg/util/errors/errors.go index 8be1a6e97f..28d4ba29d5 100644 --- a/pkg/util/errors/errors.go +++ b/pkg/util/errors/errors.go @@ -20,7 +20,7 @@ import ( "errors" "net/http" - "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/v2" ) // ErrNotFound is used to inform that the object is missing @@ -47,47 +47,17 @@ func IsNotFound(err error) bool { return true } - if _, ok := err.(gophercloud.ErrDefault404); ok { - return true - } - if _, ok := err.(gophercloud.ErrResourceNotFound); ok { return true } - if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { - if errCode.Actual == http.StatusNotFound { - return true - } - } - - return false + return gophercloud.ResponseCodeIs(err, http.StatusNotFound) } func IsInvalidError(err error) bool { - if _, ok := err.(gophercloud.ErrDefault400); ok { - return true - } - - if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { - if errCode.Actual == http.StatusBadRequest { - return true - } - } - - return false + return gophercloud.ResponseCodeIs(err, http.StatusBadRequest) } func IsConflictError(err error) bool { - if _, ok := err.(gophercloud.ErrDefault409); ok { - return true - } - - if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { - if errCode.Actual == http.StatusConflict { - return true - } - } - - return false + return gophercloud.ResponseCodeIs(err, http.StatusConflict) } diff --git a/pkg/util/openstack/keymanager.go b/pkg/util/openstack/keymanager.go index ce35ffd0a0..23a5fb0d76 100644 --- a/pkg/util/openstack/keymanager.go +++ b/pkg/util/openstack/keymanager.go @@ -17,11 +17,12 @@ limitations under the License. package openstack import ( + "context" "fmt" "strings" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/keymanager/v1/secrets" "k8s.io/cloud-provider-openstack/pkg/metrics" cpoerrors "k8s.io/cloud-provider-openstack/pkg/util/errors" ) @@ -47,7 +48,7 @@ func GetSecret(client *gophercloud.ServiceClient, name string) (*secrets.Secret, Name: name, } mc := metrics.NewMetricContext("secret", "list") - allPages, err := secrets.List(client, listOpts).AllPages() + allPages, err := secrets.List(client, listOpts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } @@ -79,7 +80,7 @@ func CreateSecret(client *gophercloud.ServiceClient, name string, secretType str SecretType: secrets.OpaqueSecret, } mc := metrics.NewMetricContext("secret", "create") - secret, err := secrets.Create(client, createOpts).Extract() + secret, err := secrets.Create(context.TODO(), client, createOpts).Extract() if mc.ObserveRequest(err) != nil { return "", err } @@ -102,7 +103,7 @@ func DeleteSecrets(client *gophercloud.ServiceClient, partName string) error { SecretType: secrets.OpaqueSecret, } mc := metrics.NewMetricContext("secret", "list") - allPages, err := secrets.List(client, listOpts).AllPages() + allPages, err := secrets.List(client, listOpts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return err } @@ -118,7 +119,7 @@ func DeleteSecrets(client *gophercloud.ServiceClient, partName string) error { return err } mc := metrics.NewMetricContext("secret", "delete") - err = secrets.Delete(client, secretID).ExtractErr() + err = secrets.Delete(context.TODO(), client, secretID).ExtractErr() if mc.ObserveRequest(err) != nil && !cpoerrors.IsNotFound(err) { return err } diff --git a/pkg/util/openstack/loadbalancer.go b/pkg/util/openstack/loadbalancer.go index 2e9d9ef629..41654ab681 100644 --- a/pkg/util/openstack/loadbalancer.go +++ b/pkg/util/openstack/loadbalancer.go @@ -17,19 +17,20 @@ limitations under the License. package openstack import ( + "context" "fmt" "os" "strconv" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/apiversions" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" - "github.com/gophercloud/gophercloud/pagination" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/apiversions" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/l7policies" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/listeners" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/loadbalancers" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/monitors" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2/pagination" version "github.com/hashicorp/go-version" "k8s.io/apimachinery/pkg/util/wait" klog "k8s.io/klog/v2" @@ -67,7 +68,7 @@ func getOctaviaVersion(client *gophercloud.ServiceClient) (string, error) { var defaultVer = "0.0" mc := metrics.NewMetricContext("version", "list") - allPages, err := apiversions.List(client).AllPages() + allPages, err := apiversions.List(client).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return defaultVer, err } @@ -175,7 +176,7 @@ func WaitActiveAndGetLoadBalancer(client *gophercloud.ServiceClient, loadbalance err := wait.ExponentialBackoff(backoff, func() (bool, error) { mc := metrics.NewMetricContext("loadbalancer", "get") var err error - loadbalancer, err = loadbalancers.Get(client, loadbalancerID).Extract() + loadbalancer, err = loadbalancers.Get(context.TODO(), client, loadbalancerID).Extract() if mc.ObserveRequest(err) != nil { klog.Warningf("Failed to fetch loadbalancer status from OpenStack (lbID %q): %s", loadbalancerID, err) return false, nil @@ -201,7 +202,7 @@ func WaitActiveAndGetLoadBalancer(client *gophercloud.ServiceClient, loadbalance // GetLoadBalancers returns all the filtered load balancer. func GetLoadBalancers(client *gophercloud.ServiceClient, opts loadbalancers.ListOpts) ([]loadbalancers.LoadBalancer, error) { mc := metrics.NewMetricContext("loadbalancer", "list") - allPages, err := loadbalancers.List(client, opts).AllPages() + allPages, err := loadbalancers.List(client, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } @@ -216,7 +217,7 @@ func GetLoadBalancers(client *gophercloud.ServiceClient, opts loadbalancers.List // GetLoadbalancerByID retrieves loadbalancer object func GetLoadbalancerByID(client *gophercloud.ServiceClient, lbID string) (*loadbalancers.LoadBalancer, error) { mc := metrics.NewMetricContext("loadbalancer", "get") - lb, err := loadbalancers.Get(client, lbID).Extract() + lb, err := loadbalancers.Get(context.TODO(), client, lbID).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -230,7 +231,7 @@ func GetLoadbalancerByName(client *gophercloud.ServiceClient, name string) (*loa Name: name, } mc := metrics.NewMetricContext("loadbalancer", "list") - allPages, err := loadbalancers.List(client, opts).AllPages() + allPages, err := loadbalancers.List(client, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } @@ -263,7 +264,7 @@ func UpdateLoadBalancerTags(client *gophercloud.ServiceClient, lbID string, tags // UpdateLoadBalancer updates the load balancer func UpdateLoadBalancer(client *gophercloud.ServiceClient, lbID string, updateOpts loadbalancers.UpdateOpts) (*loadbalancers.LoadBalancer, error) { mc := metrics.NewMetricContext("loadbalancer", "update") - _, err := loadbalancers.Update(client, lbID, updateOpts).Extract() + _, err := loadbalancers.Update(context.TODO(), client, lbID, updateOpts).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -285,7 +286,7 @@ func waitLoadbalancerDeleted(client *gophercloud.ServiceClient, loadbalancerID s } err := wait.ExponentialBackoff(backoff, func() (bool, error) { mc := metrics.NewMetricContext("loadbalancer", "get") - _, err := loadbalancers.Get(client, loadbalancerID).Extract() + _, err := loadbalancers.Get(context.TODO(), client, loadbalancerID).Extract() if err != nil { if cpoerrors.IsNotFound(err) { klog.V(4).InfoS("Load balancer deleted", "lbID", loadbalancerID) @@ -311,7 +312,7 @@ func DeleteLoadbalancer(client *gophercloud.ServiceClient, lbID string, cascade } mc := metrics.NewMetricContext("loadbalancer", "delete") - err := loadbalancers.Delete(client, lbID, opts).ExtractErr() + err := loadbalancers.Delete(context.TODO(), client, lbID, opts).ExtractErr() if err != nil && !cpoerrors.IsNotFound(err) { _ = mc.ObserveRequest(err) return fmt.Errorf("error deleting loadbalancer %s: %v", lbID, err) @@ -328,7 +329,7 @@ func DeleteLoadbalancer(client *gophercloud.ServiceClient, lbID string, cascade // UpdateListener updates a listener and wait for the lb active func UpdateListener(client *gophercloud.ServiceClient, lbID string, listenerID string, opts listeners.UpdateOpts) error { mc := metrics.NewMetricContext("loadbalancer_listener", "update") - _, err := listeners.Update(client, listenerID, opts).Extract() + _, err := listeners.Update(context.TODO(), client, listenerID, opts).Extract() if mc.ObserveRequest(err) != nil { return err } @@ -343,7 +344,7 @@ func UpdateListener(client *gophercloud.ServiceClient, lbID string, listenerID s // CreateListener creates a new listener func CreateListener(client *gophercloud.ServiceClient, lbID string, opts listeners.CreateOpts) (*listeners.Listener, error) { mc := metrics.NewMetricContext("loadbalancer_listener", "create") - listener, err := listeners.Create(client, opts).Extract() + listener, err := listeners.Create(context.TODO(), client, opts).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -358,7 +359,7 @@ func CreateListener(client *gophercloud.ServiceClient, lbID string, opts listene // DeleteListener deletes a listener. func DeleteListener(client *gophercloud.ServiceClient, listenerID string, lbID string) error { mc := metrics.NewMetricContext("loadbalancer_listener", "delete") - if err := listeners.Delete(client, listenerID).ExtractErr(); mc.ObserveRequest(err) != nil { + if err := listeners.Delete(context.TODO(), client, listenerID).ExtractErr(); mc.ObserveRequest(err) != nil { if cpoerrors.IsNotFound(err) { klog.V(2).Infof("Listener %s for load balancer %s was already deleted: %v", listenerID, lbID, err) } else { @@ -384,7 +385,7 @@ func GetListenerByName(client *gophercloud.ServiceClient, name string, lbID stri pager := listeners.List(client, opts) var listenerList []listeners.Listener - err := pager.EachPage(func(page pagination.Page) (bool, error) { + err := pager.EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { v, err := listeners.ExtractListeners(page) if err != nil { return false, err @@ -414,7 +415,7 @@ func GetListenersByLoadBalancerID(client *gophercloud.ServiceClient, lbID string mc := metrics.NewMetricContext("loadbalancer_listener", "list") var lbListeners []listeners.Listener - allPages, err := listeners.List(client, listeners.ListOpts{LoadbalancerID: lbID}).AllPages() + allPages, err := listeners.List(client, listeners.ListOpts{LoadbalancerID: lbID}).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } @@ -429,7 +430,7 @@ func GetListenersByLoadBalancerID(client *gophercloud.ServiceClient, lbID string // CreatePool creates a new pool. func CreatePool(client *gophercloud.ServiceClient, opts pools.CreateOptsBuilder, lbID string) (*pools.Pool, error) { mc := metrics.NewMetricContext("loadbalancer_pool", "create") - pool, err := pools.Create(client, opts).Extract() + pool, err := pools.Create(context.TODO(), client, opts).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -450,7 +451,7 @@ func GetPoolByName(client *gophercloud.ServiceClient, name string, lbID string) LoadbalancerID: lbID, } mc := metrics.NewMetricContext("loadbalancer_pool", "list") - err := pools.List(client, opts).EachPage(func(page pagination.Page) (bool, error) { + err := pools.List(client, opts).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { v, err := pools.ExtractPools(page) if err != nil { return false, err @@ -482,7 +483,7 @@ func GetPoolByName(client *gophercloud.ServiceClient, name string, lbID string) func GetPoolByListener(client *gophercloud.ServiceClient, lbID, listenerID string) (*pools.Pool, error) { listenerPools := make([]pools.Pool, 0, 1) mc := metrics.NewMetricContext("loadbalancer_pool", "list") - err := pools.List(client, pools.ListOpts{LoadbalancerID: lbID}).EachPage(func(page pagination.Page) (bool, error) { + err := pools.List(client, pools.ListOpts{LoadbalancerID: lbID}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { poolsList, err := pools.ExtractPools(page) if err != nil { return false, err @@ -520,7 +521,7 @@ func GetPools(client *gophercloud.ServiceClient, lbID string) ([]pools.Pool, err opts := pools.ListOpts{ LoadbalancerID: lbID, } - allPages, err := pools.List(client, opts).AllPages() + allPages, err := pools.List(client, opts).AllPages(context.TODO()) if err != nil { return nil, err } @@ -538,7 +539,7 @@ func GetMembersbyPool(client *gophercloud.ServiceClient, poolID string) ([]pools var members []pools.Member mc := metrics.NewMetricContext("loadbalancer_member", "list") - err := pools.ListMembers(client, poolID, pools.ListMembersOpts{}).EachPage(func(page pagination.Page) (bool, error) { + err := pools.ListMembers(client, poolID, pools.ListMembersOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { membersList, err := pools.ExtractMembers(page) if err != nil { return false, err @@ -557,7 +558,7 @@ func GetMembersbyPool(client *gophercloud.ServiceClient, poolID string) ([]pools // UpdatePool updates a pool and wait for the lb active func UpdatePool(client *gophercloud.ServiceClient, lbID string, poolID string, opts pools.UpdateOpts) error { mc := metrics.NewMetricContext("loadbalancer_pool", "update") - _, err := pools.Update(client, poolID, opts).Extract() + _, err := pools.Update(context.TODO(), client, poolID, opts).Extract() if mc.ObserveRequest(err) != nil { return err } @@ -572,7 +573,7 @@ func UpdatePool(client *gophercloud.ServiceClient, lbID string, poolID string, o // DeletePool deletes a pool. func DeletePool(client *gophercloud.ServiceClient, poolID string, lbID string) error { mc := metrics.NewMetricContext("loadbalancer_pool", "delete") - if err := pools.Delete(client, poolID).ExtractErr(); mc.ObserveRequest(err) != nil { + if err := pools.Delete(context.TODO(), client, poolID).ExtractErr(); mc.ObserveRequest(err) != nil { if cpoerrors.IsNotFound(err) { klog.V(2).Infof("Pool %s for load balancer %s was already deleted: %v", poolID, lbID, err) } else { @@ -589,7 +590,7 @@ func DeletePool(client *gophercloud.ServiceClient, poolID string, lbID string) e // BatchUpdatePoolMembers updates pool members in batch. func BatchUpdatePoolMembers(client *gophercloud.ServiceClient, lbID string, poolID string, opts []pools.BatchUpdateMemberOpts) error { mc := metrics.NewMetricContext("loadbalancer_members", "update") - err := pools.BatchUpdateMembers(client, poolID, opts).ExtractErr() + err := pools.BatchUpdateMembers(context.TODO(), client, poolID, opts).ExtractErr() if mc.ObserveRequest(err) != nil { return err } @@ -607,7 +608,7 @@ func GetL7policies(client *gophercloud.ServiceClient, listenerID string) ([]l7po opts := l7policies.ListOpts{ ListenerID: listenerID, } - err := l7policies.List(client, opts).EachPage(func(page pagination.Page) (bool, error) { + err := l7policies.List(client, opts).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { v, err := l7policies.ExtractL7Policies(page) if err != nil { return false, err @@ -625,7 +626,7 @@ func GetL7policies(client *gophercloud.ServiceClient, listenerID string) ([]l7po // CreateL7Policy creates a l7 policy. func CreateL7Policy(client *gophercloud.ServiceClient, opts l7policies.CreateOpts, lbID string) (*l7policies.L7Policy, error) { mc := metrics.NewMetricContext("loadbalancer_l7policy", "create") - policy, err := l7policies.Create(client, opts).Extract() + policy, err := l7policies.Create(context.TODO(), client, opts).Extract() if mc.ObserveRequest(err) != nil { return nil, err } @@ -640,7 +641,7 @@ func CreateL7Policy(client *gophercloud.ServiceClient, opts l7policies.CreateOpt // DeleteL7policy deletes a l7 policy. func DeleteL7policy(client *gophercloud.ServiceClient, policyID string, lbID string) error { mc := metrics.NewMetricContext("loadbalancer_l7policy", "delete") - if err := l7policies.Delete(client, policyID).ExtractErr(); mc.ObserveRequest(err) != nil { + if err := l7policies.Delete(context.TODO(), client, policyID).ExtractErr(); mc.ObserveRequest(err) != nil { return err } @@ -654,7 +655,7 @@ func DeleteL7policy(client *gophercloud.ServiceClient, policyID string, lbID str // GetL7Rules gets all the rules for a l7 policy func GetL7Rules(client *gophercloud.ServiceClient, policyID string) ([]l7policies.Rule, error) { listOpts := l7policies.ListRulesOpts{} - allPages, err := l7policies.ListRules(client, policyID, listOpts).AllPages() + allPages, err := l7policies.ListRules(client, policyID, listOpts).AllPages(context.TODO()) if err != nil { return nil, err } @@ -669,7 +670,7 @@ func GetL7Rules(client *gophercloud.ServiceClient, policyID string) ([]l7policie // CreateL7Rule creates a l7 rule. func CreateL7Rule(client *gophercloud.ServiceClient, policyID string, opts l7policies.CreateRuleOpts, lbID string) error { mc := metrics.NewMetricContext("loadbalancer_l7rule", "create") - _, err := l7policies.CreateRule(client, policyID, opts).Extract() + _, err := l7policies.CreateRule(context.TODO(), client, policyID, opts).Extract() if mc.ObserveRequest(err) != nil { return err } @@ -684,7 +685,7 @@ func CreateL7Rule(client *gophercloud.ServiceClient, policyID string, opts l7pol // UpdateHealthMonitor updates a health monitor. func UpdateHealthMonitor(client *gophercloud.ServiceClient, monitorID string, opts monitors.UpdateOpts, lbID string) error { mc := metrics.NewMetricContext("loadbalancer_healthmonitor", "update") - _, err := monitors.Update(client, monitorID, opts).Extract() + _, err := monitors.Update(context.TODO(), client, monitorID, opts).Extract() if mc.ObserveRequest(err) != nil { return fmt.Errorf("failed to update healthmonitor: %v", err) } @@ -699,7 +700,7 @@ func UpdateHealthMonitor(client *gophercloud.ServiceClient, monitorID string, op // DeleteHealthMonitor deletes a health monitor. func DeleteHealthMonitor(client *gophercloud.ServiceClient, monitorID string, lbID string) error { mc := metrics.NewMetricContext("loadbalancer_healthmonitor", "delete") - err := monitors.Delete(client, monitorID).ExtractErr() + err := monitors.Delete(context.TODO(), client, monitorID).ExtractErr() if err != nil && !cpoerrors.IsNotFound(err) { return mc.ObserveRequest(err) } @@ -714,7 +715,7 @@ func DeleteHealthMonitor(client *gophercloud.ServiceClient, monitorID string, lb // CreateHealthMonitor creates a health monitor in a pool. func CreateHealthMonitor(client *gophercloud.ServiceClient, opts monitors.CreateOpts, lbID string) (*monitors.Monitor, error) { mc := metrics.NewMetricContext("loadbalancer_healthmonitor", "create") - monitor, err := monitors.Create(client, opts).Extract() + monitor, err := monitors.Create(context.TODO(), client, opts).Extract() if mc.ObserveRequest(err) != nil { return nil, fmt.Errorf("failed to create healthmonitor: %v", err) } @@ -729,7 +730,7 @@ func CreateHealthMonitor(client *gophercloud.ServiceClient, opts monitors.Create // GetHealthMonitor gets details about loadbalancer health monitor. func GetHealthMonitor(client *gophercloud.ServiceClient, monitorID string) (*monitors.Monitor, error) { mc := metrics.NewMetricContext("loadbalancer_healthmonitor", "get") - monitor, err := monitors.Get(client, monitorID).Extract() + monitor, err := monitors.Get(context.TODO(), client, monitorID).Extract() if mc.ObserveRequest(err) != nil { return nil, fmt.Errorf("failed to get healthmonitor: %v", err) } diff --git a/pkg/util/openstack/loadbalancer_serial.go b/pkg/util/openstack/loadbalancer_serial.go index a49f2a73e8..4538e48ae2 100644 --- a/pkg/util/openstack/loadbalancer_serial.go +++ b/pkg/util/openstack/loadbalancer_serial.go @@ -1,10 +1,11 @@ package openstack import ( + "context" "fmt" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/pools" apiv1 "k8s.io/api/core/v1" klog "k8s.io/klog/v2" @@ -68,7 +69,7 @@ func SeriallyReconcilePoolMembers(client *gophercloud.ServiceClient, pool *pools } if !memberExists(members, addr, nodePort) { klog.V(2).Infof("Creating member for pool %s", pool.ID) - _, err := pools.CreateMember(client, pool.ID, pools.CreateMemberOpts{ + _, err := pools.CreateMember(context.TODO(), client, pool.ID, pools.CreateMemberOpts{ Name: cpoutil.CutString255(fmt.Sprintf("member_%s_%s_%d", node.Name, addr, nodePort)), ProtocolPort: nodePort, Address: addr, @@ -87,7 +88,7 @@ func SeriallyReconcilePoolMembers(client *gophercloud.ServiceClient, pool *pools } for _, member := range members { klog.V(2).Infof("Deleting obsolete member %s for pool %s address %s", member.ID, pool.ID, member.Address) - err := pools.DeleteMember(client, pool.ID, member.ID).ExtractErr() + err := pools.DeleteMember(context.TODO(), client, pool.ID, member.ID).ExtractErr() if err != nil && !cpoerrors.IsNotFound(err) { return fmt.Errorf("error deleting obsolete member %s for pool %s address %s: %v", member.ID, pool.ID, member.Address, err) } diff --git a/pkg/util/openstack/network.go b/pkg/util/openstack/network.go index 889086f480..d353dbb852 100644 --- a/pkg/util/openstack/network.go +++ b/pkg/util/openstack/network.go @@ -17,14 +17,16 @@ limitations under the License. package openstack import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" - neutronports "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" - "github.com/gophercloud/gophercloud/pagination" + "context" + + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/external" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/floatingips" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/networks" + neutronports "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets" + "github.com/gophercloud/gophercloud/v2/pagination" "k8s.io/cloud-provider-openstack/pkg/metrics" cpoerrors "k8s.io/cloud-provider-openstack/pkg/util/errors" @@ -36,7 +38,7 @@ func GetNetworkExtensions(client *gophercloud.ServiceClient) (map[string]bool, e mc := metrics.NewMetricContext("network_extension", "list") pager := extensions.List(client) - err := pager.EachPage(func(page pagination.Page) (bool, error) { + err := pager.EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { exts, err := extensions.ExtractExtensions(page) if err != nil { return false, err @@ -55,7 +57,7 @@ func GetFloatingIPs(client *gophercloud.ServiceClient, opts floatingips.ListOpts var floatingIPList []floatingips.FloatingIP mc := metrics.NewMetricContext("floating_ip", "list") - allPages, err := floatingips.List(client, opts).AllPages() + allPages, err := floatingips.List(client, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return floatingIPList, err } @@ -93,7 +95,7 @@ func GetFloatingNetworkID(client *gophercloud.ServiceClient) (string, error) { var allNetworks []NetworkWithExternalExt mc := metrics.NewMetricContext("network", "list") - page, err := networks.List(client, networks.ListOpts{}).AllPages() + page, err := networks.List(client, networks.ListOpts{}).AllPages(context.TODO()) if err != nil { return "", mc.ObserveRequest(err) } @@ -106,7 +108,7 @@ func GetFloatingNetworkID(client *gophercloud.ServiceClient) (string, error) { for _, network := range allNetworks { if network.External && len(network.Subnets) > 0 { mc := metrics.NewMetricContext("subnet", "list") - page, err := subnets.List(client, subnets.ListOpts{NetworkID: network.ID}).AllPages() + page, err := subnets.List(client, subnets.ListOpts{NetworkID: network.ID}).AllPages(context.TODO()) if err != nil { return "", mc.ObserveRequest(err) } @@ -142,7 +144,7 @@ func getSubnet(networkSubnet string, subnetList []subnets.Subnet) *subnets.Subne // GetPorts gets all the filtered ports. func GetPorts[PortType interface{}](client *gophercloud.ServiceClient, listOpts neutronports.ListOpts) ([]PortType, error) { mc := metrics.NewMetricContext("port", "list") - allPages, err := neutronports.List(client, listOpts).AllPages() + allPages, err := neutronports.List(client, listOpts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return []PortType{}, err } diff --git a/pkg/util/openstack/security_group.go b/pkg/util/openstack/security_group.go index 0e31eb9edd..476d3d1b85 100644 --- a/pkg/util/openstack/security_group.go +++ b/pkg/util/openstack/security_group.go @@ -17,14 +17,16 @@ limitations under the License. package openstack import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" + "context" + + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/rules" "k8s.io/cloud-provider-openstack/pkg/metrics" ) func GetSecurityGroupRules(client *gophercloud.ServiceClient, opts rules.ListOpts) ([]rules.SecGroupRule, error) { mc := metrics.NewMetricContext("security_group_rule", "list") - page, err := rules.List(client, opts).AllPages() + page, err := rules.List(client, opts).AllPages(context.TODO()) if mc.ObserveRequest(err) != nil { return nil, err } diff --git a/tests/sanity/cinder/fakecloud.go b/tests/sanity/cinder/fakecloud.go index cff3a1bc60..53c0dcba4f 100644 --- a/tests/sanity/cinder/fakecloud.go +++ b/tests/sanity/cinder/fakecloud.go @@ -6,11 +6,11 @@ import ( "strconv" "time" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/backups" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers" "k8s.io/cloud-provider-openstack/pkg/csi/cinder" "k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack" "k8s.io/cloud-provider-openstack/pkg/util/metadata" @@ -145,11 +145,11 @@ func (cloud *cloud) GetVolume(volumeID string) (*volumes.Volume, error) { } func notFoundError() error { - return gophercloud.ErrDefault404{} + return gophercloud.ErrUnexpectedResponseCode{Actual: 404} } func invalidError() error { - return gophercloud.ErrDefault400{} + return gophercloud.ErrUnexpectedResponseCode{Actual: 400} } func (cloud *cloud) CreateSnapshot(name, volID string, tags map[string]string) (*snapshots.Snapshot, error) { @@ -318,7 +318,7 @@ func (cloud *cloud) GetInstanceByID(instanceID string) (*servers.Server, error) inst, ok := cloud.instances[instanceID] if !ok { - return nil, gophercloud.ErrDefault404{} + return nil, gophercloud.ErrUnexpectedResponseCode{Actual: 404} } return inst, nil diff --git a/tests/sanity/manila/fakemanilaclient.go b/tests/sanity/manila/fakemanilaclient.go index da783652e7..b9f69599fe 100644 --- a/tests/sanity/manila/fakemanilaclient.go +++ b/tests/sanity/manila/fakemanilaclient.go @@ -20,11 +20,11 @@ import ( "fmt" "strconv" - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/messages" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes" - "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots" + "github.com/gophercloud/gophercloud/v2" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/messages" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/shares" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/sharetypes" + "github.com/gophercloud/gophercloud/v2/openstack/sharedfilesystems/v2/snapshots" "k8s.io/cloud-provider-openstack/pkg/client" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" ) @@ -217,7 +217,7 @@ func (c fakeManilaClient) GrantAccess(shareID string, opts shares.GrantAccessOpt func (c fakeManilaClient) GetSnapshotByID(snapID string) (*snapshots.Snapshot, error) { s, ok := fakeSnapshots[strToInt(snapID)] if !ok { - return nil, gophercloud.ErrDefault404{} + return nil, gophercloud.ErrUnexpectedResponseCode{Actual: 404} } return s, nil @@ -233,7 +233,7 @@ func (c fakeManilaClient) GetSnapshotByName(snapName string) (*snapshots.Snapsho } if snapID == "" { - return nil, gophercloud.ErrResourceNotFound{} + return nil, gophercloud.ErrResourceNotFound{Name: snapName, ResourceType: "snapshot"} } return c.GetSnapshotByID(snapID) @@ -252,7 +252,7 @@ func (c fakeManilaClient) CreateSnapshot(opts snapshots.CreateOptsBuilder) (*sna snap.Status = "available" if !shareExists(snap.ShareID) { - return nil, gophercloud.ErrDefault404{} + return nil, gophercloud.ErrUnexpectedResponseCode{Actual: 404} } fakeSnapshots[fakeSnapshotID] = snap