Skip to content

Commit

Permalink
dev put lock config
Browse files Browse the repository at this point in the history
  • Loading branch information
cnolan committed Jun 14, 2024
1 parent cd7f89c commit 35b5114
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/backendstore/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type S3Client interface {
PutBucketPolicy(context.Context, *s3.PutBucketPolicyInput, ...func(*s3.Options)) (*s3.PutBucketPolicyOutput, error)
GetBucketPolicy(context.Context, *s3.GetBucketPolicyInput, ...func(*s3.Options)) (*s3.GetBucketPolicyOutput, error)
DeleteBucketPolicy(context.Context, *s3.DeleteBucketPolicyInput, ...func(*s3.Options)) (*s3.DeleteBucketPolicyOutput, error)
PutObjectLockConfiguration(context.Context, *s3.PutObjectLockConfigurationInput, ...func(*s3.Options)) (*s3.PutObjectLockConfigurationOutput, error)
}

//counterfeiter:generate . STSClient
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/bucket/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"

awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/linode/provider-ceph/apis/provider-ceph/v1alpha1"
"github.com/linode/provider-ceph/internal/consts"
"github.com/linode/provider-ceph/internal/otel/traces"
Expand Down Expand Up @@ -170,6 +171,13 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
}
c.log.Info("Bucket created on backend", consts.KeyBucketName, bucket.Name, consts.KeyBackendName, beName)

_, err = rgw.PutObjectLockConfiguration(ctx, cl, &awss3.PutObjectLockConfigurationInput{Bucket: &bucket.Name})
if err != nil {
c.log.Info("PUT LOCK CONFIG FAILED", consts.KeyBucketName, bucket.Name, consts.KeyBackendName, beName, "err", err.Error())

}
c.log.Info("PUT LOCK DONE", consts.KeyBucketName, bucket.Name, consts.KeyBackendName, beName)

// This compare-and-swap operation is the atomic equivalent of:
// if *bucketAlreadyCreated == false {
// *bucketAlreadyCreated = true
Expand Down
18 changes: 18 additions & 0 deletions internal/rgw/lifecycleconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@ const (
errGetLifecycleConfig = "failed to get bucket lifecycle configuration"
errPutLifecycleConfig = "failed to put bucket lifecycle configuration"
errDeleteLifecycle = "failed to delete bucket lifecycle"

errPutLockConfig = "failed to put bucket lock configuration"
)

func PutObjectLockConfiguration(ctx context.Context, s3Backend backendstore.S3Client, bucket *awss3.PutObjectLockConfigurationInput, o ...func(*awss3.Options)) (*awss3.PutObjectLockConfigurationOutput, error) {
ctx, span := otel.Tracer("").Start(ctx, "PutObjectLockConfiguration")
defer span.End()

resp, err := s3Backend.PutObjectLockConfiguration(ctx, bucket, o...)
if err != nil {
err := errors.Wrap(err, errPutLifecycleConfig)
traces.SetAndRecordError(span, err)

return resp, err

}

return resp, nil
}

func PutBucketLifecycleConfiguration(ctx context.Context, s3Backend backendstore.S3Client, b *v1alpha1.Bucket) (*awss3.PutBucketLifecycleConfigurationOutput, error) {
ctx, span := otel.Tracer("").Start(ctx, "PutBucketLifecycleConfiguration")
defer span.End()
Expand Down

0 comments on commit 35b5114

Please sign in to comment.