Skip to content

Commit f534e80

Browse files
authored
feat: construct and include bucket ARN in status (#132)
Fixes aws-controllers-k8s/community#2124 This patch adds the bucket's ARN to its status, as the S3 API doesn't provide it directly: - Add helper function to construct bucket ARNs - Set constructed ARN in resource status after creation/retrieval - Update e2e tests to verify ARN presence A minor addition to improve resource information completeness... By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a3fcd03 commit f534e80

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ack_generate_info:
2-
build_date: "2024-08-06T02:49:23Z"
2+
build_date: "2024-08-08T05:43:33Z"
33
build_hash: 587b90dc860e91ee9a763e9e3bc4d3f1b2fbddb7
4-
go_version: go1.22.5
4+
go_version: go1.22.4
55
version: v0.36.0
66
api_directory_checksum: 82bfc8d45e816b2a02a83a4b7cedd72056accddd
77
api_version: v1alpha1

pkg/resource/bucket/hook.go

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package bucket
1515

1616
import (
1717
"context"
18+
"fmt"
1819
"strings"
1920

2021
"github.com/pkg/errors"
@@ -26,6 +27,19 @@ import (
2627
svcsdk "github.com/aws/aws-sdk-go/service/s3"
2728
)
2829

30+
// bucketARN returns the ARN of the S3 bucket with the given name.
31+
func bucketARN(bucketName string) string {
32+
// TODO(a-hilaly): I know there could be other partitions, but I'm
33+
// not sure how to determine at this level of abstraction. Probably
34+
// something the SDK/runtime should handle. For now, we'll just use
35+
// the `aws` partition.
36+
//
37+
// NOTE(a-hilaly): Other parts of ACK also use this default partition
38+
// e.g the generated function `ARNFromName` also uses `aws` as the
39+
// default partition.
40+
return fmt.Sprintf("arn:aws:s3:::%s", bucketName)
41+
}
42+
2943
var (
3044
DefaultAccelerationStatus = svcsdk.BucketAccelerateStatusSuspended
3145
DefaultRequestPayer = svcsdk.PayerBucketOwner

pkg/resource/bucket/sdk.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
if err := rm.addPutFieldsToSpec(ctx, r, ko); err != nil {
22
return nil, err
3-
}
3+
}
4+
5+
// Set bucket ARN in the output
6+
bucketARN := ackv1alpha1.AWSResourceName(bucketARN(*ko.Spec.Name))
7+
ko.Status.ACKResourceMetadata.ARN = &bucketARN

test/e2e/tests/test_bucket.py

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def basic_bucket(s3_client) -> Generator[Bucket, None, None]:
114114
try:
115115
bucket = create_bucket("bucket")
116116
assert k8s.get_resource_exists(bucket.ref)
117+
118+
# assert bucket ARN is present in status
119+
bucket_k8s = bucket.resource_data = k8s.get_resource(bucket.ref)
120+
assert "arn:aws:s3:::" + bucket.resource_name == bucket_k8s["status"]["ackResourceMetadata"]["arn"]
117121

118122
exists = bucket_exists(s3_client, bucket)
119123
assert exists

0 commit comments

Comments
 (0)