Skip to content

Commit

Permalink
fix!: replace deprecated cluster with region
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Urbanek <[email protected]>
  • Loading branch information
shanduur committed Jul 23, 2024
1 parent 559b408 commit bbbb8f8
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion examples/example.BucketClass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ metadata:
driverName: objectstorage.cosi.linode.com
deletionPolicy: Delete
parameters:
cosi.linode.com/v1/region: us-east-1
cosi.linode.com/v1/region: us-east
cosi.linode.com/v1/acl: private
cosi.linode.com/v1/cors: disabled
20 changes: 10 additions & 10 deletions pkg/linodeclient/stubclient/stubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *Client) CreateObjectStorageBucket(ctx context.Context, opt linodego.Obj
return nil, err
}

key := fmt.Sprintf("%s/%s", opt.Cluster, opt.Label)
key := fmt.Sprintf("%s/%s", opt.Region, opt.Label)

bucket, ok := c.objectStorageBuckets[key]
if ok {
Expand All @@ -106,7 +106,7 @@ func (c *Client) CreateObjectStorageBucket(ctx context.Context, opt linodego.Obj

bucket = &linodego.ObjectStorageBucket{
Label: opt.Label,
Cluster: opt.Cluster,
Region: opt.Region,
Hostname: fmt.Sprintf("%s.linodeobjects.com", opt.Label),
}
c.objectStorageBuckets[key] = bucket
Expand All @@ -126,12 +126,12 @@ func (c *Client) CreateObjectStorageBucket(ctx context.Context, opt linodego.Obj
}

// GetObjectStorageBucket is a stub function that stubs the behavior of GetObjectStorageBucket call from linodego.Client.
func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterID, label string) (*linodego.ObjectStorageBucket, error) {
func (c *Client) GetObjectStorageBucket(ctx context.Context, region, label string) (*linodego.ObjectStorageBucket, error) {
if err := handleForcedFailure(ctx); err != nil {
return nil, err
}

key := fmt.Sprintf("%s/%s", clusterID, label)
key := fmt.Sprintf("%s/%s", region, label)

obj, ok := c.objectStorageBuckets[key]
if ok {
Expand All @@ -144,12 +144,12 @@ func (c *Client) GetObjectStorageBucket(ctx context.Context, clusterID, label st
}

// DeleteObjectStorageBucket is a stub function that stubs the behavior of DeleteObjectStorageBucket call from linodego.Client.
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterID, label string) error {
func (c *Client) DeleteObjectStorageBucket(ctx context.Context, region, label string) error {
if err := handleForcedFailure(ctx); err != nil {
return err
}

key := fmt.Sprintf("%s/%s", clusterID, label)
key := fmt.Sprintf("%s/%s", region, label)

bucket, ok := c.objectStorageBuckets[key]

Expand All @@ -169,12 +169,12 @@ func (c *Client) DeleteObjectStorageBucket(ctx context.Context, clusterID, label
}

// GetObjectStorageBucketAccess is a stub function that stubs the behavior of GetObjectStorageBucketAccess call from linodego.Client.
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterID, label string) (*linodego.ObjectStorageBucketAccess, error) {
func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, region, label string) (*linodego.ObjectStorageBucketAccess, error) {
if err := handleForcedFailure(ctx); err != nil {
return nil, err
}

key := fmt.Sprintf("%s/%s", clusterID, label)
key := fmt.Sprintf("%s/%s", region, label)

obj, ok := c.objectStorageBucketAccesses[key]
if ok {
Expand All @@ -187,12 +187,12 @@ func (c *Client) GetObjectStorageBucketAccess(ctx context.Context, clusterID, la
}

// UpdateObjectStorageBucketAccess is a stub function that stubs the behavior of UpdateObjectStorageBucketAccess call from linodego.Client.
func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, clusterID, label string, opt linodego.ObjectStorageBucketUpdateAccessOptions) error {
func (c *Client) UpdateObjectStorageBucketAccess(ctx context.Context, region, label string, opt linodego.ObjectStorageBucketUpdateAccessOptions) error {
if err := handleForcedFailure(ctx); err != nil {
return err
}

key := fmt.Sprintf("%s/%s", clusterID, label)
key := fmt.Sprintf("%s/%s", region, label)

access, ok := c.objectStorageBucketAccesses[key]
if !ok {
Expand Down
82 changes: 41 additions & 41 deletions pkg/linodeclient/stubclient/stubclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
var (
testBucket = &linodego.ObjectStorageBucket{
Label: "test-label",
Cluster: "test-cluster",
Region: "test-region",
Hostname: "test-label.linodeobjects.com",
Objects: 0,
Size: 0,
Expand All @@ -43,7 +43,7 @@ var (

testKeyBucketAccessList = []linodego.ObjectStorageKeyBucketAccess{
{
Cluster: "test-cluster",
Region: "test-region",
BucketName: "test-label",
Permissions: "test-permissions",
},
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestNew(t *testing.T) {
{
testName: "bucket accesses input",
input: []stubclient.Option{
stubclient.WithBucketAccess(testBucketAccess, testBucket.Cluster, testBucket.Label),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Region, testBucket.Label),
},
},
{
Expand All @@ -98,7 +98,7 @@ func TestNew(t *testing.T) {
testName: "mixed input",
input: []stubclient.Option{
stubclient.WithBucket(testBucket),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Cluster, testBucket.Label),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Region, testBucket.Label),
stubclient.WithKey(testKey),
},
},
Expand Down Expand Up @@ -131,9 +131,9 @@ func TestCreateObjectStorageBucket(t *testing.T) {
testName: "valid input",
client: stubclient.New(),
opts: linodego.ObjectStorageBucketCreateOptions{
Cluster: testBucket.Cluster,
Label: testBucket.Label,
ACL: linodego.ACLPrivate,
Region: testBucket.Region,
Label: testBucket.Label,
ACL: linodego.ACLPrivate,
},
expectedError: nil,
expectedValue: testBucket,
Expand All @@ -142,9 +142,9 @@ func TestCreateObjectStorageBucket(t *testing.T) {
testName: "duplicated",
client: stubclient.New(stubclient.WithBucket(testBucket)),
opts: linodego.ObjectStorageBucketCreateOptions{
Cluster: testBucket.Cluster,
Label: testBucket.Label,
ACL: linodego.ACLPrivate,
Region: testBucket.Region,
Label: testBucket.Label,
ACL: linodego.ACLPrivate,
},
expectedError: nil,
expectedValue: testBucket,
Expand All @@ -153,7 +153,7 @@ func TestCreateObjectStorageBucket(t *testing.T) {
testName: "with CORS",
client: stubclient.New(),
opts: linodego.ObjectStorageBucketCreateOptions{
Cluster: testBucket.Cluster,
Region: testBucket.Region,
Label: testBucket.Label,
ACL: linodego.ACLPrivate,
CorsEnabled: &testBool,
Expand All @@ -165,9 +165,9 @@ func TestCreateObjectStorageBucket(t *testing.T) {
testName: "invalid ACL",
client: stubclient.New(),
opts: linodego.ObjectStorageBucketCreateOptions{
Cluster: testBucket.Cluster,
Label: testBucket.Label,
ACL: "invalid-acl",
Region: testBucket.Region,
Label: testBucket.Label,
ACL: "invalid-acl",
},
expectedError: &linodego.Error{Code: http.StatusBadRequest},
expectedValue: nil,
Expand Down Expand Up @@ -226,23 +226,23 @@ func TestGetObjectStorageBucket(t *testing.T) {
testName string
ctx context.Context //nolint:containedctx
client linodeclient.Client
clusterID string
region string
label string
expectedValue *linodego.ObjectStorageBucket
expectedError error
}{
{
testName: "valid input",
client: stubclient.New(stubclient.WithBucket(testBucket)),
clusterID: testBucket.Cluster,
region: testBucket.Region,
label: testBucket.Label,
expectedValue: testBucket,
expectedError: nil,
},
{
testName: "non existent bucket",
client: stubclient.New(),
clusterID: "non-existent-cluster",
region: "non-existent-region",
label: "non-existent-label",
expectedValue: nil,
expectedError: &linodego.Error{Code: http.StatusNotFound},
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestGetObjectStorageBucket(t *testing.T) {
ctx, cancel := testutils.ContextFromT(tc.ctx, t)
defer cancel()

actual, err := tc.client.GetObjectStorageBucket(ctx, tc.clusterID, tc.label)
actual, err := tc.client.GetObjectStorageBucket(ctx, tc.region, tc.label)
if !errors.Is(err, tc.expectedError) {
t.Errorf("expected error: %v, but got: %v", tc.expectedError, err)
}
Expand All @@ -301,34 +301,34 @@ func TestDeleteObjectStorageBucket(t *testing.T) {
testName string
ctx context.Context //nolint:containedctx
client linodeclient.Client
clusterID string
region string
label string
expectedError error
}{
{
testName: "valid input",
client: stubclient.New(stubclient.WithBucket(testBucket)),
clusterID: testBucket.Cluster,
region: testBucket.Region,
label: testBucket.Label,
expectedError: nil,
},
{
testName: "non existent bucket",
client: stubclient.New(),
clusterID: testBucket.Cluster,
region: testBucket.Region,
label: testBucket.Label,
expectedError: &linodego.Error{Code: http.StatusNotFound},
},
{
testName: "non empty bucket",
client: stubclient.New(stubclient.WithBucket(&linodego.ObjectStorageBucket{
Cluster: testBucket.Cluster,
Region: testBucket.Region,
Label: testBucket.Label,
Hostname: testBucket.Hostname,
Objects: 10,
Size: 102310,
})),
clusterID: testBucket.Cluster,
region: testBucket.Region,
label: testBucket.Label,
expectedError: &linodego.Error{Code: http.StatusBadRequest},
},
Expand Down Expand Up @@ -365,7 +365,7 @@ func TestDeleteObjectStorageBucket(t *testing.T) {
ctx, cancel := testutils.ContextFromT(tc.ctx, t)
defer cancel()

err := tc.client.DeleteObjectStorageBucket(ctx, tc.clusterID, tc.label)
err := tc.client.DeleteObjectStorageBucket(ctx, tc.region, tc.label)
if !errors.Is(err, tc.expectedError) {
t.Errorf("expected error: %v, but got: %v", tc.expectedError, err)
}
Expand All @@ -380,25 +380,25 @@ func TestGetObjectStorageBucketAccess(t *testing.T) {
testName string
ctx context.Context //nolint:containedctx
client linodeclient.Client
clusterID string
region string
label string
expectedValue *linodego.ObjectStorageBucketAccess
expectedError error
}{
{
testName: "valid input",
client: stubclient.New(
stubclient.WithBucketAccess(testBucketAccess, testBucket.Cluster, testBucket.Label),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Region, testBucket.Label),
),
clusterID: testBucket.Cluster,
region: testBucket.Region,
label: testBucket.Label,
expectedValue: testBucketAccess,
expectedError: nil,
},
{
testName: "non existent bucket",
client: stubclient.New(),
clusterID: "non-existent-cluster",
region: "non-existent-region",
label: "non-existent-label",
expectedValue: nil,
expectedError: &linodego.Error{Code: http.StatusNotFound},
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestGetObjectStorageBucketAccess(t *testing.T) {
ctx, cancel := testutils.ContextFromT(tc.ctx, t)
defer cancel()

actual, err := tc.client.GetObjectStorageBucketAccess(ctx, tc.clusterID, tc.label)
actual, err := tc.client.GetObjectStorageBucketAccess(ctx, tc.region, tc.label)
if !errors.Is(err, tc.expectedError) {
t.Errorf("expected error: %v, but got: %v", tc.expectedError, err)
}
Expand All @@ -457,18 +457,18 @@ func TestUpdateObjectStorageBucketAccess(t *testing.T) {
testName string
ctx context.Context //nolint:containedctx
client linodeclient.Client
clusterID string
region string
label string
opts linodego.ObjectStorageBucketUpdateAccessOptions
expectedError error
}{
{
testName: "valid input",
client: stubclient.New(
stubclient.WithBucketAccess(testBucketAccess, testBucket.Cluster, testBucket.Label),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Region, testBucket.Label),
),
clusterID: testBucket.Cluster,
label: testBucket.Label,
region: testBucket.Region,
label: testBucket.Label,
opts: linodego.ObjectStorageBucketUpdateAccessOptions{
ACL: testBucketAccess.ACL,
},
Expand All @@ -477,10 +477,10 @@ func TestUpdateObjectStorageBucketAccess(t *testing.T) {
{
testName: "with CORS",
client: stubclient.New(
stubclient.WithBucketAccess(testBucketAccess, testBucket.Cluster, testBucket.Label),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Region, testBucket.Label),
),
clusterID: testBucket.Cluster,
label: testBucket.Label,
region: testBucket.Region,
label: testBucket.Label,
opts: linodego.ObjectStorageBucketUpdateAccessOptions{
ACL: testBucketAccess.ACL,
CorsEnabled: &testBool,
Expand All @@ -490,10 +490,10 @@ func TestUpdateObjectStorageBucketAccess(t *testing.T) {
{
testName: "invalid ACL",
client: stubclient.New(
stubclient.WithBucketAccess(testBucketAccess, testBucket.Cluster, testBucket.Label),
stubclient.WithBucketAccess(testBucketAccess, testBucket.Region, testBucket.Label),
),
clusterID: testBucket.Cluster,
label: testBucket.Label,
region: testBucket.Region,
label: testBucket.Label,
opts: linodego.ObjectStorageBucketUpdateAccessOptions{
ACL: "invalid-acl",
},
Expand All @@ -502,7 +502,7 @@ func TestUpdateObjectStorageBucketAccess(t *testing.T) {
{
testName: "non existent input",
client: stubclient.New(),
clusterID: "non-existent-cluster",
region: "non-existent-region",
label: "non-existent-label",
opts: linodego.ObjectStorageBucketUpdateAccessOptions{},
expectedError: linodego.Error{Code: http.StatusNotFound},
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestUpdateObjectStorageBucketAccess(t *testing.T) {
ctx, cancel := testutils.ContextFromT(tc.ctx, t)
defer cancel()

err := tc.client.UpdateObjectStorageBucketAccess(ctx, tc.clusterID, tc.label, tc.opts)
err := tc.client.UpdateObjectStorageBucketAccess(ctx, tc.region, tc.label, tc.opts)
if !errors.Is(err, tc.expectedError) {
t.Errorf("expected error: %v, but got: %v", tc.expectedError, err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/linodeclient/stubclient/stubclientoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Option func(c *Client)
// WithBucket is an option to configure the stub client with an Object Storage bucket.
func WithBucket(bucket *linodego.ObjectStorageBucket) Option {
return func(c *Client) {
id := fmt.Sprintf("%s/%s", bucket.Cluster, bucket.Label)
id := fmt.Sprintf("%s/%s", bucket.Region, bucket.Label)
c.objectStorageBuckets[id] = bucket
}
}
Expand All @@ -40,9 +40,9 @@ func WithKey(key *linodego.ObjectStorageKey) Option {
}

// WithBucketAccess is an option to configure the stub client with Object Storage bucket access.
func WithBucketAccess(bucketAccess *linodego.ObjectStorageBucketAccess, cluster, label string) Option {
func WithBucketAccess(bucketAccess *linodego.ObjectStorageBucketAccess, region, label string) Option {
return func(c *Client) {
id := fmt.Sprintf("%s/%s", cluster, label)
id := fmt.Sprintf("%s/%s", region, label)
c.objectStorageBucketAccesses[id] = bucketAccess
}
}
2 changes: 1 addition & 1 deletion pkg/servers/provisioner/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var (
const (
KeyBucketID = "bucket.id"
KeyBucketLabel = "bucket.label"
KeyBucketCluster = "bucket.cluster"
KeyBucketRegion = "bucket.region"
KeyBucketCreationTimestamp = "bucket.created_at"
KeyBucketACL = "bucket.acl"
KeyBucketCORS = "bucket.cors_enabled"
Expand Down
Loading

0 comments on commit bbbb8f8

Please sign in to comment.