Skip to content

Commit a460c0e

Browse files
authored
Add S3 Bucket LocationConstraint Logic and Bucket Name Immutability (#154)
fixes aws-controllers-k8s/community#2336 Description of changes: Handles bucket creation in relation to the `LocationConstraint`, particularly for the `us-east-1` region 1. **LocationConstraint Region Behavior** - **us-east-1**: - If no `LocationConstraint` is provided, creation succeeds (no `CreateBucketConfiguration` is sent). - If a user specifies `LocationConstraint=us-east-1`, S3 returns `InvalidLocationConstraint` (marked as terminal). - If a user specifies a different region (e.g., `LocationConstraint=us-west-2`), S3 returns `PermanentRedirect` (also marked as terminal). - **Non-us-east-1**: - If no `LocationConstraint` is specified, controller defaults it to match its own region, creation succeeds. - If `LocationConstraint` matches the region, creation succeeds. - If `LocationConstraint` mismatches the region, terminal error. 2. **Terminal Errors** - `PermanentRedirect`, `InvalidLocationConstraint` and `IllegalLocationConstraintException` are now handled as terminal conditions to avoid repeated reconciles. 3. **Bucket Name Immutability** - Enforced via CRD validation (`x-kubernetes-validations`) and generator config (`is_immutable: true`). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0db0a3d commit a460c0e

File tree

8 files changed

+57
-15
lines changed

8 files changed

+57
-15
lines changed
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2025-02-20T18:30:11Z"
2+
build_date: "2025-02-21T22:05:26Z"
33
build_hash: a326346bd3a6973254d247c9ab2dc76790c36241
44
go_version: go1.24.0
55
version: v0.43.2
6-
api_directory_checksum: 72db31f2a497b2114082d97643f7bfbe0bf6d425
6+
api_directory_checksum: 2108338a86d704419192e545c0bfb433bab8c836
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 9624c46b047ce91bc8039ff874cd7c93b64a0a52
10+
file_checksum: 0170e59d23a7c2d7fcc2960ce3f537e348933ded
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/bucket.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/generator.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resources:
2121
Name:
2222
is_primary_key: true
2323
is_required: true
24+
is_immutable: true
2425
from:
2526
operation: CreateBucket
2627
path: Bucket
@@ -96,6 +97,11 @@ resources:
9697
errors:
9798
404:
9899
code: NoSuchBucket
100+
terminal_codes:
101+
- PermanentRedirect
102+
- InvalidLocationConstraint
103+
- MalformedXML
104+
- IllegalLocationConstraintException
99105
hooks:
100106
delta_pre_compare:
101107
code: customPreCompare(a, b)

config/crd/bases/s3.services.k8s.aws_buckets.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ spec:
659659
restrictions, see Directory bucket naming rules (https://docs.aws.amazon.com/AmazonS3/latest/userguide/directory-bucket-naming-rules.html)
660660
in the Amazon S3 User Guide
661661
type: string
662+
x-kubernetes-validations:
663+
- message: Value is immutable once set
664+
rule: self == oldSelf
662665
notification:
663666
description: |-
664667
A container for specifying the notification configuration of the bucket.

generator.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resources:
2121
Name:
2222
is_primary_key: true
2323
is_required: true
24+
is_immutable: true
2425
from:
2526
operation: CreateBucket
2627
path: Bucket
@@ -96,6 +97,11 @@ resources:
9697
errors:
9798
404:
9899
code: NoSuchBucket
100+
terminal_codes:
101+
- PermanentRedirect
102+
- InvalidLocationConstraint
103+
- MalformedXML
104+
- IllegalLocationConstraintException
99105
hooks:
100106
delta_pre_compare:
101107
code: customPreCompare(a, b)

helm/crds/s3.services.k8s.aws_buckets.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ spec:
659659
restrictions, see Directory bucket naming rules (https://docs.aws.amazon.com/AmazonS3/latest/userguide/directory-bucket-naming-rules.html)
660660
in the Amazon S3 User Guide
661661
type: string
662+
x-kubernetes-validations:
663+
- message: Value is immutable once set
664+
rule: self == oldSelf
662665
notification:
663666
description: |-
664667
A container for specifying the notification configuration of the bucket.

pkg/resource/bucket/sdk.go

+26-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/bucket/sdk_create_post_build_request.go.tpl

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
if input.CreateBucketConfiguration == nil {
2-
input.CreateBucketConfiguration = &svcsdktypes.CreateBucketConfiguration{}
1+
2+
if rm.awsRegion != "us-east-1" {
3+
// Set default region if not specified
4+
if input.CreateBucketConfiguration == nil ||
5+
input.CreateBucketConfiguration.LocationConstraint == "" {
6+
input.CreateBucketConfiguration = &svcsdktypes.CreateBucketConfiguration{
7+
LocationConstraint: svcsdktypes.BucketLocationConstraint(rm.awsRegion),
8+
}
9+
}
310
}
4-
if input.CreateBucketConfiguration.LocationConstraint == "" && rm.awsRegion != "us-east-1" {
5-
input.CreateBucketConfiguration.LocationConstraint = svcsdktypes.BucketLocationConstraint(rm.awsRegion)
6-
}

0 commit comments

Comments
 (0)