Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

🌱 Upgrade Gophercloud to v2 #2107

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"fmt"
"time"

"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
kerrors "k8s.io/apimachinery/pkg/util/errors"
Expand Down
41 changes: 21 additions & 20 deletions controllers/openstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/floatingips"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets"
. "github.com/onsi/ginkgo/v2" //nolint:revive
. "github.com/onsi/gomega" //nolint:revive
"go.uber.org/mock/gomock"
Expand All @@ -43,7 +43,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/clients"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/scope"
)

Expand Down Expand Up @@ -272,17 +271,18 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
scope := scope.NewWithLogger(clientScope, log)

server := clients.ServerExt{}
server.ID = "adopted-bastion-uuid"
server.Status = "ACTIVE"
server := servers.Server{
ID: "adopted-bastion-uuid",
Status: "ACTIVE",
}

networkClientRecorder := mockScopeFactory.NetworkClient.EXPECT()
networkClientRecorder.ListPort(gomock.Any()).Return([]ports.Port{{ID: "portID1"}}, nil)

computeClientRecorder := mockScopeFactory.ComputeClient.EXPECT()
computeClientRecorder.ListServers(servers.ListOpts{
Name: "^capi-cluster-bastion$",
}).Return([]clients.ServerExt{server}, nil)
}).Return([]servers.Server{server}, nil)

networkClientRecorder.ListFloatingIP(floatingips.ListOpts{PortID: "portID1"}).Return(make([]floatingips.FloatingIP, 1), nil)

Expand Down Expand Up @@ -356,9 +356,10 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
scope := scope.NewWithLogger(clientScope, log)

server := clients.ServerExt{}
server.ID = "adopted-fip-bastion-uuid"
server.Status = "ACTIVE"
server := servers.Server{
ID: "adopted-fip-bastion-uuid",
Status: "ACTIVE",
}

networkClientRecorder := mockScopeFactory.NetworkClient.EXPECT()
networkClientRecorder.ListPort(gomock.Any()).Return([]ports.Port{{ID: "portID1"}}, nil)
Expand Down Expand Up @@ -438,9 +439,10 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
scope := scope.NewWithLogger(clientScope, log)

server := clients.ServerExt{}
server.ID = "requeue-bastion-uuid"
server.Status = "BUILD"
server := servers.Server{
ID: "requeue-bastion-uuid",
Status: "BUILD",
}

computeClientRecorder := mockScopeFactory.ComputeClient.EXPECT()
computeClientRecorder.GetServer("requeue-bastion-uuid").Return(&server, nil)
Expand Down Expand Up @@ -495,13 +497,12 @@ var _ = Describe("OpenStackCluster controller", func() {
Expect(err).To(BeNil())
scope := scope.NewWithLogger(clientScope, log)

server := clients.ServerExt{}
server.ID = "delete-bastion-uuid"
server := servers.Server{ID: "delete-bastion-uuid"}

computeClientRecorder := mockScopeFactory.ComputeClient.EXPECT()
computeClientRecorder.ListServers(servers.ListOpts{
Name: "^capi-cluster-bastion$",
}).Return([]clients.ServerExt{server}, nil)
}).Return([]servers.Server{server}, nil)
computeClientRecorder.DeleteServer("delete-bastion-uuid").Return(nil)
computeClientRecorder.GetServer("delete-bastion-uuid").Return(nil, gophercloud.ErrResourceNotFound{})

Expand Down
35 changes: 16 additions & 19 deletions controllers/openstackmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ import (

"github.com/go-logr/logr/testr"
"github.com/google/go-cmp/cmp"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/v2/openstack/image/v2/images"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/trunks"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports"
. "github.com/onsi/gomega" //nolint:revive
"go.uber.org/mock/gomock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/clients"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/clients/mock"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/compute"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/scope"
Expand Down Expand Up @@ -271,34 +270,32 @@ func Test_reconcileDelete(t *testing.T) {
}

deleteServerByID := func(r *recorders) {
r.compute.GetServer(instanceUUID).Return(&clients.ServerExt{
Server: servers.Server{
ID: instanceUUID,
Name: openStackMachineName,
},
r.compute.GetServer(instanceUUID).Return(&servers.Server{
ID: instanceUUID,
Name: openStackMachineName,
}, nil)
r.compute.DeleteServer(instanceUUID).Return(nil)
r.compute.GetServer(instanceUUID).Return(nil, gophercloud.ErrDefault404{})
r.compute.GetServer(instanceUUID).Return(nil, gophercloud.ErrUnexpectedResponseCode{Actual: 404})
}
deleteServerByName := func(r *recorders) {
r.compute.ListServers(servers.ListOpts{
Name: "^" + openStackMachineName + "$",
}).Return([]clients.ServerExt{
{Server: servers.Server{
}).Return([]servers.Server{
{
ID: instanceUUID,
Name: openStackMachineName,
}},
},
}, nil)
r.compute.DeleteServer(instanceUUID).Return(nil)
r.compute.GetServer(instanceUUID).Return(nil, gophercloud.ErrDefault404{})
r.compute.GetServer(instanceUUID).Return(nil, gophercloud.ErrUnexpectedResponseCode{Actual: 404})
}

deleteMissingServerByName := func(r *recorders) {
// Lookup server by name because it is not in status.
// Don't find it.
r.compute.ListServers(servers.ListOpts{
Name: "^" + openStackMachineName + "$",
}).Return([]clients.ServerExt{}, nil)
}).Return([]servers.Server{}, nil)
}

deleteRootVolume := func(r *recorders) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"testing"

"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
. "github.com/onsi/ginkgo/v2" //nolint:revive
. "github.com/onsi/gomega" //nolint:revive
"go.uber.org/mock/gomock"
Expand All @@ -38,7 +39,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"

infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/clients"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/compute"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/scope"
"sigs.k8s.io/cluster-api-provider-openstack/test/helpers/external"
Expand Down Expand Up @@ -172,7 +172,7 @@ var _ = Describe("When calling getOrCreate", func() {
openStackCluster := &infrav1.OpenStackCluster{}
machine := &clusterv1.Machine{}
openStackMachine := &infrav1.OpenStackMachine{}
servers := make([]clients.ServerExt, 1)
servers := make([]servers.Server, 1)
servers[0].ID = "machine-uuid"

mockScopeFactory.ComputeClient.EXPECT().ListServers(gomock.Any()).Return(servers, nil)
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/gofuzz v1.2.0
github.com/google/uuid v1.4.0
github.com/gophercloud/gophercloud v1.11.0
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56
github.com/gophercloud/gophercloud/v2 v2.0.0
github.com/gophercloud/utils/v2 v2.0.0-20240701101423-2401526caee5
github.com/hashicorp/go-version v1.4.0
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/prometheus/client_golang v1.18.0
github.com/spf13/pflag v1.0.5
go.uber.org/mock v0.4.0
golang.org/x/crypto v0.21.0
golang.org/x/text v0.14.0
golang.org/x/crypto v0.24.0
golang.org/x/text v0.16.0
gopkg.in/ini.v1 v1.67.0
k8s.io/api v0.29.3
k8s.io/apiextensions-apiserver v0.29.3
Expand Down Expand Up @@ -69,6 +69,7 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gobuffalo/flect v1.0.2 // 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
Expand All @@ -79,7 +80,6 @@ require (
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
Expand Down Expand Up @@ -127,14 +127,14 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
Expand Down
Loading