Skip to content

Commit

Permalink
Update gophercloud/gophercloud to v2
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Hros <roman.hros@dnation.cloud>
  • Loading branch information
chess-knight committed Mar 28, 2024
1 parent 870c281 commit f50df5c
Show file tree
Hide file tree
Showing 47 changed files with 87 additions and 3,644 deletions.
2 changes: 1 addition & 1 deletion .builder-image-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1
2 changes: 1 addition & 1 deletion api/v1alpha1/openstacknodeimagerelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha1

import (
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/images"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiv1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.1
require (
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.5
github.com/google/go-github/v52 v52.0.0
github.com/gophercloud/gophercloud v1.11.0
github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2
github.com/gophercloud/utils/v2 v2.0.0-20240305212012-b57aefba4cdb
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
Expand Down Expand Up @@ -49,7 +49,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2 // indirect
github.com/gophercloud/gophercloud v1.11.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

githubmocks "github.com/SovereignCloudStack/cluster-stack-operator/pkg/github/client/mocks"
"github.com/google/go-github/v52/github"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/images"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
Expand Down
30 changes: 15 additions & 15 deletions internal/controller/openstacknodeimagerelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"fmt"
"time"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/imageimport"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/openstack"
"github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/imageimport"
"github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/images"
"github.com/gophercloud/utils/v2/openstack/clientconfig"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -124,7 +124,7 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req

// Create an OpenStack provider client
opts := &clientconfig.ClientOpts{AuthInfo: cloud.AuthInfo}
providerClient, err := clientconfig.AuthenticatedClient(opts)
providerClient, err := clientconfig.AuthenticatedClient(ctx, opts)
if err != nil {
record.Warnf(openstacknodeimagerelease, "OpenStackProviderClientNotSet", err.Error())
logger.Error(err, "failed to create a provider client")
Expand All @@ -147,7 +147,7 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req

conditions.MarkTrue(openstacknodeimagerelease, apiv1alpha1.OpenStackImageServiceClientAvailableCondition)

imageID, err := getImageID(imageClient, openstacknodeimagerelease.Spec.Image.CreateOpts)
imageID, err := getImageID(ctx, imageClient, openstacknodeimagerelease.Spec.Image.CreateOpts)
if err != nil {
conditions.MarkFalse(openstacknodeimagerelease,
apiv1alpha1.OpenStackImageReadyCondition,
Expand All @@ -167,7 +167,7 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req
openstacknodeimagerelease.Status.Ready = false

imageCreateOpts := openstacknodeimagerelease.Spec.Image.CreateOpts
imageCreated, err := createImage(imageClient, imageCreateOpts)
imageCreated, err := createImage(ctx, imageClient, imageCreateOpts)
if err != nil {
conditions.MarkFalse(openstacknodeimagerelease,
apiv1alpha1.OpenStackImageReadyCondition,
Expand All @@ -185,7 +185,7 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req
Name: imageimport.WebDownloadMethod,
URI: openstacknodeimagerelease.Spec.Image.URL,
}
err = importImage(imageClient, imageCreated.ID, imageImportOpts)
err = importImage(ctx, imageClient, imageCreated.ID, imageImportOpts)
if err != nil {
conditions.MarkFalse(openstacknodeimagerelease,
apiv1alpha1.OpenStackImageReadyCondition,
Expand All @@ -206,7 +206,7 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req
}

// Check if image is active
image, err := images.Get(imageClient, imageID).Extract()
image, err := images.Get(ctx, imageClient, imageID).Extract()
if err != nil {
conditions.MarkFalse(openstacknodeimagerelease,
apiv1alpha1.OpenStackImageReadyCondition,
Expand Down Expand Up @@ -331,7 +331,7 @@ func (r *OpenStackNodeImageReleaseReconciler) getCloudFromSecret(ctx context.Con
return cloud, nil
}

func getImageID(imagesClient *gophercloud.ServiceClient, imageCreateOps *apiv1alpha1.CreateOpts) (string, error) {
func getImageID(ctx context.Context, imagesClient *gophercloud.ServiceClient, imageCreateOps *apiv1alpha1.CreateOpts) (string, error) {
var listOpts images.ListOpts

if imageCreateOps.ID != "" {
Expand All @@ -345,7 +345,7 @@ func getImageID(imagesClient *gophercloud.ServiceClient, imageCreateOps *apiv1al
}
}

allPages, err := images.List(imagesClient, listOpts).AllPages()
allPages, err := images.List(imagesClient, listOpts).AllPages(ctx)
if err != nil {
return "", fmt.Errorf("failed to list images with name %s: %w", imageCreateOps.Name, err)
}
Expand All @@ -365,17 +365,17 @@ func getImageID(imagesClient *gophercloud.ServiceClient, imageCreateOps *apiv1al
}
}

func createImage(imageClient *gophercloud.ServiceClient, createOpts *apiv1alpha1.CreateOpts) (*images.Image, error) {
image, err := images.Create(imageClient, (*images.CreateOpts)(createOpts)).Extract()
func createImage(ctx context.Context, imageClient *gophercloud.ServiceClient, createOpts *apiv1alpha1.CreateOpts) (*images.Image, error) {
image, err := images.Create(ctx, imageClient, (*images.CreateOpts)(createOpts)).Extract()
if err != nil {
return nil, fmt.Errorf("failed to create image with name %s: %w", createOpts.Name, err)
}

return image, nil
}

func importImage(imageClient *gophercloud.ServiceClient, imageID string, createOpts imageimport.CreateOpts) error {
err := imageimport.Create(imageClient, imageID, createOpts).ExtractErr()
func importImage(ctx context.Context, imageClient *gophercloud.ServiceClient, imageID string, createOpts imageimport.CreateOpts) error {
err := imageimport.Create(ctx, imageClient, imageID, createOpts).ExtractErr()
if err != nil {
return fmt.Errorf("failed to import image with ID %s: %w", imageID, err)
}
Expand Down
28 changes: 14 additions & 14 deletions internal/controller/openstacknodeimagerelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"net/http"
"testing"

"github.com/gophercloud/gophercloud/openstack/imageservice/v2/imageimport"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
th "github.com/gophercloud/gophercloud/testhelper"
fakeclient "github.com/gophercloud/gophercloud/testhelper/client"
"github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/imageimport"
"github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/images"
th "github.com/gophercloud/gophercloud/v2/testhelper"
fakeclient "github.com/gophercloud/gophercloud/v2/testhelper/client"
"github.com/gophercloud/utils/v2/openstack/clientconfig"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestGetImageID(t *testing.T) {
ID: "123",
}

imageID, err := getImageID(fakeclient.ServiceClient(), imageFilter)
imageID, err := getImageID(context.TODO(), fakeclient.ServiceClient(), imageFilter)

assert.NoError(t, err)
assert.Equal(t, "123", imageID)
Expand All @@ -215,7 +215,7 @@ func TestGetImageIDByNameAndTags(t *testing.T) {
Tags: []string{"v1"},
}

imageID, err := getImageID(fakeclient.ServiceClient(), imageFilter)
imageID, err := getImageID(context.TODO(), fakeclient.ServiceClient(), imageFilter)

assert.NoError(t, err)
assert.Equal(t, "123", imageID)
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestGetImageIDWithTwoSameImageNames(t *testing.T) {
Tags: []string{"v1"},
}

imageID, err := getImageID(fakeclient.ServiceClient(), imageFilter)
imageID, err := getImageID(context.TODO(), fakeclient.ServiceClient(), imageFilter)

assert.Error(t, err) // Expecting an error due to multiple images with the same name
assert.Equal(t, "", imageID)
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestGetImageIDNoImageFound(t *testing.T) {
Tags: []string{"v1"},
}

imageID, err := getImageID(fakeclient.ServiceClient(), imageFilter)
imageID, err := getImageID(context.TODO(), fakeclient.ServiceClient(), imageFilter)

assert.NoError(t, err)
assert.Equal(t, "", imageID)
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestGetImageIDWrongImageName(t *testing.T) {
Name: "test_bad_image",
}

imageID, err := getImageID(fakeclient.ServiceClient(), imageFilter)
imageID, err := getImageID(context.TODO(), fakeclient.ServiceClient(), imageFilter)

assert.NoError(t, err)
assert.NotEqual(t, "231", imageID)
Expand All @@ -342,7 +342,7 @@ func TestGetImageIDNotFound(t *testing.T) {

fakeClient := fakeclient.ServiceClient()

imageID, err := getImageID(fakeClient, imageFilter)
imageID, err := getImageID(context.TODO(), fakeClient, imageFilter)

assert.Error(t, err)
assert.Equal(t, "", imageID)
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestCreateImage(t *testing.T) {

fakeClient := fakeclient.ServiceClient()

createdImage, err := createImage(fakeClient, createOpts)
createdImage, err := createImage(context.TODO(), fakeClient, createOpts)

expectedImage := images.Image{
ID: "test_id",
Expand Down Expand Up @@ -447,7 +447,7 @@ func TestCreateImageFailed(t *testing.T) {

fakeClient := fakeclient.ServiceClient()

createdImage, err := createImage(fakeClient, createOpts)
createdImage, err := createImage(context.TODO(), fakeClient, createOpts)

assert.Error(t, err)
assert.Nil(t, createdImage)
Expand Down Expand Up @@ -482,7 +482,7 @@ func TestImportImage(t *testing.T) {

fakeClient := fakeclient.ServiceClient()

err := importImage(fakeClient, imageID, createOpts)
err := importImage(context.TODO(), fakeClient, imageID, createOpts)

assert.NoError(t, err)
}
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestImportImageError(t *testing.T) {

fakeClient := fakeclient.ServiceClient()

err := importImage(fakeClient, imageID, createOpts)
err := importImage(context.TODO(), fakeClient, imageID, createOpts)

assert.Error(t, err)
assert.EqualError(t, err, fmt.Sprintf("failed to import image with ID %s: Internal Server Error", imageID))
Expand Down
137 changes: 0 additions & 137 deletions vendor/github.com/gophercloud/gophercloud/openstack/auth_env.go

This file was deleted.

Loading

0 comments on commit f50df5c

Please sign in to comment.