Skip to content

Commit 96dcae8

Browse files
authored
feat: Store resource partition in Status (#615)
Description of changes: Store resource partition as ACKResourceMetadata By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b061ffd commit 96dcae8

6 files changed

Lines changed: 28 additions & 3 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.25.0
44

55
require (
66
github.com/aws-controllers-k8s/pkg v0.0.23
7-
github.com/aws-controllers-k8s/runtime v0.58.1
7+
github.com/aws-controllers-k8s/runtime v0.58.2-0.20260514225948-a4e124a7b16d
88
github.com/aws/aws-sdk-go v1.49.0
99
github.com/aws/aws-sdk-go-v2 v1.32.7
1010
github.com/dlclark/regexp2 v1.10.0 // indirect
@@ -96,7 +96,7 @@ require (
9696

9797
require (
9898
github.com/google/btree v1.1.3 // indirect
99-
github.com/micahhausler/aws-iam-policy v0.4.4 // indirect
99+
github.com/micahhausler/aws-iam-policy v0.4.5-0.20260511184658-411e29b8ffd2 // indirect
100100
go.yaml.in/yaml/v2 v2.4.3 // indirect
101101
go.yaml.in/yaml/v3 v3.0.4 // indirect
102102
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ github.com/aws-controllers-k8s/pkg v0.0.23 h1:iqu8jKQUnyP/c6TiVcXySQYpkATui0iXFC
6666
github.com/aws-controllers-k8s/pkg v0.0.23/go.mod h1:VvdjLWmR6IJ3KU8KByKiq/lJE8M+ur2piXysXKTGUS0=
6767
github.com/aws-controllers-k8s/runtime v0.58.1 h1:FZso3Bwd2JIqglH6cpFurNAWkIyc4Z1qNXE7+t0wxdI=
6868
github.com/aws-controllers-k8s/runtime v0.58.1/go.mod h1:WPlOiAG+xGySh1I076llz5g6nbuUeH62Qxh49hnieGo=
69+
github.com/aws-controllers-k8s/runtime v0.58.2-0.20260514225948-a4e124a7b16d h1:rS0TjFROFwOf8PS76OJlG75FUt73IVnalGGSVAUHDxo=
70+
github.com/aws-controllers-k8s/runtime v0.58.2-0.20260514225948-a4e124a7b16d/go.mod h1:ljWD1IdtVx/qC7C4lVobF4vLNhno/xX5A78BOke1Ksk=
6971
github.com/aws/aws-sdk-go v1.49.0 h1:g9BkW1fo9GqKfwg2+zCD+TW/D36Ux+vtfJ8guF4AYmY=
7072
github.com/aws/aws-sdk-go v1.49.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
7173
github.com/aws/aws-sdk-go-v2 v1.32.7 h1:ky5o35oENWi0JYWUZkB7WYvVPP+bcRF5/Iq7JWSb5Rw=
@@ -420,6 +422,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
420422
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
421423
github.com/micahhausler/aws-iam-policy v0.4.4 h1:1aMhJ+0CkvUJ8HGN1chX+noXHs8uvGLkD7xIBeYd31c=
422424
github.com/micahhausler/aws-iam-policy v0.4.4/go.mod h1:H+yWljTu4XWJjNJJYgrPUai0AUTGNHc8pumkN57/foI=
425+
github.com/micahhausler/aws-iam-policy v0.4.5-0.20260511184658-411e29b8ffd2 h1:J1D4vj3/AVzVoo1allyJJD3mh7J6bPWXVoQHOBQ+p5Y=
426+
github.com/micahhausler/aws-iam-policy v0.4.5-0.20260511184658-411e29b8ffd2/go.mod h1:H+yWljTu4XWJjNJJYgrPUai0AUTGNHc8pumkN57/foI=
423427
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
424428
github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37/go.mod h1:dYWq+UWoFCDY1TndvFUQuhBbIYmZpjreC8adEAx93zE=
425429
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=

pkg/generate/ack/runtime_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func (ids *fakeIdentifiers) Region() *ackv1alpha1.AWSRegion {
5151
return &region
5252
}
5353

54+
func (ids *fakeIdentifiers) Partition() *ackv1alpha1.AWSPartition {
55+
region := ackv1alpha1.AWSPartition("aws")
56+
return &region
57+
}
58+
5459
type fakeDescriptor struct{}
5560

5661
func (fd *fakeDescriptor) GroupVersionKind() schema.GroupVersionKind {

templates/pkg/resource/identifiers.go.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ func (ri *resourceIdentifiers) Region() *ackv1alpha1.AWSRegion {
4040
}
4141
return nil
4242
}
43+
44+
// Partition returns the AWS partition in which the reosurce exists, or
45+
// nil if this information is not known.
46+
func (ri *resourceIdentifiers) Partition() *ackv1alpha1.AWSPartition {
47+
if ri.meta != nil {
48+
return ri.meta.Partition
49+
}
50+
return nil
51+
}

templates/pkg/resource/manager.go.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type resourceManager struct {
6262
awsAccountID ackv1alpha1.AWSAccountID
6363
// The AWS Region that this resource manager targets
6464
awsRegion ackv1alpha1.AWSRegion
65+
// The AWS Partition that this resource manager targets
66+
awsPartition ackv1alpha1.AWSPartition
6567
// sdk is a pointer to the AWS service API client exposed by the
6668
// aws-sdk-go-v2/services/{alias} package.
6769
sdkapi *svcsdk.Client
@@ -180,7 +182,8 @@ func (rm *resourceManager) Delete(
180182
// name for the resource
181183
func (rm *resourceManager) ARNFromName(name string) string {
182184
return fmt.Sprintf(
183-
"arn:aws:{{ .ControllerName }}:%s:%s:%s",
185+
"arn:%s:{{ .ControllerName }}:%s:%s:%s",
186+
rm.awsPartition,
184187
rm.awsRegion,
185188
rm.awsAccountID,
186189
name,
@@ -435,6 +438,7 @@ func newResourceManager(
435438
rr: rr,
436439
awsAccountID: id,
437440
awsRegion: region,
441+
awsPartition: ackv1alpha1.AWSPartition(cfg.Partition),
438442
sdkapi: svcsdk.NewFromConfig(clientcfg{{- if $hookCode := Hook .CRD "new_resource_manager_client_options" }}, {{ $hookCode }}{{ end }}),
439443
}, nil
440444
}

templates/pkg/resource/sdk.go.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ func (rm *resourceManager) setStatusDefaults (
202202
if ko.Status.ACKResourceMetadata.Region == nil {
203203
ko.Status.ACKResourceMetadata.Region = &rm.awsRegion
204204
}
205+
if ko.Status.ACKResourceMetadata.Partition == nil {
206+
ko.Status.ACKResourceMetadata.Partition = &rm.awsPartition
207+
}
205208
if ko.Status.ACKResourceMetadata.OwnerAccountID == nil {
206209
ko.Status.ACKResourceMetadata.OwnerAccountID = &rm.awsAccountID
207210
}

0 commit comments

Comments
 (0)